mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-29 16:51:10 +00:00
Factored out symdef function from vars.c
This commit is contained in:
parent
512a31a458
commit
1cc877717a
29
vars.c
29
vars.c
@ -15,27 +15,18 @@
|
|||||||
#include "label.h"
|
#include "label.h"
|
||||||
#include "vars.h"
|
#include "vars.h"
|
||||||
|
|
||||||
/* Lookup variable name in variable table *
|
/* Lookup variable name in variable table *
|
||||||
* Returns index into varnam array *
|
* Sets: varidx = index into varnam array *
|
||||||
* FALSE if variable was not found */
|
* varcnt if not found *
|
||||||
|
* Returns: TRUE if found, otherwise FALSE */
|
||||||
int fndvar(char *name)
|
int fndvar(char *name)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
DEBUG("Looking up variable '%s'\n", word);
|
DEBUG("Looking up variable '%s'\n", word);
|
||||||
for (i=0; i<varcnt; i++) {
|
for (varidx=0; varidx<varcnt; varidx++) {
|
||||||
if (strcmp(varnam[i], name) == 0)
|
if (strcmp(varnam[varidx], name) == 0)
|
||||||
return i;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return -1;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if variable has been defined */
|
|
||||||
int symdef(char *name)
|
|
||||||
{
|
|
||||||
if (fndvar(name) > -1)
|
|
||||||
return TRUE;
|
|
||||||
else
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for variable *
|
/* Check for variable *
|
||||||
@ -48,7 +39,7 @@ void chksym(int alwreg, char *name)
|
|||||||
if (alwreg) return;
|
if (alwreg) return;
|
||||||
else ERROR("Illegal reference to register %s\n", name, EXIT_FAILURE);
|
else ERROR("Illegal reference to register %s\n", name, EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (!symdef(name))
|
if (!fndvar(name))
|
||||||
ERROR("Undeclared variable '%s' encountered\n", name, EXIT_FAILURE);
|
ERROR("Undeclared variable '%s' encountered\n", name, EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +171,7 @@ void setvar(int m, int t)
|
|||||||
void addvar(int m, int t)
|
void addvar(int m, int t)
|
||||||
{
|
{
|
||||||
strcpy(vrname, word); //Save Variable Name
|
strcpy(vrname, word); //Save Variable Name
|
||||||
if (symdef(vrname))
|
if (fndvar(vrname))
|
||||||
ERROR("Duplicate declaration of variable '%s\n", word,EXIT_FAILURE);
|
ERROR("Duplicate declaration of variable '%s\n", word,EXIT_FAILURE);
|
||||||
if (t == VTVOID)
|
if (t == VTVOID)
|
||||||
ERROR("Illegal Variable Type\n", 0, EXIT_FAILURE);
|
ERROR("Illegal Variable Type\n", 0, EXIT_FAILURE);
|
||||||
|
2
vars.h
2
vars.h
@ -8,9 +8,11 @@ char varmod[MAXVAR+1]; //Variable Modifier
|
|||||||
char vartyp[MAXVAR+1]; //Variable Type
|
char vartyp[MAXVAR+1]; //Variable Type
|
||||||
char varsiz[MAXVAR+1][4]; //Variable Array
|
char varsiz[MAXVAR+1][4]; //Variable Array
|
||||||
int varcnt; //Number of Variables in Table
|
int varcnt; //Number of Variables in Table
|
||||||
|
int varidx; //Index into Variable Tables
|
||||||
char vrname[MAXVAR+1]; //Variable Name
|
char vrname[MAXVAR+1]; //Variable Name
|
||||||
int vrwrtn; //Variables Written Flag
|
int vrwrtn; //Variables Written Flag
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int varidx; //Index into Variable Table
|
int varidx; //Index into Variable Table
|
||||||
int vrtype; //Variable Type
|
int vrtype; //Variable Type
|
||||||
|
Loading…
Reference in New Issue
Block a user