static void insertIOFunc(void) { TreeNode *func; TreeNode *typeSpec; TreeNode *param; TreeNode *compStmt; func = newDeclNode(FuncK); typeSpec = newTypeNode(FuncK); typeSpec->attr.type = INT; func->type = Integer; compStmt = newStmtNode(CompK); compStmt->child[0] = NULL; // no local var compStmt->child[1] = NULL; // no stmt func->lineno = 0; func->attr.name = "input"; func->child[0] = typeSpec; func->child[1] = NULL; // no param func->child[2] = compStmt; st_insert("input", -1, addLocation(), func); func = newDeclNode(FuncK); typeSpec = newTypeNode(FuncK); typeSpec->attr.type = VOID; func->type = Void; param = newParamNode(NonArrParamK); param->attr.name = "arg"; param->child[0] = newTypeNode(FuncK); param->child[0]->attr.type = INT; compStmt = newStmtNode(CompK); compStmt->child[0] = NULL; // no local var compStmt->child[1] = NULL; // no stmt func->lineno = 0; func->attr.name = "output"; func->child[0] = typeSpec; func->child[1] = param; func->child[2] = compStmt; st_insert("output", -1, addLocation(), func); }
static void insertBultinFunctions(TreeNode **_pSyntaxtree) { TreeNode *inputFunctionNode = NULL; TreeNode *outputFunctionNode = NULL; inputFunctionNode = newDeclNode(FunK); outputFunctionNode = newDeclNode(FunK); inputFunctionNode->name = copyString("input"); outputFunctionNode->name = copyString("output"); inputFunctionNode->lineno = 0; outputFunctionNode->lineno = 0; inputFunctionNode->nArguments = 0; outputFunctionNode->nArguments = 1; inputFunctionNode->detailKind.kindInDecl = FunK; outputFunctionNode->detailKind.kindInDecl = FunK; inputFunctionNode->bReturnWithValue = 1; outputFunctionNode->bReturnWithValue = 0; inputFunctionNode->bDataType = Integer; outputFunctionNode->bDataType = Void; outputFunctionNode->child[0] = newDeclNode(ParamK); outputFunctionNode->child[0]->name = copyString("arg"); outputFunctionNode->child[0]->lineno = 0; outputFunctionNode->child[0]->bDataType = Integer; outputFunctionNode->child[0]->sibling = NULL; inputFunctionNode->sibling = *_pSyntaxtree; *_pSyntaxtree = inputFunctionNode; outputFunctionNode->sibling = *_pSyntaxtree; *_pSyntaxtree = outputFunctionNode; }