Esempio n. 1
0
int findInstanceVar(InstanceVar* src, Sym *name) {
    while ( ! src->isEmpty ) {
        if ( strcmp(symToString(src->name), symToString(name)) == 0 ) {
            return src->offset;
        }
        src = src->next;
    }
    return -1;
}
Esempio n. 2
0
Type *checkSimpleVar(Absyn * node, Table * symtab)
{
	Entry *entry;
	entry = lookup(symtab, node->u.simpleVar.name);
	if (entry == NULL)
		error("undefined variable '%s' in line %d",
		      symToString(node->u.simpleVar.name), node->line);
	if (entry->kind != ENTRY_KIND_VAR)
		error("'%s' is not a variable in line %d",
		      symToString(node->u.simpleVar.name), node->line);
	node->type_t = entry->u.varEntry.type;
	return node->type_t;
}
Esempio n. 3
0
Type *checkNameTy(Absyn * node, Table * symtab)
{
	Entry *entry;
	entry = lookup(symtab, node->u.nameTy.name);
	if (entry == NULL) {
		error("undefined type '%s' in line %d",
		      symToString(node->u.nameTy.name), node->line);
	}
	// check if entry is type
	if (entry->kind != ENTRY_KIND_TYPE)
		error("'%s' is not a type in line %d",
		      symToString(node->u.nameTy.name), node->line);

	return entry->u.typeEntry.type;
}
Esempio n. 4
0
File: vmt.c Progetto: halfdan/ninjac
void printVMT(FILE* file, VMT* vmt) {
    while(!vmt->isEmpty) {
        fprintf(file, ".addr\t%s_%s_%lx\n", vmt->className, symToString(vmt->name), djb2(vmt->fileName));
        vmt = vmt->next;
    }
    fprintf(file, "\n");
}
Esempio n. 5
0
static void showArrayTy(Absyn *node, int n) {
  indent(n);
  say("ArrayTy(\n");
  indent(n + 1);
  say(symToString(node->u.arrayTy.name));
  say(",\n");
  showNode(node->u.arrayTy.valList, n + 1);
  say(")");
}
Esempio n. 6
0
static void showClassTy(Absyn *node, int n) {
  indent(n);
  say("ClassTy(\n");
  indent(n + 1);
  say(symToString(node->u.classTy.name));
  say(",\n");
  showNode(node->u.classTy.decList, n + 1);
  say(")");
}
Esempio n. 7
0
static void showStrTy(Absyn *node, int n) {
  indent(n);
  say("StrTy(\n");
  indent(n + 1);
  say(symToString(node->u.strTy.name));
  say(",\n");
  showNode(node->u.strTy.strList, n + 1);
  say(")");
}
Esempio n. 8
0
static void showNumTy(Absyn *node, int n) {
  indent(n);
  say("NumTy(\n");
  indent(n + 1);
  say(symToString(node->u.numTy.name));
  say(",\n");
  showNode(node->u.numTy.value, n + 1);
  say(")");
}
Esempio n. 9
0
File: vmt.c Progetto: halfdan/ninjac
void showVMT(VMT* src, int indent) {
    printIndent(indent);
    if ( src->isEmpty ) {
        printf("===== END =====\n");
        return;
    }
    printf("%d:\t%s_%s\n", src->offset, src->className, symToString(src->name));
    showVMT(src->next, indent);
}
Esempio n. 10
0
char *strListToString(Absyn *strList) {
    Absyn *node,*dec;
    unsigned strLength;
    unsigned strPos;
    char *newStr;

    strLength = 0;
    strPos = 0;
    node = strList;

    if (node->u.strList.isEmpty) {
        return "";
    }

    if (node->u.strList.tail->u.strList.isEmpty) {
        return symToString(node->u.strList.head->u.str.value);
    }

    while (!node->u.strList.isEmpty) {
        dec = node->u.strList.head;
        strLength += strlen(symToString(dec->u.str.value));
        node = node->u.strList.tail;
        if (!node->u.strList.isEmpty) {
            strLength += 1;
        }
    }
    newStr = (char *) allocate((strLength +1) * sizeof(char));

    node = strList;
    while (!node->u.strList.isEmpty) {
        dec = node->u.strList.head;
        strcpy(newStr + strPos,symToString(dec->u.str.value));
        strPos += strlen(symToString(dec->u.str.value));
        node = node->u.strList.tail;
        if (!node->u.strList.isEmpty) {
            newStr[++strPos] = '\"';
        }
    }
    newStr[++strPos] = 0;
    return newStr;
}
Esempio n. 11
0
Type *checkVarDec(Absyn * node, Table * symtab)
{
	Type *type;
	Entry *entry;
	type = checkNode(node->u.typeDec.ty, symtab);
	entry = newVarEntry(type, FALSE, ENTRY_SOURCE_LOCVAR);
	if (enter(symtab, node->u.typeDec.name, entry) == NULL) {
		error("redeclaration of '%s' in line %d",
		      symToString(node->u.typeDec.name), node->line);
	}
	return NULL;
}
Esempio n. 12
0
Type *checkCallStm(Absyn * node, Table * symtab)
{
	Entry *entry;
	ParamTypes *p;
	Absyn *args, *arg;
	int n = 0;

	entry = lookup(symtab, node->u.callStm.name);
	if (entry == NULL)
		error("undefined procedure '%s' in line %d",
		      symToString(node->u.callStm.name), node->line);
	if (entry->kind != ENTRY_KIND_PROC)
		error("call of non-procedure '%s' in line %d",
		      symToString(node->u.callStm.name), node->line);

	p = entry->u.procEntry.paramTypes;
	args = node->u.callStm.args;
	if (args->type != ABSYN_EXPLIST)
		error
		    ("error in abstract syntax. should not happen; internal compiler error.");
	arg = args;

	while (p && !p->isEmpty) {
		n++;
		if (arg->u.expList.isEmpty)	// (n < soll_n)
			error
			    ("procedure '%s' called with too few arguments in line %d",
			     symToString(node->u.callStm.name), node->line);
		if (p->type != checkNode(arg->u.expList.head, symtab)) {
			error
			    ("procedure '%s' argument %d type mismatch in line %d",
			     symToString(node->u.callStm.name), n, node->line);
		}

		arg = arg->u.expList.tail;
		p = p->next;
	}
	if (!(arg->u.expList.isEmpty))	// (n > soll_n)
		error
		    ("procedure '%s' called with too many arguments in line %d",
		     symToString(node->u.callStm.name), node->line);

	// check ref params for being a variable explicitly.
	arg = args;
	p = entry->u.procEntry.paramTypes;
	while (p && !p->isEmpty) {
		if (p->isRef && arg->u.expList.head->type != ABSYN_VAREXP) {
			error
			    ("procedure '%s' argument %d must be a variable in line %d",
			     symToString(node->u.callStm.name), n, node->line);
		}
		arg = arg->u.expList.tail;
		p = p->next;
	}

	return NULL;
}
Esempio n. 13
0
Type *checkProcDec(Absyn * node, Table * symtab)
{
	Table *localSymtab;
	Entry *entry;

	// loopup procs local symtable here
	entry = lookup(symtab, node->u.procDec.name);
	localSymtab = entry->u.procEntry.localTable;

	// compute local declarations
	checkNode(node->u.procDec.decls, localSymtab);

	// compute procedure body
	checkNode(node->u.procDec.body, localSymtab);

	// optional debug output
	if (local_debug) {
		printf("symbol table at end of procedure '%s':\n",
		       symToString(node->u.procDec.name));
		showTable(localSymtab);
	}

	return NULL;
}
Esempio n. 14
0
static void showStr(Absyn *node, int n) {
  indent(n);
  say("Str(");
  say(symToString(node->u.str.value));
  say(")");
}
Esempio n. 15
0
static void showNum(Absyn *node, int n) {
  indent(n);
  say("Num(");
  say(symToString(node->u.num.value));
  say(")");
}
Esempio n. 16
0
void enter_proc_decs(Absyn * program, Table * symtab)
{
	ParamTypes *paramTypes, *p_last, *p_new;
	Table *localSymtab;
	Entry *entry;
	Absyn *tmp, *node;
	Sym *name;

	while (!program->u.decList.isEmpty) {
		node = program->u.decList.head;
		if (node->type == ABSYN_PROCDEC) {

			// determine parameter types
			paramTypes = NULL;
			tmp = node->u.procDec.params;
			if (tmp->u.decList.isEmpty)
				paramTypes = emptyParamTypes();
			else {
				while (!(tmp->u.decList.isEmpty)) {
					p_new =
					    newParamTypes(checkNode
							  (tmp->u.decList.head,
							   symtab),
							  tmp->u.decList.
							  head->u.parDec.isRef,
							  NULL);
					if (paramTypes == NULL)
						paramTypes = p_new;
					else
						p_last->next = p_new;
					p_last = p_new;
					tmp = tmp->u.decList.tail;
				}
				p_last->next = emptyParamTypes();
			}

			// enter proc into global symbol table
			localSymtab = newTable(symtab);
			entry = newProcEntry(paramTypes, localSymtab, node);

			if (enter(symtab, node->u.procDec.name, entry) == NULL) {
				error("redeclaration of '%s' in line %d",
				      symToString(node->u.procDec.name),
				      node->line);
			}
			// enter parameters into local symbol table
			tmp = node->u.procDec.params;
			while (!(tmp->u.decList.isEmpty)) {
				name = tmp->u.decList.head->u.varDec.name;
				entry =
				    newVarEntry(checkNode
						(tmp->u.decList.head->u.
						 parDec.ty, symtab),
						tmp->u.decList.head->u.
						parDec.isRef, ENTRY_SOURCE_PARAM);
				enter(localSymtab, name, entry);
				tmp = tmp->u.decList.tail;
			}

		}
		if (node->type == ABSYN_TYPEDEC) {
			checkTypeDec(node, symtab);
		}
		program = program->u.decList.tail;
	}
	return;
}