3 #define NUM_ECC_ADDED_LINES 50
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);
278 f.Puts("__builtin_offsetof(");
280 OutputTypeName(exp.typeName, f, false);
283 OutputIdentifier(exp.identifier, f);
286 case extensionInitializerExp:
287 f.Puts("__extension__ (");
288 if(exp.initializer.typeName)
289 OutputTypeName(exp.initializer.typeName, f, false);
291 if(exp.initializer.initializer)
292 OutputInitializer(exp.initializer.initializer, f);
296 OutputTypeName(exp.cast.typeName, f, false);
299 OutputExpression(exp.cast.exp, f);
302 OutputExpression(exp.cond.cond, f);
305 Expression expression;
306 for(expression = exp.cond.exp->first; expression; expression = expression.next)
308 OutputExpression(expression, f);
309 if(expression.next) f.Puts(", ");
314 OutputExpression(exp.cond.elseExp, f);
317 f.Puts("__builtin_va_arg(");
318 OutputExpression(exp.vaArg.exp, f);
320 OutputTypeName(exp.vaArg.typeName, f, false);
327 Expression expression;
328 for(expression = exp.list->first; expression; expression = expression.next)
330 OutputExpression(expression, f);
331 if(expression.next) f.Puts(", ");
339 static void OutputAsmField(AsmField field, File f)
344 OutputIdentifier(field.symbolic, f);
347 f.Puts(field.command);
351 OutputExpression(field.expression, f);
356 static void GetSourceName(char * name, const char * src)
361 if(!strchr(src, '/') && !strchr(src, '\\'))
362 StripLastDirectory(sourceFile, name);
366 PathCat(name, sourceFile);
367 ChangeCh(name, '\\', '/');
370 static void OutputStatement(Statement stmt, File f)
372 char name[MAX_FILENAME] = "";
373 char origName[MAX_FILENAME] = "";
377 GetSourceName(name, stmt.loc.start.included ? GetIncludeFileFromID(stmt.loc.start.included) : null);
379 PathCat(origName, outputFile);
380 ChangeCh(origName, '\\', '/');
384 if(inCompiler && outputLineNumbers && stmt.loc.start.line)
386 /*if(stmt.loc.start.line == 1)
388 f.Printf("\n#line %d \"%s\"\n", stmt.loc.start.line, name);
394 case badDeclarationStmt:
395 OutputDeclaration(stmt.decl, f);
398 OutputIdentifier(stmt.labeled.id, f);
401 if(stmt.labeled.stmt)
403 if(stmt.labeled.stmt.type == badDeclarationStmt) f.Puts("; ");
404 OutputStatement(stmt.labeled.stmt, f);
408 if(stmt.caseStmt.exp)
411 OutputExpression(stmt.caseStmt.exp, f);
417 f.Puts("default:\n");
420 if(stmt.caseStmt.stmt)
422 if(stmt.caseStmt.stmt.type == badDeclarationStmt) f.Puts("; ");
423 OutputStatement(stmt.caseStmt.stmt, f);
430 if(stmt.compound.declarations)
433 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
435 OutputDeclaration(decl, f);
439 if(stmt.compound.statements)
442 if(stmt.compound.declarations)
447 for(statement = stmt.compound.statements->first; statement; statement = statement.next)
449 OutputStatement(statement, f);
454 if(inCompiler && outputLineNumbers && stmt.loc.end.line)
456 /*if(stmt.loc.end.line == 1)
459 f.Printf("\n#line %d \"%s\"\n", stmt.loc.end.line, name);
471 for(exp = stmt.expressions->first; exp; exp = exp.next)
473 OutputExpression(exp, f);
474 if(exp.next) f.Puts(", ");
484 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
486 OutputExpression(exp, f);
487 if(exp.next) f.Puts(", ");
492 OutputStatement(stmt.ifStmt.stmt, f);
493 if(stmt.ifStmt.elseStmt)
498 if(stmt.ifStmt.elseStmt.type != ifStmt)
505 OutputStatement(stmt.ifStmt.elseStmt, f);
513 if(stmt.switchStmt.exp)
515 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
517 OutputExpression(exp, f);
518 if(exp.next) f.Puts(", ");
523 OutputStatement(stmt.switchStmt.stmt, f);
530 if(stmt.switchStmt.exp)
532 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
534 OutputExpression(exp, f);
535 if(exp.next) f.Puts(", ");
540 OutputStatement(stmt.whileStmt.stmt, f);
548 OutputStatement(stmt.whileStmt.stmt, f);
550 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
552 OutputExpression(exp, f);
553 if(exp.next) f.Puts(", ");
562 OutputStatement(stmt.forStmt.init, f);
564 OutputStatement(stmt.forStmt.check, f);
566 if(stmt.forStmt.increment)
568 // TESTING THIS HERE FOR FOR INCREMENT
569 if(inCompiler && outputLineNumbers && stmt.loc.end.line)
571 /*if(stmt.loc.end.line == 1)
574 f.Printf("\n#line %d \"%s\"\n", stmt.loc.end.line, name);
578 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
580 OutputExpression(exp, f);
581 if(exp.next) f.Puts(", ");
586 OutputStatement(stmt.forStmt.stmt, f);
592 OutputIdentifier(stmt.gotoStmt.id, f);
606 if(inCompiler && memoryGuard)
608 Expression exp = stmt.expressions ? stmt.expressions->last : null;
609 Type returnType = exp ? (exp.destType ? exp.destType : exp.expType) : null;
611 if(returnType && returnType.kind != voidType)
613 char string[1024] = "";
614 OldList * specs = MkList();
618 if(returnType.kind == templateType)
620 if(returnType.templateParameter.dataTypeString)
621 decl = SpecDeclFromString(returnType.templateParameter.dataTypeString, specs,
622 MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal")));
623 else if(returnType.templateParameter.dataType)
626 specs = CopyList(returnType.templateParameter.dataType.specifiers, CopySpecifier);
627 decl = PlugDeclarator(/*CopyDeclarator(*/returnType.templateParameter.dataType.decl/*)*/,
628 MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal")));
632 ListAdd(specs, MkSpecifierName("uint64"));
633 decl = MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal"));
638 // Printing 'name' as a hack when we're dealing with typedefs with extended attributes
639 if(returnType.passAsTemplate)
640 strcpy(string, "uint64");
642 PrintType /*NoConst*/(returnType, string, returnType.kind == dummyType ? true : false, true);
643 decl = SpecDeclFromString(string, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereReturnVal")));
646 typeName = MkTypeName(specs, decl);
647 InstDeclPassTypeName(typeName, false);
648 OutputTypeName(typeName, f, false);
650 FreeTypeName(typeName);
657 Expression exp = stmt.expressions ? stmt.expressions->last : null;
658 if(exp && exp.expType && exp.expType.kind != voidType)
659 f.Printf("__ecereReturnVal = ");
664 for(exp = stmt.expressions->first; exp; exp = exp.next)
666 OutputExpression(exp, f);
667 if(exp.next) f.Puts(", ");
672 if(inCompiler && memoryGuard)
674 Expression exp = stmt.expressions ? (Expression)stmt.expressions->last : null;
675 f.Printf(" __ecereNameSpace__ecere__com__MemoryGuard_PopLoc();");
676 if(exp && exp.expType && exp.expType.kind != voidType)
677 f.Printf("return __ecereReturnVal;");
690 if(stmt.asmStmt.spec)
691 OutputSpecifier(stmt.asmStmt.spec, f, false);
693 f.Puts(stmt.asmStmt.statements);
695 if(stmt.asmStmt.inputFields || stmt.asmStmt.outputFields || stmt.asmStmt.clobberedFields)
698 if(stmt.asmStmt.inputFields)
700 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
702 if(field.prev) f.Puts(",");
703 OutputAsmField(field, f);
707 if(stmt.asmStmt.outputFields || stmt.asmStmt.clobberedFields)
710 if(stmt.asmStmt.outputFields)
712 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
714 if(field.prev) f.Puts(",");
715 OutputAsmField(field, f);
719 if(stmt.asmStmt.clobberedFields)
722 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
724 if(field.prev) f.Puts(",");
725 OutputAsmField(field, f);
734 if(inCompiler && outputLineNumbers && stmt.loc.start.line)
736 f.Printf("\n#line %d \"%s\"\n", outputLine+2, origName);
741 static void OutputPointer(Pointer ptr, File f)
748 for(spec = ptr.qualifiers->first; spec; spec = spec.next)
750 OutputSpecifier(spec, f, false);
751 if(spec.next) f.Puts(" ");
756 OutputPointer(ptr.pointer, f);
760 static void OutputDeclarator(Declarator decl, File f)
764 case structDeclarator:
767 OutputDeclarator(decl.declarator, f);
769 if(decl.structDecl.exp)
772 OutputExpression(decl.structDecl.exp, f);
774 if(decl.structDecl.posExp)
777 OutputExpression(decl.structDecl.posExp, f);
779 if(decl.structDecl.attrib)
782 OutputAttrib(decl.structDecl.attrib, f);
785 case identifierDeclarator:
786 OutputIdentifier(decl.identifier, f);
788 case bracketsDeclarator:
790 OutputDeclarator(decl.declarator, f);
793 case extendedDeclarator:
794 if(decl.extended.extended) OutputExtDecl(decl.extended.extended, f);
796 OutputDeclarator(decl.declarator, f);
798 case extendedDeclaratorEnd:
799 OutputDeclarator(decl.declarator, f);
801 if(decl.extended.extended)
802 OutputExtDecl(decl.extended.extended, f);
804 case arrayDeclarator:
807 OutputDeclarator(decl.declarator, f);
813 ProcessExpressionType(decl.array.exp);
814 ComputeExpression(decl.array.exp);
816 OutputExpression(decl.array.exp, f);
818 else if(decl.array.enumClass)
820 Symbol _class = decl.array.enumClass.symbol; // FindClass(decl.array.enumClass.name);
821 if(_class && _class.registered)
823 f.Printf("%d", (int)eClass_GetProperty(_class.registered, "enumSize"));
828 case functionDeclarator:
833 OutputDeclarator(decl.declarator, f);
835 if(decl.function.parameters && decl.function.parameters->first)
837 for(param = decl.function.parameters->first; param; param = param.next)
839 OutputTypeName(param, f, false);
847 case pointerDeclarator:
848 if(decl.pointer.pointer) OutputPointer(decl.pointer.pointer, f);
852 OutputDeclarator(decl.declarator, f);
858 static void OutputEnumerator(Enumerator enumerator, File f)
860 OutputIdentifier(enumerator.id, f);
864 OutputExpression(enumerator.exp, f);
868 static void OutputAttribute(Attribute attr, File f)
875 OutputExpression(attr.exp, f);
879 static void OutputAttrib(Attrib attr, File f)
883 case ATTRIB: f.Puts("__attribute__(("); break;
884 case __ATTRIB: f.Puts("__attribute(("); break;
885 case ATTRIB_DEP: f.Puts("__attribute_deprecated__(("); break;
891 for(attrib = attr.attribs->first; attrib; attrib = attrib.next)
893 if(attrib.prev) f.Puts(" ");
894 OutputAttribute(attrib, f);
900 static void OutputExtDecl(ExtDecl extDecl, File f)
902 if(extDecl.type == extDeclString && extDecl.s)
904 else if(extDecl.type == extDeclAttrib)
905 OutputAttrib(extDecl.attr, f);
908 static void OutputSpecifier(Specifier spec, File f, bool typeName)
913 switch(spec.specifier)
958 f.Puts("_Imaginary");
970 f.Puts(typeName ? "uint" : "unsigned int");
975 f.Puts(typeName ? "int64" : "long long");
978 f.Puts("__builtin_va_list");
996 f.Puts("typed_object");
999 f.Puts("any_object");
1005 f.Puts("thisclass");
1009 case extendedSpecifier:
1011 OutputExtDecl(spec.extDecl, f);
1014 //case classSpecifier:
1015 if(spec.name && !strcmp(spec.name, "class"))
1017 f.Puts("typed_object");
1021 Symbol symbol = spec.symbol; // FindClass(spec.name);
1022 // WILL HAVE TO VERIFY THESE ELSEWHERE...
1023 if(!symbol && spec.name)
1024 symbol = FindClass(spec.name);
1027 f.Puts(symbol.string ? symbol.string : "(null)");
1039 OutputIdentifier(spec.id, f);
1043 Enumerator enumerator;
1046 for(enumerator = spec.list->first; enumerator; enumerator = enumerator.next)
1048 OutputEnumerator(enumerator, f);
1049 if(enumerator.next) f.Puts(", ");
1056 case structSpecifier:
1057 case unionSpecifier:
1059 f.Puts((spec.type == structSpecifier) ? "struct" : "union");
1060 if(spec.extDeclStruct)
1063 OutputExtDecl(spec.extDeclStruct, f);
1068 OutputIdentifier(spec.id, f);
1070 if(spec.definitions)
1075 for(def = spec.definitions->first; def; def = def.next)
1077 //OutputDeclaration(decl, f);
1078 OutputClassDef(def, f);
1080 f.Puts("} ecere_gcc_struct");
1084 case typeOfSpecifier:
1085 f.Puts("__typeof(");
1086 OutputExpression(spec.expression, f);
1089 case subClassSpecifier:
1090 f.Puts("subclass(");
1091 OutputSpecifier(spec._class, f, false);
1094 case templateTypeSpecifier:
1095 OutputIdentifier(spec.templateParameter.identifier, f);
1100 static void OutputInitializer(Initializer initializer, File f)
1102 char name[MAX_FILENAME] = "";
1103 char origName[MAX_FILENAME] = "";
1107 GetSourceName(name, initializer.loc.start.included ? GetIncludeFileFromID(initializer.loc.start.included) : null);
1109 PathCat(origName, outputFile);
1110 ChangeCh(origName, '\\', '/');
1113 if(initializer.type == listInitializer)
1117 // TODO: Add support for multiple IDs and [ ]
1119 OutputIdentifier(initializer.id, f);
1122 switch(initializer.type)
1124 case listInitializer:
1132 if(inCompiler && outputLineNumbers && initializer.loc.start.line)
1134 /*if(initializer.loc.start.line == 1)
1137 f.Printf("\n#line %d \"%s\"\n", initializer.loc.start.line, name);
1141 for(init = initializer.list->first; init; init = init.next)
1143 OutputInitializer(init, f);
1144 if(init.next) f.Puts(init.next.type == listInitializer ? "," : ", ");
1148 if(inCompiler && outputLineNumbers && initializer.loc.start.line)
1150 /*if(initializer.loc.start.line == 1)
1153 f.Printf("\n#line %d \"%s\"\n", initializer.loc.start.line, name);
1160 case expInitializer:
1164 OutputExpression(initializer.exp, f);
1169 static void OutputInitDeclarator(InitDeclarator decl, File f)
1171 OutputDeclarator(decl.declarator, f);
1172 if(decl.initializer)
1175 if(decl.initializer.type == expInitializer) f.Puts(" ");
1176 OutputInitializer(decl.initializer, f);
1180 static void OutputDeclaration(Declaration decl, File f)
1183 char origName[MAX_FILENAME];
1184 char name[MAX_FILENAME];
1188 strcpy(origName, outputFile);
1189 ChangeCh(origName, '\\', '/');
1191 GetSourceName(name, decl.loc.start.included ? GetIncludeFileFromID(decl.loc.start.included) : null);
1193 if(inCompiler && outputLineNumbers && decl.loc.start.line)
1195 f.Printf("\n#line %d \"%s\"\n", decl.loc.start.line, name);
1201 case initDeclaration:
1205 //GetWorkingDir(origName, sizeof(origName));
1207 /*if(decl.declarators && decl.declarators->first)
1209 for(d = decl.declarators->first; d; d = d.next)
1212 char name[MAX_FILENAME] = "";
1214 GetSourceName(name, decl.loc.start.included ? GetIncludeFileFromID(decl.loc.start.included) : null);
1216 if(inCompiler && outputLineNumbers && decl.loc.start.line)
1218 f.Printf("\n#line %d \"%s\"\n", decl.loc.start.line, name);
1227 bool inTypeDef = false;
1228 for(spec = decl.specifiers->first; spec; spec = spec.next)
1230 if(spec.type == baseSpecifier && spec.specifier == TYPEDEF)
1232 OutputSpecifier(spec, f, inTypeDef && !spec.next);
1233 if(spec.next) f.Puts(" ");
1236 if(decl.declarators && decl.declarators->first)
1240 for(d = decl.declarators->first; d; d = d.next)
1242 OutputInitDeclarator(d, f);
1243 if(d.next) f.Puts(", ");
1248 case structDeclaration:
1252 for(spec = decl.specifiers->first; spec; spec = spec.next)
1254 OutputSpecifier(spec, f, false);
1255 if(spec.next) f.Puts(" ");
1258 if(decl.declarators)
1263 for(d = decl.declarators->first; d; d = d.next)
1265 OutputDeclarator(d, f);
1266 if(d.next) f.Puts(", ");
1272 OutputSpecifier(decl.extStorage, f, false);
1276 case instDeclaration:
1279 OutputInstance(decl.inst, f);
1282 case defineDeclaration:
1283 return; // Skip semicolon
1287 if(inCompiler && outputLineNumbers && decl.loc.start.line)
1289 f.Printf("\n#line %d \"%s\"\n", outputLine+2, origName);
1294 static FunctionDefinition curFunction;
1296 static void OutputFunction(FunctionDefinition func, File f)
1298 FunctionDefinition oldFunc = curFunction;
1303 for(spec = func.specifiers->first; spec; spec = spec.next)
1305 OutputSpecifier(spec, f, false);
1306 if(spec.next) f.Puts(" ");
1310 if(func.declarator) OutputDeclarator(func.declarator, f);
1313 if(func.declarations)
1316 for(decl = func.declarations->first; decl; decl = decl.next)
1318 OutputDeclaration(decl, f);
1325 if(inCompiler && memoryGuard)
1327 char name[1024] = "";
1328 Identifier id = GetDeclId(func.declarator);
1330 GetSourceName(name, func.loc.start.included ? GetIncludeFileFromID(func.loc.start.included) : null);
1333 f.Printf(" __ecereNameSpace__ecere__com__MemoryGuard_PushLoc(\"%s:%s\");\n", name, id.string);
1336 OutputStatement(func.body, f);
1337 if(inCompiler && memoryGuard)
1339 f.Printf(" __ecereNameSpace__ecere__com__MemoryGuard_PopLoc();\n");
1346 curFunction = oldFunc;
1349 static void OutputMemberInit(MemberInit init, File f)
1351 if(init.identifiers)
1353 if(init.identifiers->count > 1)
1357 for(id = init.identifiers->first; id; id = id.next)
1359 OutputIdentifier(id, f);
1365 else if(init.identifiers->first)
1366 OutputIdentifier(init.identifiers->first, f);
1368 if(init.initializer && init.initializer.type == expInitializer) f.Puts(" ");
1370 if(init.initializer)
1371 OutputInitializer(init.initializer, f);
1374 static void OutputMembersInit(MembersInit init, File f)
1378 case dataMembersInit:
1381 if(init.dataMembers)
1383 for(member = init.dataMembers->first; member; member = member.next)
1385 OutputMemberInit(member, f);
1386 if(member.next) f.Puts(", ");
1391 case methodMembersInit:
1392 OutputClassFunction(init.function, f);
1397 static void OutputInstance(Instantiation inst, File f)
1400 OutputSpecifier(inst._class, f, false);
1404 OutputExpression(inst.exp, f);
1406 if(inst.members && inst.members->count > 1)
1411 else if(inst.members)
1418 for(init = inst.members->first; init; init = init.next)
1420 OutputMembersInit(init, f);
1421 if(init.type == dataMembersInit && init.next)
1434 static void OutputClassFunction(ClassFunction func, File f)
1439 for(spec = func.specifiers->first; spec; spec = spec.next)
1441 OutputSpecifier(spec, f, false);
1442 if(spec.next) f.Puts(" ");
1448 //if(func.class != (void *)-1)
1450 OutputSpecifier(func.class, f, false);
1453 if(func.declarator) OutputDeclarator(func.declarator, f);
1456 if(func.declarations)
1459 for(decl = func.declarations->first; decl; decl = decl.next)
1461 OutputDeclaration(decl, f);
1468 OutputStatement(func.body, f);
1476 static void OutputClassDef(ClassDef def, File f)
1480 case declarationClassDef:
1483 OutputDeclaration(def.decl, f);
1484 if(def.next && def.next.type != declarationClassDef)
1491 case defaultPropertiesClassDef:
1494 for(init = def.defProperties->first; init; init = init.next)
1496 OutputMemberInit(init, f);
1497 if(init.next) f.Puts(", ");
1503 case functionClassDef:
1504 OutputClassFunction(def.function, f);
1511 static void OutputClass(ClassDefinition _class, File f)
1514 OutputSpecifier(_class._class, f, false);
1515 if(_class.baseSpecs)
1520 for(spec = _class.baseSpecs->first; spec; spec = spec.next)
1522 OutputSpecifier(spec, f, false);
1525 if(_class.definitions)
1530 for(def = _class.definitions->first; def; def = def.next)
1532 OutputClassDef(def, f);
1541 public void OutputTree(OldList ast, File f)
1545 outputLine = NUM_ECC_ADDED_LINES;
1547 for(external = ast.first; external; external = external.next)
1549 switch(external.type)
1551 case functionExternal:
1552 OutputFunction(external.function, f);
1556 case declarationExternal:
1557 if(external.declaration)
1558 OutputDeclaration(external.declaration, f);
1563 OutputClass(external._class, f);
1571 public void OutputExternal(External external, File f)
1573 switch(external.type)
1575 case functionExternal:
1576 OutputFunction(external.function, f);
1580 case declarationExternal:
1581 if(external.declaration)
1582 OutputDeclaration(external.declaration, f);
1587 OutputClass(external._class, f);
1594 public char * StringFromSpecDecl(OldList specs, Declarator decl)
1597 TypeName typeName { };
1598 File f = TempFile { };
1601 typeName.qualifiers = specs;
1602 typeName.declarator = decl;
1604 OutputTypeName(typeName, f, true);
1609 string = new char[size + 1];
1611 f.Read(string, 1, size);
1612 string[size] = '\0';
1613 TrimRSpaces(string, string);