3 #define YYLTYPE Location
9 bool memoryGuard = false;
10 public void SetMemoryGuard(bool b) { memoryGuard = b; } public bool GetMemoryGuard() { return memoryGuard; }
12 static void OutputIdentifier(Identifier id, File f)
17 TODO: Name Space Fix ups
18 if(id.nameSpace && id.nameSpace->name)
20 f.Puts(id.nameSpace->name);
24 if(id._class.type == templateTypeSpecifier)
26 if(id._class.templateParameter && id._class.templateParameter.identifier && id._class.templateParameter.identifier.string)
27 f.Puts(id._class.templateParameter.identifier.string);
33 if(!strcmp(id._class.name, "class"))
34 f.Puts("typed_object");
36 f.Puts(id._class.name);
42 f.Puts((id && id.string) ? id.string : "(null identifier)");
45 static void OutputOperator(int op, File f)
49 case INC_OP: f.Puts("++"); break;
50 case DEC_OP: f.Puts("--");break;
51 case SIZEOF: f.Puts("sizeof "); break;
52 case LEFT_OP: f.Puts("<<"); break;
53 case RIGHT_OP: f.Puts(">>"); break;
54 case LE_OP: f.Puts("<="); break;
55 case GE_OP: f.Puts(">="); break;
56 case EQ_OP: f.Puts("=="); break;
57 case NE_OP: f.Puts("!="); break;
58 case AND_OP: f.Puts("&&"); break;
59 case OR_OP: f.Puts("||"); break;
60 case MUL_ASSIGN: f.Puts("*="); break;
61 case DIV_ASSIGN: f.Puts("/="); break;
62 case MOD_ASSIGN: f.Puts("%="); break;
63 case ADD_ASSIGN: f.Puts("+="); break;
64 case SUB_ASSIGN: f.Puts("-="); break;
65 case LEFT_ASSIGN: f.Puts("<<="); break;
66 case RIGHT_ASSIGN: f.Puts(">>="); break;
67 case AND_ASSIGN: f.Puts("&="); break;
68 case XOR_ASSIGN: f.Puts("^="); break;
69 case OR_ASSIGN: f.Puts("|="); break;
70 case '&': case '*': case '+': case '-': case '~': case '!': case '/': case '%':
71 case '<': case '>': case '|': case '^': case '=':
74 case DELETE: f.Puts("delete "); break;
78 public void OutputTypeName(TypeName type, File f, bool typeName)
80 /*if(type.typedObject)
82 //f.Puts("Class * class, void *");
85 else */if(type.qualifiers)
88 for(spec = type.qualifiers->first; spec; spec = spec.next)
90 OutputSpecifier(spec, f, typeName);
91 if(spec.next) f.Puts(" ");
97 OutputDeclarator(type.declarator, f);
100 if(/*!type.typedObject && */!type.qualifiers && !type.declarator)
105 public void OutputExpression(Expression exp, File f)
111 if(exp._classExp.specifiers)
114 for(spec = exp._classExp.specifiers->first; spec; spec = spec.next)
116 OutputSpecifier(spec, f, false);
117 if(spec.next) f.Puts(" ");
119 if(exp._classExp.decl)
122 OutputDeclarator(exp._classExp.decl, f);
127 case extensionCompoundExp:
128 f.Puts("__extension__ (");
129 OutputStatement(exp.compound, f);
135 OutputTypeName(exp._renew.typeName, f, false);
137 OutputExpression(exp._renew.size, f);
143 OutputTypeName(exp._renew.typeName, f, false);
145 OutputExpression(exp._renew.size, f);
150 OutputExpression(exp._renew.exp, f);
152 OutputTypeName(exp._renew.typeName, f, false);
154 OutputExpression(exp._renew.size, f);
159 OutputExpression(exp._renew.exp, f);
161 OutputTypeName(exp._renew.typeName, f, false);
163 OutputExpression(exp._renew.size, f);
168 OutputIdentifier(exp.identifier, f);
172 OutputInstance(exp.instance, f);
176 f.Puts(exp.constant);
187 OutputExpression(exp.op.exp1, f);
191 OutputOperator(exp.op.op, f);
194 if(exp.op.exp1 || (exp.op.exp2.type == opExp && !exp.op.exp2.op.exp1 && exp.op.exp2.op.op == exp.op.op))
196 OutputExpression(exp.op.exp2, f);
199 case extensionExpressionExp:
202 Expression expression;
203 if(exp.type == extensionExpressionExp)
204 f.Puts("__extension__ (");
208 for(expression = exp.list->first; expression; expression = expression.next)
210 OutputExpression(expression, f);
211 if(expression.next) f.Puts(", ");
219 Expression expression;
221 OutputExpression(exp.index.exp, f);
224 for(expression = exp.index.index->first; expression; expression = expression.next)
226 OutputExpression(expression, f);
227 if(expression.next) f.Puts(", ");
234 OutputExpression(exp.call.exp, f);
236 if(exp.call.arguments)
238 Expression expression;
239 for(expression = exp.call.arguments->first; expression; expression = expression.next)
241 OutputExpression(expression, f);
242 if(expression.next) f.Puts(", ");
250 OutputExpression(exp.member.exp, f);
252 if(exp.member.member)
253 OutputIdentifier(exp.member.member, f);
256 OutputExpression(exp.member.exp, f);
258 OutputIdentifier(exp.member.member, f);
262 OutputTypeName(exp.typeName, f, false);
266 f.Puts("__alignof__(");
267 OutputTypeName(exp.typeName, f, false);
270 case extensionInitializerExp:
271 f.Puts("__extension__ (");
272 if(exp.initializer.typeName)
273 OutputTypeName(exp.initializer.typeName, f, false);
275 if(exp.initializer.initializer)
276 OutputInitializer(exp.initializer.initializer, f);
280 OutputTypeName(exp.cast.typeName, f, false);
283 OutputExpression(exp.cast.exp, f);
286 OutputExpression(exp.cond.cond, f);
289 Expression expression;
290 for(expression = exp.cond.exp->first; expression; expression = expression.next)
292 OutputExpression(expression, f);
293 if(expression.next) f.Puts(", ");
297 OutputExpression(exp.cond.elseExp, f);
300 f.Puts("__builtin_va_arg(");
301 OutputExpression(exp.vaArg.exp, f);
303 OutputTypeName(exp.vaArg.typeName, f, false);
310 Expression expression;
311 for(expression = exp.list->first; expression; expression = expression.next)
313 OutputExpression(expression, f);
314 if(expression.next) f.Puts(", ");
322 static void OutputAsmField(AsmField field, File f)
324 f.Puts(field.command);
328 OutputExpression(field.expression, f);
333 static void GetSourceName(char * name, const char * src)
338 if(!strchr(src, '/') && !strchr(src, '\\'))
339 StripLastDirectory(sourceFile, name);
343 PathCat(name, sourceFile);
344 ChangeCh(name, '\\', '/');
347 static void OutputStatement(Statement stmt, File f)
349 char name[MAX_FILENAME] = "";
350 char origName[MAX_FILENAME] = "";
354 GetSourceName(name, stmt.loc.start.included ? GetIncludeFileFromID(stmt.loc.start.included) : null);
356 PathCat(origName, outputFile);
357 ChangeCh(origName, '\\', '/');
361 if(inCompiler && outputLineNumbers && stmt.loc.start.line)
363 /*if(stmt.loc.start.line == 1)
365 f.Printf("\n#line %d \"%s\"\n", stmt.loc.start.line, name);
371 case badDeclarationStmt:
372 OutputDeclaration(stmt.decl, f);
375 OutputIdentifier(stmt.labeled.id, f);
378 OutputStatement(stmt.labeled.stmt, f);
381 if(stmt.caseStmt.exp)
384 OutputExpression(stmt.caseStmt.exp, f);
390 f.Puts("default:\n");
393 if(stmt.caseStmt.stmt)
394 OutputStatement(stmt.caseStmt.stmt, f);
400 if(stmt.compound.declarations)
403 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
405 OutputDeclaration(decl, f);
409 if(stmt.compound.statements)
412 if(stmt.compound.declarations)
417 for(statement = stmt.compound.statements->first; statement; statement = statement.next)
419 OutputStatement(statement, f);
424 if(inCompiler && outputLineNumbers && stmt.loc.end.line)
426 /*if(stmt.loc.end.line == 1)
429 f.Printf("\n#line %d \"%s\"\n", stmt.loc.end.line, name);
441 for(exp = stmt.expressions->first; exp; exp = exp.next)
443 OutputExpression(exp, f);
444 if(exp.next) f.Puts(", ");
454 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
456 OutputExpression(exp, f);
457 if(exp.next) f.Puts(", ");
462 OutputStatement(stmt.ifStmt.stmt, f);
463 if(stmt.ifStmt.elseStmt)
468 if(stmt.ifStmt.elseStmt.type != ifStmt)
475 OutputStatement(stmt.ifStmt.elseStmt, f);
483 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
485 OutputExpression(exp, f);
486 if(exp.next) f.Puts(", ");
490 OutputStatement(stmt.switchStmt.stmt, f);
497 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
499 OutputExpression(exp, f);
500 if(exp.next) f.Puts(", ");
504 OutputStatement(stmt.whileStmt.stmt, f);
512 OutputStatement(stmt.whileStmt.stmt, f);
514 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
516 OutputExpression(exp, f);
517 if(exp.next) f.Puts(", ");
526 OutputStatement(stmt.forStmt.init, f);
528 OutputStatement(stmt.forStmt.check, f);
530 if(stmt.forStmt.increment)
532 // TESTING THIS HERE FOR FOR INCREMENT
533 if(inCompiler && outputLineNumbers && stmt.loc.end.line)
535 /*if(stmt.loc.end.line == 1)
538 f.Printf("\n#line %d \"%s\"\n", stmt.loc.end.line, name);
542 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
544 OutputExpression(exp, f);
545 if(exp.next) f.Puts(", ");
550 OutputStatement(stmt.forStmt.stmt, f);
556 OutputIdentifier(stmt.gotoStmt.id, f);
570 if(inCompiler && memoryGuard)
572 Expression exp = stmt.expressions ? stmt.expressions->last : null;
574 if(exp && exp.expType)
577 char string[1024] = "";
578 OldList * specs = MkList();
581 if(exp.expType.kind == templateType)
583 if(exp.expType.templateParameter.dataTypeString)
584 decl = SpecDeclFromString(exp.expType.templateParameter.dataTypeString, specs,
585 MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal")));
586 else if(exp.expType.templateParameter.dataType)
589 specs = CopyList(exp.expType.templateParameter.dataType.specifiers, CopySpecifier);
590 decl = PlugDeclarator(/*CopyDeclarator(*/exp.expType.templateParameter.dataType.decl/*)*/,
591 MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal")));
595 ListAdd(specs, MkSpecifierName("uint64"));
596 decl = MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal"));
601 // Printing 'name' as a hack when we're dealing with typedefs with extended attributes
602 PrintTypeNoConst(exp.expType, string, exp.expType.kind == dummyType ? true : false, true);
603 decl = SpecDeclFromString(string, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal")));
606 typeName = MkTypeName(specs, decl);
607 InstDeclPassTypeName(typeName, false);
608 OutputTypeName(typeName, f, false);
610 FreeTypeName(typeName);
617 Expression exp = stmt.expressions ? stmt.expressions->last : null;
618 if(exp && exp.expType)
619 f.Printf("__ecereReturnVal = ");
624 for(exp = stmt.expressions->first; exp; exp = exp.next)
626 OutputExpression(exp, f);
627 if(exp.next) f.Puts(", ");
632 if(inCompiler && memoryGuard)
634 Expression exp = stmt.expressions ? (Expression)stmt.expressions->last : null;
635 f.Printf(" __ecereNameSpace__ecere__com__MemoryGuard_PopLoc();");
636 if(exp && exp.expType)
637 f.Printf("return __ecereReturnVal;");
650 if(stmt.asmStmt.spec)
651 OutputSpecifier(stmt.asmStmt.spec, f, false);
653 f.Puts(stmt.asmStmt.statements);
655 if(stmt.asmStmt.inputFields || stmt.asmStmt.outputFields || stmt.asmStmt.clobberedFields)
658 if(stmt.asmStmt.inputFields)
660 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
662 if(field.prev) f.Puts(",");
663 OutputAsmField(field, f);
667 if(stmt.asmStmt.outputFields || stmt.asmStmt.clobberedFields)
670 if(stmt.asmStmt.outputFields)
672 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
674 if(field.prev) f.Puts(",");
675 OutputAsmField(field, f);
679 if(stmt.asmStmt.clobberedFields)
682 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
684 if(field.prev) f.Puts(",");
685 OutputAsmField(field, f);
694 if(inCompiler && outputLineNumbers && stmt.loc.start.line)
696 f.Printf("\n#line %d \"%s\"\n", outputLine+2, origName);
701 static void OutputPointer(Pointer ptr, File f)
708 for(spec = ptr.qualifiers->first; spec; spec = spec.next)
710 OutputSpecifier(spec, f, false);
711 if(spec.next) f.Puts(" ");
716 OutputPointer(ptr.pointer, f);
720 static void OutputDeclarator(Declarator decl, File f)
724 case structDeclarator:
727 OutputDeclarator(decl.declarator, f);
729 if(decl.structDecl.exp)
732 OutputExpression(decl.structDecl.exp, f);
734 if(decl.structDecl.posExp)
737 OutputExpression(decl.structDecl.posExp, f);
739 if(decl.structDecl.attrib)
742 OutputAttrib(decl.structDecl.attrib, f);
745 case identifierDeclarator:
746 OutputIdentifier(decl.identifier, f);
748 case bracketsDeclarator:
750 OutputDeclarator(decl.declarator, f);
753 case extendedDeclarator:
754 if(decl.extended.extended) OutputExtDecl(decl.extended.extended, f);
756 OutputDeclarator(decl.declarator, f);
758 case extendedDeclaratorEnd:
759 OutputDeclarator(decl.declarator, f);
761 if(decl.extended.extended)
762 OutputExtDecl(decl.extended.extended, f);
764 case arrayDeclarator:
767 OutputDeclarator(decl.declarator, f);
773 ProcessExpressionType(decl.array.exp);
774 ComputeExpression(decl.array.exp);
776 OutputExpression(decl.array.exp, f);
778 else if(decl.array.enumClass)
780 Symbol _class = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
781 if(_class && _class.registered)
783 f.Printf("%d", (int)eClass_GetProperty(_class.registered, "enumSize"));
788 case functionDeclarator:
793 OutputDeclarator(decl.declarator, f);
795 if(decl.function.parameters && decl.function.parameters->first)
797 for(param = decl.function.parameters->first; param; param = param.next)
799 OutputTypeName(param, f, false);
807 case pointerDeclarator:
808 if(decl.pointer.pointer) OutputPointer(decl.pointer.pointer, f);
812 OutputDeclarator(decl.declarator, f);
818 static void OutputEnumerator(Enumerator enumerator, File f)
820 OutputIdentifier(enumerator.id, f);
824 OutputExpression(enumerator.exp, f);
828 static void OutputAttribute(Attribute attr, File f)
835 OutputExpression(attr.exp, f);
839 static void OutputAttrib(Attrib attr, File f)
843 case ATTRIB: f.Puts("__attribute__(("); break;
844 case __ATTRIB: f.Puts("__attribute(("); break;
845 case ATTRIB_DEP: f.Puts("__attribute_deprecated__(("); break;
851 for(attrib = attr.attribs->first; attrib; attrib = attrib.next)
853 if(attrib.prev) f.Puts(" ");
854 OutputAttribute(attrib, f);
860 static void OutputExtDecl(ExtDecl extDecl, File f)
862 if(extDecl.type == extDeclString && extDecl.s)
864 else if(extDecl.type == extDeclAttrib)
865 OutputAttrib(extDecl.attr, f);
868 static void OutputSpecifier(Specifier spec, File f, bool typeName)
873 switch(spec.specifier)
914 f.Puts(typeName ? "uint" : "unsigned int");
919 f.Puts(typeName ? "int64" : "long long");
922 f.Puts("__builtin_va_list");
940 f.Puts("typed_object");
943 f.Puts("any_object");
953 case extendedSpecifier:
955 OutputExtDecl(spec.extDecl, f);
958 //case classSpecifier:
959 if(spec.name && !strcmp(spec.name, "class"))
961 f.Puts("typed_object");
965 Symbol symbol = spec.symbol; // FindClass(spec.name);
966 // WILL HAVE TO VERIFY THESE ELSEWHERE...
967 if(!symbol && spec.name)
968 symbol = FindClass(spec.name);
971 f.Puts(symbol.string ? symbol.string : "(null)");
983 OutputIdentifier(spec.id, f);
987 Enumerator enumerator;
990 for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
992 OutputEnumerator(enumerator, f);
993 if(enumerator.next) f.Puts(", ");
1000 case structSpecifier:
1001 case unionSpecifier:
1003 f.Puts((spec.type == structSpecifier) ? "struct" : "union");
1004 if(spec.extDeclStruct)
1007 OutputExtDecl(spec.extDeclStruct, f);
1012 OutputIdentifier(spec.id, f);
1014 if(spec.definitions)
1019 for(def = spec.definitions->first; def; def = def.next)
1021 //OutputDeclaration(decl, f);
1022 OutputClassDef(def, f);
1024 f.Puts("} __attribute__ ((gcc_struct))");
1028 case typeOfSpecifier:
1029 f.Puts("__typeof(");
1030 OutputExpression(spec.expression, f);
1033 case subClassSpecifier:
1034 f.Puts("subclass(");
1035 OutputSpecifier(spec._class, f, false);
1038 case templateTypeSpecifier:
1039 OutputIdentifier(spec.templateParameter.identifier, f);
1044 static void OutputInitializer(Initializer initializer, File f)
1046 char name[MAX_FILENAME] = "";
1047 char origName[MAX_FILENAME] = "";
1051 GetSourceName(name, initializer.loc.start.included ? GetIncludeFileFromID(initializer.loc.start.included) : null);
1053 PathCat(origName, outputFile);
1054 ChangeCh(origName, '\\', '/');
1057 switch(initializer.type)
1059 case listInitializer:
1065 if(inCompiler && outputLineNumbers && initializer.loc.start.line)
1067 /*if(initializer.loc.start.line == 1)
1070 f.Printf("\n#line %d \"%s\"\n", initializer.loc.start.line, name);
1074 for(init = initializer.list->first; init; init = init.next)
1076 OutputInitializer(init, f);
1077 if(init.next) f.Puts(", ");
1081 if(inCompiler && outputLineNumbers && initializer.loc.start.line)
1083 /*if(initializer.loc.start.line == 1)
1086 f.Printf("\n#line %d \"%s\"\n", initializer.loc.start.line, name);
1093 case expInitializer:
1095 OutputExpression(initializer.exp, f);
1100 static void OutputInitDeclarator(InitDeclarator decl, File f)
1102 OutputDeclarator(decl.declarator, f);
1103 if(decl.initializer)
1106 OutputInitializer(decl.initializer, f);
1110 static void OutputDeclaration(Declaration decl, File f)
1113 char origName[MAX_FILENAME] = "";
1117 case initDeclaration:
1121 //GetWorkingDir(origName, sizeof(origName));
1124 PathCat(origName, outputFile);
1125 ChangeCh(origName, '\\', '/');
1128 if(decl.declarators && decl.declarators->first)
1130 for(d = decl.declarators->first; d; d = d.next)
1133 char name[MAX_FILENAME] = "";
1135 GetSourceName(name, decl.loc.start.included ? GetIncludeFileFromID(decl.loc.start.included) : null);
1137 if(inCompiler && outputLineNumbers && decl.loc.start.line)
1139 /*if(decl.loc.start.line == 1)
1142 f.Printf("\n#line %d \"%s\"\n", decl.loc.start.line, name);
1151 bool inTypeDef = false;
1152 for(spec = decl.specifiers->first; spec; spec = spec.next)
1154 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1156 OutputSpecifier(spec, f, inTypeDef && !spec.next);
1157 if(spec.next) f.Puts(" ");
1160 if(decl.declarators && decl.declarators->first)
1164 for(d = decl.declarators->first; d; d = d.next)
1166 OutputInitDeclarator(d, f);
1167 if(d.next) f.Puts(", ");
1172 case structDeclaration:
1176 for(spec = decl.specifiers->first; spec; spec = spec.next)
1178 OutputSpecifier(spec, f, false);
1179 if(spec.next) f.Puts(" ");
1182 if(decl.declarators)
1187 for(d = decl.declarators->first; d; d = d.next)
1189 OutputDeclarator(d, f);
1190 if(d.next) f.Puts(", ");
1196 OutputSpecifier(decl.extStorage, f, false);
1200 case instDeclaration:
1203 OutputInstance(decl.inst, f);
1206 case defineDeclaration:
1207 return; // Skip semicolon
1211 if(inCompiler && outputLineNumbers && decl.loc.start.line && decl.type == initDeclaration)
1213 f.Printf("\n#line %d \"%s\"\n", outputLine+2, origName);
1218 static FunctionDefinition curFunction;
1220 static void OutputFunction(FunctionDefinition func, File f)
1222 FunctionDefinition oldFunc = curFunction;
1227 for(spec = func.specifiers->first; spec; spec = spec.next)
1229 OutputSpecifier(spec, f, false);
1230 if(spec.next) f.Puts(" ");
1234 if(func.declarator) OutputDeclarator(func.declarator, f);
1237 if(func.declarations)
1240 for(decl = func.declarations->first; decl; decl = decl.next)
1242 OutputDeclaration(decl, f);
1249 if(inCompiler && memoryGuard)
1251 char name[1024] = "";
1252 Identifier id = GetDeclId(func.declarator);
1254 GetSourceName(name, func.loc.start.included ? GetIncludeFileFromID(func.loc.start.included) : null);
1257 f.Printf(" __ecereNameSpace__ecere__com__MemoryGuard_PushLoc(\"%s:%s\");\n", name, id.string);
1260 OutputStatement(func.body, f);
1261 if(inCompiler && memoryGuard)
1263 f.Printf(" __ecereNameSpace__ecere__com__MemoryGuard_PopLoc();\n");
1270 curFunction = oldFunc;
1273 static void OutputMemberInit(MemberInit init, File f)
1275 if(init.identifiers)
1277 if(init.identifiers->count > 1)
1281 for(id = init.identifiers->first; id; id = id.next)
1283 OutputIdentifier(id, f);
1289 else if(init.identifiers->first)
1290 OutputIdentifier(init.identifiers->first, f);
1293 if(init.initializer)
1294 OutputInitializer(init.initializer, f);
1297 static void OutputMembersInit(MembersInit init, File f)
1301 case dataMembersInit:
1304 if(init.dataMembers)
1306 for(member = init.dataMembers->first; member; member = member.next)
1308 OutputMemberInit(member, f);
1309 if(member.next) f.Puts(", ");
1314 case methodMembersInit:
1315 OutputClassFunction(init.function, f);
1320 static void OutputInstance(Instantiation inst, File f)
1323 OutputSpecifier(inst._class, f, false);
1327 OutputExpression(inst.exp, f);
1329 if(inst.members && inst.members->count > 1)
1334 else if(inst.members)
1341 for(init = inst.members->first; init; init = init.next)
1343 OutputMembersInit(init, f);
1344 if(init.type == dataMembersInit && init.next)
1357 static void OutputClassFunction(ClassFunction func, File f)
1362 for(spec = func.specifiers->first; spec; spec = spec.next)
1364 OutputSpecifier(spec, f, false);
1365 if(spec.next) f.Puts(" ");
1371 //if(func.class != (void *)-1)
1373 OutputSpecifier(func.class, f, false);
1376 if(func.declarator) OutputDeclarator(func.declarator, f);
1379 if(func.declarations)
1382 for(decl = func.declarations->first; decl; decl = decl.next)
1384 OutputDeclaration(decl, f);
1391 OutputStatement(func.body, f);
1399 static void OutputClassDef(ClassDef def, File f)
1403 case declarationClassDef:
1406 OutputDeclaration(def.decl, f);
1407 if(def.next && def.next.type != declarationClassDef)
1414 case defaultPropertiesClassDef:
1417 for(init = def.defProperties->first; init; init = init.next)
1419 OutputMemberInit(init, f);
1420 if(init.next) f.Puts(", ");
1426 case functionClassDef:
1427 OutputClassFunction(def.function, f);
1434 static void OutputClass(ClassDefinition _class, File f)
1437 OutputSpecifier(_class._class, f, false);
1438 if(_class.baseSpecs)
1443 for(spec = _class.baseSpecs->first; spec; spec = spec.next)
1445 OutputSpecifier(spec, f, false);
1448 if(_class.definitions)
1453 for(def = _class.definitions->first; def; def = def.next)
1455 OutputClassDef(def, f);
1464 public void OutputTree(OldList ast, File f)
1470 for(external = ast.first; external; external = external.next)
1472 switch(external.type)
1474 case functionExternal:
1475 OutputFunction(external.function, f);
1479 case declarationExternal:
1480 OutputDeclaration(external.declaration, f);
1485 OutputClass(external._class, f);
1493 public char * StringFromSpecDecl(OldList specs, Declarator decl)
1496 TypeName typeName { };
1497 File f = TempFile { };
1500 typeName.qualifiers = specs;
1501 typeName.declarator = decl;
1503 OutputTypeName(typeName, f, true);
1508 string = new char[size + 1];
1510 f.Read(string, 1, size);
1511 string[size] = '\0';
1512 TrimRSpaces(string, string);