コード例 #1
0
ファイル: ClassNode.cpp プロジェクト: fdyjfd/idlcpp
void ClassNode::GenerateCreateArrayMethod(const char* methodName, MethodNode* constructor)
{
	IdentifyNode* name = (IdentifyNode*)newIdentify(methodName);
	ParameterNode* parameter = (ParameterNode*)newParameter(newPrimitiveType(newToken(snt_keyword_unsigned), pt_uint), 0, 0, newIdentify("count"));
	ParameterListNode* parameterList = (ParameterListNode*)newParameterList(0,0,parameter);
	MethodNode* method = (MethodNode*)newMethod(name, 
		constructor->m_leftParenthesis, parameterList, 
		constructor->m_rightParenthesis, constructor->m_constant);
	method->m_semicolon = constructor->m_semicolon;

	ScopeNameNode* scopeName = (ScopeNameNode*)newScopeName(m_name, 0, 0, 0);
	ScopeNameListNode* scopeNameList = (ScopeNameListNode*)newScopeNameList(0, scopeName);
	TypeNameNode* typeName = (TypeNameNode*)newTypeName(scopeNameList);
	TokenNode* passing = (TokenNode*)newToken('^');
	setMethodResult(method, typeName, passing);
	setMethodResultArray(method);
	TokenNode* modifier = (TokenNode*)newToken(snt_keyword_static);
	setMethodModifier(method, modifier);
	if (constructor->m_filterNode)
	{
		method->m_filterNode = (TokenNode*)newToken(constructor->m_filterNode->m_nodeType);
	}
	method->m_enclosing = this;
	m_additionalMethods.push_back(method);
}
コード例 #2
0
ファイル: semant.c プロジェクト: christianwameni/dsnb12
Table *check(Absyn * program, boolean showSymbolTables)
{
	Table *globalTable;
	Entry *e;
	globalTable = newTable(NULL);

	if (showSymbolTables) {
	  local_debug = TRUE;
	}

	/* generate built-in types */
	builtinType_int  = newPrimitiveType("int",  INT_BYTE_SIZE);
	builtinType_bool = newPrimitiveType("bool", BOOL_BYTE_SIZE);

	Entry *builtinProc_exit =
	    newProcEntry(emptyParamTypes(), newTable(globalTable), NULL);
	Entry *builtinProc_time =
	    newProcEntry(newParamTypes
			 (builtinType_int, TRUE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_readi =
	    newProcEntry(newParamTypes
			 (builtinType_int, TRUE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_readc =
	    newProcEntry(newParamTypes
			 (builtinType_int, TRUE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_printi =
	    newProcEntry(newParamTypes
			 (builtinType_int, FALSE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_printc =
	    newProcEntry(newParamTypes
			 (builtinType_int, FALSE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_clearAll =
	    newProcEntry(newParamTypes
			 (builtinType_int, FALSE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_setPixel =
	    newProcEntry(newParamTypes(builtinType_int, FALSE,
				       newParamTypes(builtinType_int, FALSE,
						     newParamTypes
						     (builtinType_int, FALSE,
						      emptyParamTypes()))),
			 newTable(globalTable), NULL);
	Entry *builtinProc_drawCircle =
	    newProcEntry(newParamTypes(builtinType_int, FALSE,
				       newParamTypes(builtinType_int, FALSE,
						     newParamTypes
						     (builtinType_int, FALSE,
						      newParamTypes
						      (builtinType_int, FALSE,
						       emptyParamTypes())))),
			 newTable(globalTable), NULL);
	Entry *builtinProc_drawLine =
	    newProcEntry(newParamTypes(builtinType_int, FALSE,
				       newParamTypes(builtinType_int, FALSE,
						     newParamTypes
						     (builtinType_int, FALSE,
						      newParamTypes
						      (builtinType_int, FALSE,
						       newParamTypes
						       (builtinType_int, FALSE,
							emptyParamTypes()))))),
			 newTable(globalTable), NULL);

	/* setup global symbol table */
	enter(globalTable, newSym("int"), newTypeEntry(builtinType_int));
	enter(globalTable, newSym("exit"), builtinProc_exit);
	enter(globalTable, newSym("time"), builtinProc_time);
	enter(globalTable, newSym("readi"), builtinProc_readi);
	enter(globalTable, newSym("readc"), builtinProc_readc);
	enter(globalTable, newSym("printi"), builtinProc_printi);
	enter(globalTable, newSym("printc"), builtinProc_printc);
	enter(globalTable, newSym("clearAll"), builtinProc_clearAll);
	enter(globalTable, newSym("setPixel"), builtinProc_setPixel);
	enter(globalTable, newSym("drawCircle"), builtinProc_drawCircle);
	enter(globalTable, newSym("drawLine"), builtinProc_drawLine);

	/* enter all procs into global symtable */
	enter_proc_decs(program, globalTable);

	/* do semantic checks */
	checkNode(program, globalTable);

	/* check if "main()" is present */
	e = lookup(globalTable, newSym("main"));
	if (e == NULL)
		error("procedure 'main' is missing");
	if (e->kind != ENTRY_KIND_PROC)
		error("'main' is not a procedure");
	// check that main has no params
	if (!e->u.procEntry.paramTypes->isEmpty)
		error("procedure 'main' must not have any parameters");

	/* return global symbol table */
	return globalTable;
}