3 #define NUM_ECC_ADDED_LINES 47
5 #define YYLTYPE Location
11 bool memoryGuard = false;
12 public void SetMemoryGuard(bool b) { memoryGuard = b; } public bool GetMemoryGuard() { return memoryGuard; }
14 static void OutputIdentifier(Identifier id, File f)
19 TODO: Name Space Fix ups
20 if(id.nameSpace && id.nameSpace->name)
22 f.Puts(id.nameSpace->name);
26 if(id._class.type == templateTypeSpecifier)
28 if(id._class.templateParameter && id._class.templateParameter.identifier && id._class.templateParameter.identifier.string)
29 f.Puts(id._class.templateParameter.identifier.string);
35 if(!strcmp(id._class.name, "class"))
36 f.Puts("typed_object");
38 f.Puts(id._class.name);
44 f.Puts((id && id.string) ? id.string : "(null identifier)");
47 static void OutputOperator(int op, File f)
51 case INC_OP: f.Puts("++"); break;
52 case DEC_OP: f.Puts("--");break;
53 case SIZEOF: f.Puts("sizeof "); break;
54 case LEFT_OP: f.Puts("<<"); break;
55 case RIGHT_OP: f.Puts(">>"); break;
56 case LE_OP: f.Puts("<="); break;
57 case GE_OP: f.Puts(">="); break;
58 case EQ_OP: f.Puts("=="); break;
59 case NE_OP: f.Puts("!="); break;
60 case AND_OP: f.Puts("&&"); break;
61 case OR_OP: f.Puts("||"); break;
62 case MUL_ASSIGN: f.Puts("*="); break;
63 case DIV_ASSIGN: f.Puts("/="); break;
64 case MOD_ASSIGN: f.Puts("%="); break;
65 case ADD_ASSIGN: f.Puts("+="); break;
66 case SUB_ASSIGN: f.Puts("-="); break;
67 case LEFT_ASSIGN: f.Puts("<<="); break;
68 case RIGHT_ASSIGN: f.Puts(">>="); break;
69 case AND_ASSIGN: f.Puts("&="); break;
70 case XOR_ASSIGN: f.Puts("^="); break;
71 case OR_ASSIGN: f.Puts("|="); break;
72 case '&': case '*': case '+': case '-': case '~': case '!': case '/': case '%':
73 case '<': case '>': case '|': case '^': case '=':
76 case DELETE: f.Puts("delete "); break;
80 public void OutputTypeName(TypeName type, File f, bool typeName)
82 /*if(type.typedObject)
84 //f.Puts("Class * class, void *");
87 else */if(type.qualifiers)
90 for(spec = type.qualifiers->first; spec; spec = spec.next)
92 OutputSpecifier(spec, f, typeName);
93 if(spec.next) f.Puts(" ");
99 OutputDeclarator(type.declarator, f);
102 if(/*!type.typedObject && */!type.qualifiers && !type.declarator)
107 public void OutputExpression(Expression exp, File f)
113 if(exp._classExp.specifiers)
116 for(spec = exp._classExp.specifiers->first; spec; spec = spec.next)
118 OutputSpecifier(spec, f, false);
119 if(spec.next) f.Puts(" ");
121 if(exp._classExp.decl)
124 OutputDeclarator(exp._classExp.decl, f);
129 case extensionCompoundExp:
130 f.Puts("__extension__ (");
131 OutputStatement(exp.compound, f);
133 if(inCompiler && outputLineNumbers && exp.loc.end.line)
135 char name[MAX_FILENAME] = "";
136 GetSourceName(name, exp.loc.end.included ? GetIncludeFileFromID(exp.loc.end.included) : null);
137 f.Printf("\n#line %d \"%s\"\n", exp.loc.end.line, name);
144 OutputTypeName(exp._renew.typeName, f, false);
146 OutputExpression(exp._renew.size, 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 OutputExpression(exp._renew.exp, f);
170 OutputTypeName(exp._renew.typeName, f, false);
172 OutputExpression(exp._renew.size, f);
177 OutputIdentifier(exp.identifier, f);
181 OutputInstance(exp.instance, f);
185 f.Puts(exp.constant);
194 OutputExpression(exp.op.exp1, f);
198 OutputOperator(exp.op.op, f);
201 if(exp.op.exp1 || (exp.op.exp2.type == opExp && !exp.op.exp2.op.exp1 && exp.op.exp2.op.op == exp.op.op))
203 OutputExpression(exp.op.exp2, f);
206 case extensionExpressionExp:
209 Expression expression;
210 if(exp.type == extensionExpressionExp)
211 f.Puts("__extension__ (");
215 for(expression = exp.list->first; expression; expression = expression.next)
217 OutputExpression(expression, f);
218 if(expression.next) f.Puts(", ");
226 Expression expression;
228 OutputExpression(exp.index.exp, f);
231 for(expression = exp.index.index->first; expression; expression = expression.next)
233 OutputExpression(expression, f);
234 if(expression.next) f.Puts(", ");
241 OutputExpression(exp.call.exp, f);
243 if(exp.call.arguments)
245 Expression expression;
246 for(expression = exp.call.arguments->first; expression; expression = expression.next)
248 OutputExpression(expression, f);
249 if(expression.next) f.Puts(", ");
257 OutputExpression(exp.member.exp, f);
259 if(exp.member.member)
260 OutputIdentifier(exp.member.member, f);
263 OutputExpression(exp.member.exp, f);
265 OutputIdentifier(exp.member.member, f);
269 OutputTypeName(exp.typeName, f, false);
273 f.Puts("__alignof__(");
274 OutputTypeName(exp.typeName, f, false);
277 case extensionInitializerExp:
278 f.Puts("__extension__ (");
279 if(exp.initializer.typeName)
280 OutputTypeName(exp.initializer.typeName, f, false);
282 if(exp.initializer.initializer)
283 OutputInitializer(exp.initializer.initializer, f);
287 OutputTypeName(exp.cast.typeName, f, false);
290 OutputExpression(exp.cast.exp, f);
293 OutputExpression(exp.cond.cond, f);
296 Expression expression;
297 for(expression = exp.cond.exp->first; expression; expression = expression.next)
299 OutputExpression(expression, f);
300 if(expression.next) f.Puts(", ");
305 OutputExpression(exp.cond.elseExp, f);
308 f.Puts("__builtin_va_arg(");
309 OutputExpression(exp.vaArg.exp, f);
311 OutputTypeName(exp.vaArg.typeName, f, false);
318 Expression expression;
319 for(expression = exp.list->first; expression; expression = expression.next)
321 OutputExpression(expression, f);
322 if(expression.next) f.Puts(", ");
330 static void OutputAsmField(AsmField field, File f)
335 OutputIdentifier(field.symbolic, f);
338 f.Puts(field.command);
342 OutputExpression(field.expression, f);
347 static void GetSourceName(char * name, const char * src)
352 if(!strchr(src, '/') && !strchr(src, '\\'))
353 StripLastDirectory(sourceFile, name);
357 PathCat(name, sourceFile);
358 ChangeCh(name, '\\', '/');
361 static void OutputStatement(Statement stmt, File f)
363 char name[MAX_FILENAME] = "";
364 char origName[MAX_FILENAME] = "";
368 GetSourceName(name, stmt.loc.start.included ? GetIncludeFileFromID(stmt.loc.start.included) : null);
370 PathCat(origName, outputFile);
371 ChangeCh(origName, '\\', '/');
375 if(inCompiler && outputLineNumbers && stmt.loc.start.line)
377 /*if(stmt.loc.start.line == 1)
379 f.Printf("\n#line %d \"%s\"\n", stmt.loc.start.line, name);
385 case badDeclarationStmt:
386 OutputDeclaration(stmt.decl, f);
389 OutputIdentifier(stmt.labeled.id, f);
392 if(stmt.labeled.stmt)
394 if(stmt.labeled.stmt.type == badDeclarationStmt) f.Puts("; ");
395 OutputStatement(stmt.labeled.stmt, f);
399 if(stmt.caseStmt.exp)
402 OutputExpression(stmt.caseStmt.exp, f);
408 f.Puts("default:\n");
411 if(stmt.caseStmt.stmt)
413 if(stmt.caseStmt.stmt.type == badDeclarationStmt) f.Puts("; ");
414 OutputStatement(stmt.caseStmt.stmt, f);
421 if(stmt.compound.declarations)
424 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
426 OutputDeclaration(decl, f);
430 if(stmt.compound.statements)
433 if(stmt.compound.declarations)
438 for(statement = stmt.compound.statements->first; statement; statement = statement.next)
440 OutputStatement(statement, f);
445 if(inCompiler && outputLineNumbers && stmt.loc.end.line)
447 /*if(stmt.loc.end.line == 1)
450 f.Printf("\n#line %d \"%s\"\n", stmt.loc.end.line, name);
462 for(exp = stmt.expressions->first; exp; exp = exp.next)
464 OutputExpression(exp, f);
465 if(exp.next) f.Puts(", ");
475 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
477 OutputExpression(exp, f);
478 if(exp.next) f.Puts(", ");
483 OutputStatement(stmt.ifStmt.stmt, f);
484 if(stmt.ifStmt.elseStmt)
489 if(stmt.ifStmt.elseStmt.type != ifStmt)
496 OutputStatement(stmt.ifStmt.elseStmt, f);
504 if(stmt.switchStmt.exp)
506 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
508 OutputExpression(exp, f);
509 if(exp.next) f.Puts(", ");
514 OutputStatement(stmt.switchStmt.stmt, f);
521 if(stmt.switchStmt.exp)
523 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
525 OutputExpression(exp, f);
526 if(exp.next) f.Puts(", ");
531 OutputStatement(stmt.whileStmt.stmt, f);
539 OutputStatement(stmt.whileStmt.stmt, f);
541 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
543 OutputExpression(exp, f);
544 if(exp.next) f.Puts(", ");
553 OutputStatement(stmt.forStmt.init, f);
555 OutputStatement(stmt.forStmt.check, f);
557 if(stmt.forStmt.increment)
559 // TESTING THIS HERE FOR FOR INCREMENT
560 if(inCompiler && outputLineNumbers && stmt.loc.end.line)
562 /*if(stmt.loc.end.line == 1)
565 f.Printf("\n#line %d \"%s\"\n", stmt.loc.end.line, name);
569 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
571 OutputExpression(exp, f);
572 if(exp.next) f.Puts(", ");
577 OutputStatement(stmt.forStmt.stmt, f);
583 OutputIdentifier(stmt.gotoStmt.id, f);
597 if(inCompiler && memoryGuard)
599 Expression exp = stmt.expressions ? stmt.expressions->last : null;
600 Type returnType = exp ? (exp.destType ? exp.destType : exp.expType) : null;
602 if(returnType && returnType.kind != voidType)
604 char string[1024] = "";
605 OldList * specs = MkList();
609 if(returnType.kind == templateType)
611 if(returnType.templateParameter.dataTypeString)
612 decl = SpecDeclFromString(returnType.templateParameter.dataTypeString, specs,
613 MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal")));
614 else if(returnType.templateParameter.dataType)
617 specs = CopyList(returnType.templateParameter.dataType.specifiers, CopySpecifier);
618 decl = PlugDeclarator(/*CopyDeclarator(*/returnType.templateParameter.dataType.decl/*)*/,
619 MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal")));
623 ListAdd(specs, MkSpecifierName("uint64"));
624 decl = MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal"));
629 // Printing 'name' as a hack when we're dealing with typedefs with extended attributes
630 if(returnType.passAsTemplate)
631 strcpy(string, "uint64");
633 PrintType /*NoConst*/(returnType, string, returnType.kind == dummyType ? true : false, true);
634 decl = SpecDeclFromString(string, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal")));
637 typeName = MkTypeName(specs, decl);
638 InstDeclPassTypeName(typeName, false);
639 OutputTypeName(typeName, f, false);
641 FreeTypeName(typeName);
648 Expression exp = stmt.expressions ? stmt.expressions->last : null;
649 if(exp && exp.expType && exp.expType.kind != voidType)
650 f.Printf("__ecereReturnVal = ");
655 for(exp = stmt.expressions->first; exp; exp = exp.next)
657 OutputExpression(exp, f);
658 if(exp.next) f.Puts(", ");
663 if(inCompiler && memoryGuard)
665 Expression exp = stmt.expressions ? (Expression)stmt.expressions->last : null;
666 f.Printf(" __ecereNameSpace__ecere__com__MemoryGuard_PopLoc();");
667 if(exp && exp.expType && exp.expType.kind != voidType)
668 f.Printf("return __ecereReturnVal;");
681 if(stmt.asmStmt.spec)
682 OutputSpecifier(stmt.asmStmt.spec, f, false);
684 f.Puts(stmt.asmStmt.statements);
686 if(stmt.asmStmt.inputFields || stmt.asmStmt.outputFields || stmt.asmStmt.clobberedFields)
689 if(stmt.asmStmt.inputFields)
691 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
693 if(field.prev) f.Puts(",");
694 OutputAsmField(field, f);
698 if(stmt.asmStmt.outputFields || stmt.asmStmt.clobberedFields)
701 if(stmt.asmStmt.outputFields)
703 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
705 if(field.prev) f.Puts(",");
706 OutputAsmField(field, f);
710 if(stmt.asmStmt.clobberedFields)
713 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
715 if(field.prev) f.Puts(",");
716 OutputAsmField(field, f);
725 if(inCompiler && outputLineNumbers && stmt.loc.start.line)
727 f.Printf("\n#line %d \"%s\"\n", outputLine+2, origName);
732 static void OutputPointer(Pointer ptr, File f)
739 for(spec = ptr.qualifiers->first; spec; spec = spec.next)
741 OutputSpecifier(spec, f, false);
742 if(spec.next) f.Puts(" ");
747 OutputPointer(ptr.pointer, f);
751 static void OutputDeclarator(Declarator decl, File f)
755 case structDeclarator:
758 OutputDeclarator(decl.declarator, f);
760 if(decl.structDecl.exp)
763 OutputExpression(decl.structDecl.exp, f);
765 if(decl.structDecl.posExp)
768 OutputExpression(decl.structDecl.posExp, f);
770 if(decl.structDecl.attrib)
773 OutputAttrib(decl.structDecl.attrib, f);
776 case identifierDeclarator:
777 OutputIdentifier(decl.identifier, f);
779 case bracketsDeclarator:
781 OutputDeclarator(decl.declarator, f);
784 case extendedDeclarator:
785 if(decl.extended.extended) OutputExtDecl(decl.extended.extended, f);
787 OutputDeclarator(decl.declarator, f);
789 case extendedDeclaratorEnd:
790 OutputDeclarator(decl.declarator, f);
792 if(decl.extended.extended)
793 OutputExtDecl(decl.extended.extended, f);
795 case arrayDeclarator:
798 OutputDeclarator(decl.declarator, f);
804 ProcessExpressionType(decl.array.exp);
805 ComputeExpression(decl.array.exp);
807 OutputExpression(decl.array.exp, f);
809 else if(decl.array.enumClass)
811 Symbol _class = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
812 if(_class && _class.registered)
814 f.Printf("%d", (int)eClass_GetProperty(_class.registered, "enumSize"));
819 case functionDeclarator:
824 OutputDeclarator(decl.declarator, f);
826 if(decl.function.parameters && decl.function.parameters->first)
828 for(param = decl.function.parameters->first; param; param = param.next)
830 OutputTypeName(param, f, false);
838 case pointerDeclarator:
839 if(decl.pointer.pointer) OutputPointer(decl.pointer.pointer, f);
843 OutputDeclarator(decl.declarator, f);
849 static void OutputEnumerator(Enumerator enumerator, File f)
851 OutputIdentifier(enumerator.id, f);
855 OutputExpression(enumerator.exp, f);
859 static void OutputAttribute(Attribute attr, File f)
866 OutputExpression(attr.exp, f);
870 static void OutputAttrib(Attrib attr, File f)
874 case ATTRIB: f.Puts("__attribute__(("); break;
875 case __ATTRIB: f.Puts("__attribute(("); break;
876 case ATTRIB_DEP: f.Puts("__attribute_deprecated__(("); break;
882 for(attrib = attr.attribs->first; attrib; attrib = attrib.next)
884 if(attrib.prev) f.Puts(" ");
885 OutputAttribute(attrib, f);
891 static void OutputExtDecl(ExtDecl extDecl, File f)
893 if(extDecl.type == extDeclString && extDecl.s)
895 else if(extDecl.type == extDeclAttrib)
896 OutputAttrib(extDecl.attr, f);
899 static void OutputSpecifier(Specifier spec, File f, bool typeName)
904 switch(spec.specifier)
949 f.Puts("_Imaginary");
961 f.Puts(typeName ? "uint" : "unsigned int");
966 f.Puts(typeName ? "int64" : "long long");
969 f.Puts("__builtin_va_list");
987 f.Puts("typed_object");
990 f.Puts("any_object");
1000 case extendedSpecifier:
1002 OutputExtDecl(spec.extDecl, f);
1005 //case classSpecifier:
1006 if(spec.name && !strcmp(spec.name, "class"))
1008 f.Puts("typed_object");
1012 Symbol symbol = spec.symbol; // FindClass(spec.name);
1013 // WILL HAVE TO VERIFY THESE ELSEWHERE...
1014 if(!symbol && spec.name)
1015 symbol = FindClass(spec.name);
1018 f.Puts(symbol.string ? symbol.string : "(null)");
1030 OutputIdentifier(spec.id, f);
1034 Enumerator enumerator;
1037 for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
1039 OutputEnumerator(enumerator, f);
1040 if(enumerator.next) f.Puts(", ");
1047 case structSpecifier:
1048 case unionSpecifier:
1050 f.Puts((spec.type == structSpecifier) ? "struct" : "union");
1051 if(spec.extDeclStruct)
1054 OutputExtDecl(spec.extDeclStruct, f);
1059 OutputIdentifier(spec.id, f);
1061 if(spec.definitions)
1066 for(def = spec.definitions->first; def; def = def.next)
1068 //OutputDeclaration(decl, f);
1069 OutputClassDef(def, f);
1071 f.Puts("} __attribute__ ((gcc_struct))");
1075 case typeOfSpecifier:
1076 f.Puts("__typeof(");
1077 OutputExpression(spec.expression, f);
1080 case subClassSpecifier:
1081 f.Puts("subclass(");
1082 OutputSpecifier(spec._class, f, false);
1085 case templateTypeSpecifier:
1086 OutputIdentifier(spec.templateParameter.identifier, f);
1091 static void OutputInitializer(Initializer initializer, File f)
1093 char name[MAX_FILENAME] = "";
1094 char origName[MAX_FILENAME] = "";
1098 GetSourceName(name, initializer.loc.start.included ? GetIncludeFileFromID(initializer.loc.start.included) : null);
1100 PathCat(origName, outputFile);
1101 ChangeCh(origName, '\\', '/');
1104 if(initializer.type == listInitializer)
1108 // TODO: Add support for multiple IDs and [ ]
1110 OutputIdentifier(initializer.id, f);
1113 switch(initializer.type)
1115 case listInitializer:
1123 if(inCompiler && outputLineNumbers && initializer.loc.start.line)
1125 /*if(initializer.loc.start.line == 1)
1128 f.Printf("\n#line %d \"%s\"\n", initializer.loc.start.line, name);
1132 for(init = initializer.list->first; init; init = init.next)
1134 OutputInitializer(init, f);
1135 if(init.next) f.Puts(init.next.type == listInitializer ? "," : ", ");
1139 if(inCompiler && outputLineNumbers && initializer.loc.start.line)
1141 /*if(initializer.loc.start.line == 1)
1144 f.Printf("\n#line %d \"%s\"\n", initializer.loc.start.line, name);
1151 case expInitializer:
1155 OutputExpression(initializer.exp, f);
1160 static void OutputInitDeclarator(InitDeclarator decl, File f)
1162 OutputDeclarator(decl.declarator, f);
1163 if(decl.initializer)
1166 if(decl.initializer.type == expInitializer) f.Puts(" ");
1167 OutputInitializer(decl.initializer, f);
1171 static void OutputDeclaration(Declaration decl, File f)
1174 char origName[MAX_FILENAME];
1175 char name[MAX_FILENAME];
1179 strcpy(origName, outputFile);
1180 ChangeCh(origName, '\\', '/');
1182 GetSourceName(name, decl.loc.start.included ? GetIncludeFileFromID(decl.loc.start.included) : null);
1184 if(inCompiler && outputLineNumbers && decl.loc.start.line)
1186 f.Printf("\n#line %d \"%s\"\n", decl.loc.start.line, name);
1192 case initDeclaration:
1196 //GetWorkingDir(origName, sizeof(origName));
1198 /*if(decl.declarators && decl.declarators->first)
1200 for(d = decl.declarators->first; d; d = d.next)
1203 char name[MAX_FILENAME] = "";
1205 GetSourceName(name, decl.loc.start.included ? GetIncludeFileFromID(decl.loc.start.included) : null);
1207 if(inCompiler && outputLineNumbers && decl.loc.start.line)
1209 f.Printf("\n#line %d \"%s\"\n", decl.loc.start.line, name);
1218 bool inTypeDef = false;
1219 for(spec = decl.specifiers->first; spec; spec = spec.next)
1221 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1223 OutputSpecifier(spec, f, inTypeDef && !spec.next);
1224 if(spec.next) f.Puts(" ");
1227 if(decl.declarators && decl.declarators->first)
1231 for(d = decl.declarators->first; d; d = d.next)
1233 OutputInitDeclarator(d, f);
1234 if(d.next) f.Puts(", ");
1239 case structDeclaration:
1243 for(spec = decl.specifiers->first; spec; spec = spec.next)
1245 OutputSpecifier(spec, f, false);
1246 if(spec.next) f.Puts(" ");
1249 if(decl.declarators)
1254 for(d = decl.declarators->first; d; d = d.next)
1256 OutputDeclarator(d, f);
1257 if(d.next) f.Puts(", ");
1263 OutputSpecifier(decl.extStorage, f, false);
1267 case instDeclaration:
1270 OutputInstance(decl.inst, f);
1273 case defineDeclaration:
1274 return; // Skip semicolon
1278 if(inCompiler && outputLineNumbers && decl.loc.start.line)
1280 f.Printf("\n#line %d \"%s\"\n", outputLine+2, origName);
1285 static FunctionDefinition curFunction;
1287 static void OutputFunction(FunctionDefinition func, File f)
1289 FunctionDefinition oldFunc = curFunction;
1294 for(spec = func.specifiers->first; spec; spec = spec.next)
1296 OutputSpecifier(spec, f, false);
1297 if(spec.next) f.Puts(" ");
1301 if(func.declarator) OutputDeclarator(func.declarator, f);
1304 if(func.declarations)
1307 for(decl = func.declarations->first; decl; decl = decl.next)
1309 OutputDeclaration(decl, f);
1316 if(inCompiler && memoryGuard)
1318 char name[1024] = "";
1319 Identifier id = GetDeclId(func.declarator);
1321 GetSourceName(name, func.loc.start.included ? GetIncludeFileFromID(func.loc.start.included) : null);
1324 f.Printf(" __ecereNameSpace__ecere__com__MemoryGuard_PushLoc(\"%s:%s\");\n", name, id.string);
1327 OutputStatement(func.body, f);
1328 if(inCompiler && memoryGuard)
1330 f.Printf(" __ecereNameSpace__ecere__com__MemoryGuard_PopLoc();\n");
1337 curFunction = oldFunc;
1340 static void OutputMemberInit(MemberInit init, File f)
1342 if(init.identifiers)
1344 if(init.identifiers->count > 1)
1348 for(id = init.identifiers->first; id; id = id.next)
1350 OutputIdentifier(id, f);
1356 else if(init.identifiers->first)
1357 OutputIdentifier(init.identifiers->first, f);
1359 if(init.initializer && init.initializer.type == expInitializer) f.Puts(" ");
1361 if(init.initializer)
1362 OutputInitializer(init.initializer, f);
1365 static void OutputMembersInit(MembersInit init, File f)
1369 case dataMembersInit:
1372 if(init.dataMembers)
1374 for(member = init.dataMembers->first; member; member = member.next)
1376 OutputMemberInit(member, f);
1377 if(member.next) f.Puts(", ");
1382 case methodMembersInit:
1383 OutputClassFunction(init.function, f);
1388 static void OutputInstance(Instantiation inst, File f)
1391 OutputSpecifier(inst._class, f, false);
1395 OutputExpression(inst.exp, f);
1397 if(inst.members && inst.members->count > 1)
1402 else if(inst.members)
1409 for(init = inst.members->first; init; init = init.next)
1411 OutputMembersInit(init, f);
1412 if(init.type == dataMembersInit && init.next)
1425 static void OutputClassFunction(ClassFunction func, File f)
1430 for(spec = func.specifiers->first; spec; spec = spec.next)
1432 OutputSpecifier(spec, f, false);
1433 if(spec.next) f.Puts(" ");
1439 //if(func.class != (void *)-1)
1441 OutputSpecifier(func.class, f, false);
1444 if(func.declarator) OutputDeclarator(func.declarator, f);
1447 if(func.declarations)
1450 for(decl = func.declarations->first; decl; decl = decl.next)
1452 OutputDeclaration(decl, f);
1459 OutputStatement(func.body, f);
1467 static void OutputClassDef(ClassDef def, File f)
1471 case declarationClassDef:
1474 OutputDeclaration(def.decl, f);
1475 if(def.next && def.next.type != declarationClassDef)
1482 case defaultPropertiesClassDef:
1485 for(init = def.defProperties->first; init; init = init.next)
1487 OutputMemberInit(init, f);
1488 if(init.next) f.Puts(", ");
1494 case functionClassDef:
1495 OutputClassFunction(def.function, f);
1502 static void OutputClass(ClassDefinition _class, File f)
1505 OutputSpecifier(_class._class, f, false);
1506 if(_class.baseSpecs)
1511 for(spec = _class.baseSpecs->first; spec; spec = spec.next)
1513 OutputSpecifier(spec, f, false);
1516 if(_class.definitions)
1521 for(def = _class.definitions->first; def; def = def.next)
1523 OutputClassDef(def, f);
1532 public void OutputTree(OldList ast, File f)
1536 outputLine = NUM_ECC_ADDED_LINES;
1538 for(external = ast.first; external; external = external.next)
1540 switch(external.type)
1542 case functionExternal:
1543 OutputFunction(external.function, f);
1547 case declarationExternal:
1548 if(external.declaration)
1549 OutputDeclaration(external.declaration, f);
1554 OutputClass(external._class, f);
1562 public void OutputExternal(External external, File f)
1564 switch(external.type)
1566 case functionExternal:
1567 OutputFunction(external.function, f);
1571 case declarationExternal:
1572 if(external.declaration)
1573 OutputDeclaration(external.declaration, f);
1578 OutputClass(external._class, f);
1585 public char * StringFromSpecDecl(OldList specs, Declarator decl)
1588 TypeName typeName { };
1589 File f = TempFile { };
1592 typeName.qualifiers = specs;
1593 typeName.declarator = decl;
1595 OutputTypeName(typeName, f, true);
1600 string = new char[size + 1];
1602 f.Read(string, 1, size);
1603 string[size] = '\0';
1604 TrimRSpaces(string, string);