3 #define YYLTYPE Location
6 extern External curExternal;
7 ///////////////// INSTANCE DECLARATION PASS ///////////////////////
9 // Returns true if we should add a * to the declarator
10 static int ReplaceClassSpec(OldList specs, Specifier spec, bool param)
12 if(spec.type == templateTypeSpecifier)
14 TemplateParameter parameter = spec.templateParameter;
16 if(!param && parameter.dataTypeString)
18 OldList * newSpecs = MkList();
19 Declarator decl = SpecDeclFromString(parameter.dataTypeString, newSpecs, null);
22 Specifier newSpec = CopySpecifier(newSpecs->first);
26 FreeList(newSpecs, FreeSpecifier);
30 bool isPointer = decl.type == pointerDeclarator;
37 else if(!param && parameter.dataType)
39 OldList * newSpecs = parameter.dataType.specifiers;
40 Declarator decl = parameter.dataType.decl;
43 Specifier newSpec = CopySpecifier(newSpecs->first);
50 bool isPointer = decl.type == pointerDeclarator;
57 spec.type = nameSpecifier;
58 spec.name = CopyString("uint64");
59 spec.symbol = FindClass("uint64");
63 if(spec.type == nameSpecifier || spec.type == subClassSpecifier)
65 // TODO: Apply more care because nameSpecifier / subClassSpecifier use different parts of the union!
66 Symbol classSym = spec.symbol;
67 if(spec.type == subClassSpecifier)
69 classSym = FindClass("ecere::com::Class");
74 Class _class = classSym.registered;
76 FreeSpecifierContents(spec);
78 spec.type = nameSpecifier;
79 if(_class && _class.type == structClass)
84 FullClassNameCat(name, _class.fullName, false);
85 FreeSpecifierContents(spec);
86 spec.type = structSpecifier;
87 spec.baseSpecs = null;
88 spec.id = MkIdentifier(name);
90 spec.definitions = null;
92 spec.addNameSpace = false;
94 else if(_class && _class.type == noHeadClass)
97 FullClassNameCat(name, _class.fullName, false);
98 spec.type = structSpecifier;
99 spec.baseSpecs = null;
100 spec.id = MkIdentifier(name);
102 spec.definitions = null;
104 spec.addNameSpace = false;
108 if((_class.type != systemClass ||
109 !strcmp(_class.fullName, "enum") ||
110 (_class.dataTypeString && !strcmp(_class.dataTypeString, "char *")) ||
111 //strcmp(_class.fullName, "bool") &&
112 !strcmp(_class.fullName, "uint64") ||
113 !strcmp(_class.fullName, "uint32") ||
114 !strcmp(_class.fullName, "uint16") ||
115 !strcmp(_class.fullName, "uintptr") ||
116 !strcmp(_class.fullName, "intptr") ||
117 !strcmp(_class.fullName, "uintsize") ||
118 !strcmp(_class.fullName, "intsize") ||
119 !strcmp(_class.fullName, "uint") ||
120 !strcmp(_class.fullName, "byte")))
122 if(_class.dataTypeString)
124 if(!strcmp(_class.dataTypeString, "uint64") ||
125 !strcmp(_class.dataTypeString, "uint32") ||
126 !strcmp(_class.dataTypeString, "uint16") ||
127 !strcmp(_class.dataTypeString, "uintptr") ||
128 !strcmp(_class.dataTypeString, "intptr") ||
129 !strcmp(_class.dataTypeString, "uintsize") ||
130 !strcmp(_class.dataTypeString, "intsize") ||
131 !strcmp(_class.dataTypeString, "uint") ||
132 !strcmp(_class.dataTypeString, "byte"))
135 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
136 if(_class.dataType && _class.dataType.kind == classType)
137 classSym = _class.dataType._class;
139 classSym = FindClass(_class.dataTypeString);
140 _class = classSym ? classSym.registered : null;
143 spec.name = CopyString(!strcmp(_class.dataTypeString, "char *") ? "char" : _class.dataTypeString);
148 spec.name = CopyString(null);
152 else if(!_class.base)
154 spec.type = baseSpecifier;
155 spec.specifier = VOID;
161 spec.type = structSpecifier;
162 spec.id = MkIdentifier("__ecereNameSpace__ecere__com__Instance");
164 spec.baseSpecs = null;
165 spec.definitions = null;
167 spec.addNameSpace = false;
170 if(_class && _class.dataTypeString && !strcmp(_class.dataTypeString, "char *"))
172 if(!_class || _class.type == normalClass || _class.type == noHeadClass)
174 else if(param && _class.type == structClass)
178 else if(spec.type == baseSpecifier)
180 if(spec.specifier == ANY_OBJECT || spec.specifier == CLASS)
182 spec.specifier = CONST;
183 specs.Add(MkSpecifier(VOID));
190 static void ReplaceByInstancePtr(Specifier spec, Declarator * declPtr, int type)
192 Declarator decl = *declPtr;
193 if(decl && decl.type == pointerDeclarator)
195 // Pointers to simple classes shouldn't be added pointers
199 decl.pointer.pointer = MkPointer(null, decl.pointer.pointer);
203 Declarator newDecl { };
207 decl.declarator = newDecl;
211 decl.type = pointerDeclarator;
212 decl.pointer.pointer = MkPointer(null, null);
217 static void InstDeclPassSpecifier(Specifier spec, bool byRefTypedObject)
222 if(spec.specifier == TYPED_OBJECT)
224 spec.type = extendedSpecifier;
225 spec.extDecl = MkExtDeclString(CopyString(byRefTypedObject ?
226 "struct __ecereNameSpace__ecere__com__Class * class, void *" :
227 "struct __ecereNameSpace__ecere__com__Class * class, const void *"));
228 DeclareStruct(curExternal, "ecere::com::Class", false, true);
238 for(e = spec.list->first; e; e = e.next)
245 case structSpecifier:
251 for(def = spec.definitions->first; def; def = def.next)
253 InstDeclPassDeclaration(def.decl);
256 InstDeclPassIdentifier(spec.id);
259 case extendedSpecifier:
260 if(spec.extDecl && spec.extDecl.type == extDeclString && spec.extDecl.s)
262 if(!strcmp(spec.extDecl.s, "dllexport"))
265 delete spec.extDecl.s;
266 for(prevSpec = spec.prev; prevSpec; prevSpec = prevSpec.prev)
267 if(prevSpec.type == baseSpecifier && prevSpec.specifier == EXTERN)
271 if(targetPlatform == win32)
272 spec.extDecl.s = CopyString("__declspec(dllexport)");
274 spec.extDecl.s = CopyString("__attribute__ ((visibility(\"default\")))");
278 if(targetPlatform == win32)
279 spec.extDecl.s = CopyString("extern __declspec(dllexport)");
281 spec.extDecl.s = CopyString("extern __attribute__ ((visibility(\"default\")))");
284 else if(!strcmp(spec.extDecl.s, "stdcall") || !strcmp(spec.extDecl.s, "_stdcall") ||
285 !strcmp(spec.extDecl.s, "__stdcall") || !strcmp(spec.extDecl.s, "__stdcall__"))
287 delete spec.extDecl.s;
288 spec.extDecl.s = CopyString("ecere_stdcall");
295 static void InstDeclPassDeclarator(Declarator decl)
299 case structDeclarator:
301 InstDeclPassDeclarator(decl.declarator);
303 case identifierDeclarator:
306 InstDeclPassIdentifier(decl.identifier);
309 case bracketsDeclarator:
311 InstDeclPassDeclarator(decl.declarator);
313 case arrayDeclarator:
315 InstDeclPassDeclarator(decl.declarator);
317 case functionDeclarator:
320 InstDeclPassDeclarator(decl.declarator);
321 if(decl.function.parameters)
325 InstDeclPassDeclarator(decl.declarator);
326 for(type = decl.function.parameters->first; type; type = type.next)
328 bool typedObject = false;
329 Specifier spec = null;
332 spec = (Specifier)type.qualifiers->first;
333 if(spec && spec.type == nameSpecifier && !strcmp(spec.name, "class"))
337 InstDeclPassTypeName(type, true);
342 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
343 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
345 DeclareStruct(curExternal, "ecere::com::Class", false, true);
346 decl.function.parameters->Insert(spec.prev, _class);
352 case pointerDeclarator:
353 case extendedDeclarator:
354 case extendedDeclaratorEnd:
355 if((decl.type == extendedDeclarator || decl.type == extendedDeclaratorEnd) && decl.extended.extended)
357 if(decl.extended.extended.type == extDeclString && decl.extended.extended.s && !strcmp(decl.extended.extended.s, "dllexport"))
359 delete decl.extended.extended.s;
360 if(targetPlatform == win32)
361 decl.extended.extended.s = CopyString("extern __declspec(dllexport)");
363 decl.extended.extended.s = CopyString("extern __attribute__ ((visibility(\"default\")))");
365 else if(decl.extended.extended.type == extDeclString && decl.extended.extended.s &&
366 (!strcmp(decl.extended.extended.s, "stdcall") || !strcmp(decl.extended.extended.s, "_stdcall") ||
367 !strcmp(decl.extended.extended.s, "__stdcall") || !strcmp(decl.extended.extended.s, "__stdcall__")))
369 delete decl.extended.extended.s;
370 decl.extended.extended.s = CopyString("ecere_stdcall");
374 InstDeclPassDeclarator(decl.declarator);
379 /*static */void InstDeclPassTypeName(TypeName type, bool param)
384 for(spec = type.qualifiers->first; spec; spec = spec.next)
387 if((result = ReplaceClassSpec(type.qualifiers, spec, param)))
388 ReplaceByInstancePtr(spec, &type.declarator, result);
391 Symbol classSym = (spec.type == nameSpecifier) ? spec.symbol /*FindClass(spec.name)*/ : null;
392 if(type.classObjectType && (!classSym || (classSym && classSym.registered &&
393 (classSym.registered.type == enumClass || classSym.registered.type == bitClass || classSym.registered.type == unitClass))))
394 ReplaceByInstancePtr(spec, &type.declarator, 2);
396 InstDeclPassSpecifier(spec, type.declarator && type.declarator.type == pointerDeclarator);
400 InstDeclPassDeclarator(type.declarator);
403 static void InstDeclPassIdentifier(Identifier id)
405 if(strchr(id.string, ':'))
411 strcpy(newID, "__ecereNameSpace__");
414 for(c = 0; (ch = id.string[c]); c++)
416 if(ch == ':') ch = '_';
422 id.string = CopyString(newID);
426 /*static */bool IsVoidPtrCast(TypeName typeName)
429 Declarator d = typeName.declarator;
430 if(d && d.type == pointerDeclarator && d.pointer.pointer && !d.pointer.pointer.pointer)
432 if(typeName.qualifiers)
435 for(s = typeName.qualifiers->first; s; s = s.next)
437 if(s.type == baseSpecifier && s.specifier == VOID)
445 static void AddPointerCast(Expression e)
447 Type src = e.expType;
449 if(src && (src.kind == templateType || src.kind == classType))
451 if(e.type != castExp || !IsVoidPtrCast(e.cast.typeName))
453 if(src) src.refCount++;
454 if(src.kind == templateType && src.templateParameter && src.templateParameter.type == type)
457 if(src.templateParameter.dataTypeString)
458 newType = ProcessTypeString(src.templateParameter.dataTypeString, false);
459 else if(src.templateParameter.dataType)
460 newType = ProcessType(src.templateParameter.dataType.specifiers, src.templateParameter.dataType.decl);
467 if(src && src.kind == classType && src._class)
469 Class sc = src._class.registered;
470 if(src.thisClassFrom && src.thisClassFrom.base)
471 sc = src.thisClassFrom;
473 if(sc && (sc.type == structClass || sc.type == noHeadClass))
475 Type dest = e.destType;
477 if(dest && (dest.kind == templateType || dest.kind == classType))
479 if(dest) dest.refCount++;
481 if(dest.kind == templateType && dest.templateParameter && dest.templateParameter.type == type)
484 if(dest.templateParameter.dataTypeString)
485 newType = ProcessTypeString(dest.templateParameter.dataTypeString, false);
486 else if(dest.templateParameter.dataType)
487 newType = ProcessType(dest.templateParameter.dataType.specifiers, dest.templateParameter.dataType.decl);
494 if(!dest.passAsTemplate && dest.kind == classType && dest._class && dest._class.registered)
496 Class dc = dest._class.registered;
498 if(sc.templateClass) sc = sc.templateClass;
499 if(dc.templateClass) dc = dc.templateClass;
500 if(dc.base && sc != dc)
502 e.cast.exp = MkExpBrackets(MkListOne(MoveExpContents(e)));
504 e.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), QMkPtrDecl(null));
514 else if(src && src.kind == intPtrType && e.destType && e.destType.classObjectType)
516 Expression nbExp = GetNonBracketsExp(e);
517 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
519 e.cast.exp = MkExpBrackets(MkListOne(MoveExpContents(e)));
521 e.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), QMkPtrDecl(null));
526 static void InstDeclPassExpression(Expression exp)
533 InstDeclPassIdentifier(exp.identifier);
542 InstDeclPassExpression(exp.op.exp1);
545 InstDeclPassExpression(exp.op.exp2);
546 if(exp.op.op != '=' && exp.op.exp1 && exp.op.exp1.expType && exp.op.exp1.expType.kind == pointerType && exp.op.exp1.expType.type && exp.op.exp1.expType.type.kind == templateType &&
547 exp.op.exp2.expType && exp.op.exp2.expType.kind == pointerType && exp.op.exp2.expType.type && exp.op.exp2.expType.type.kind == templateType)
549 Expression e = exp.op.exp2;
550 e.cast.exp = MkExpBrackets(MkListOne(MoveExpContents(e)));
552 e.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), QMkPtrDecl(null));
555 e.cast.exp = MkExpBrackets(MkListOne(MoveExpContents(e)));
557 e.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), QMkPtrDecl(null));
559 else if(exp.op.exp1 && (exp.op.op == '=' || exp.op.op == EQ_OP || exp.op.op == NE_OP))
560 AddPointerCast(exp.op.exp2);
563 case extensionExpressionExp:
567 for(e = exp.list->first; e; e = e.next)
568 InstDeclPassExpression(e);
574 InstDeclPassExpression(exp.index.exp);
575 for(e = exp.index.index->first; e; e = e.next)
576 InstDeclPassExpression(e);
582 InstDeclPassExpression(exp.call.exp);
583 if(exp.call.arguments)
585 for(e = exp.call.arguments->first; e; e = e.next)
587 bool addCast = false;
588 InstDeclPassExpression(e);
591 if(e.expType && e.expType.kind == pointerType && e.expType.type && (e.expType.type.kind == classType || (e.expType.type.kind == pointerType && e.expType.type.type && e.expType.type.type.kind != voidType)) &&
592 e.destType && e.destType.kind == pointerType && e.destType.type && e.destType.type.kind == pointerType && e.destType.type.type && e.destType.type.type.kind == voidType)
594 // Fix for adding a cast to Unserialize with a struct passed as a parameter:
595 else if(e.expType && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass && e.byReference &&
596 e.destType && e.destType.kind == classType && e.destType.classObjectType && e.destType.byReference)
599 if(addCast && (e.type != castExp || !IsVoidPtrCast(e.cast.typeName)))
601 e.cast.exp = MkExpBrackets(MkListOne(MoveExpContents(e)));
603 e.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), QMkPtrDecl(null));
612 InstDeclPassExpression(exp.member.exp);
618 InstDeclPassExpression(exp.member.exp);
622 InstDeclPassTypeName(exp.typeName, false);
626 Type type = exp.expType;
627 // Remove casts to simple structs... (Watch out for pointers later...)
628 if(type && type.kind == classType && type._class.registered && type._class.registered.type == structClass && !exp.needCast)
630 if(exp.destType && exp.destType.classObjectType == typedObject && exp.destType.byReference)
632 // For Unserialize with a StaticString
633 FreeTypeName(exp.cast.typeName);
634 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, MkPointer(null, null)), null));
638 Expression castExp = exp.cast.exp;
639 Expression prev = exp.prev, next = exp.next;
641 FreeExpContents(exp);
642 FreeType(exp.expType);
643 FreeType(exp.destType);
648 InstDeclPassExpression(exp);
653 if(exp.expType && exp.expType.kind == pointerType)
655 if(exp.cast.exp && exp.cast.exp.expType && exp.cast.exp.expType.kind == templateType && !exp.cast.exp.expType.isPointerType)
656 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), exp.cast.exp);
659 InstDeclPassTypeName(exp.cast.typeName, exp.usage.usageArg /*false*/);
662 if(exp.expType && exp.expType.kind == templateType && exp.destType &&
663 (exp.destType.passAsTemplate || (!exp.destType.templateParameter || (!exp.destType.templateParameter.dataType && !exp.destType.templateParameter.dataTypeString))) &&
664 exp.cast.exp.expType && !exp.cast.exp.expType.passAsTemplate && exp.cast.exp.expType.isPointerType)
665 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), exp.cast.exp);
666 InstDeclPassExpression(exp.cast.exp);
674 InstDeclPassExpression(exp.cond.cond);
675 for(e = exp.cond.exp->first; e; e = e.next)
676 InstDeclPassExpression(e);
678 InstDeclPassExpression(exp.cond.elseExp);
681 case extensionCompoundExp:
683 InstDeclPassStatement(exp.compound);
688 InstDeclPassExpression(exp.vaArg.exp);
691 case extensionInitializerExp:
693 InstDeclPassTypeName(exp.initializer.typeName, false);
694 InstDeclPassInitializer(exp.initializer.initializer);
700 static void InstDeclPassInitializer(Initializer init)
707 InstDeclPassExpression(init.exp);
708 AddPointerCast(init.exp);
711 case listInitializer:
714 for(i = init.list->first; i; i = i.next)
715 InstDeclPassInitializer(i);
721 static void InstDeclPassDeclaration(Declaration decl)
725 case initDeclaration:
730 for(spec = decl.specifiers->first; spec; spec = spec.next)
733 if((type = ReplaceClassSpec(decl.specifiers, spec, false)))
738 for(d = decl.declarators->first; d; d = d.next)
739 ReplaceByInstancePtr(spec, &d.declarator, type);
742 InstDeclPassSpecifier(spec, false);
748 for(d = decl.declarators->first; d; d = d.next)
750 InstDeclPassDeclarator(d.declarator);
752 InstDeclPassInitializer(d.initializer);
757 case structDeclaration:
762 for(spec = decl.specifiers->first; spec; spec = spec.next)
765 if((type = ReplaceClassSpec(decl.specifiers, spec, false)))
770 for(d = decl.declarators->first; d; d = d.next)
771 ReplaceByInstancePtr(spec, &d, type);
774 InstDeclPassSpecifier(spec, false);
781 for(d = decl.declarators->first; d; d = d.next)
782 InstDeclPassDeclarator(d);
786 // This should be removed by now?
787 case instDeclaration:
788 // InstDeclPassInstantiation(decl.inst);
793 static void InstDeclPassStatement(Statement stmt)
797 case badDeclarationStmt:
799 InstDeclPassDeclaration(stmt.decl);
802 InstDeclPassStatement(stmt.labeled.stmt);
805 // This expression should be constant...
806 if(stmt.caseStmt.exp)
807 InstDeclPassExpression(stmt.caseStmt.exp);
808 if(stmt.caseStmt.stmt)
809 InstDeclPassStatement(stmt.caseStmt.stmt);
815 Context prevContext = curContext;
817 if(!stmt.compound.isSwitch)
818 curContext = stmt.compound.context;
820 if(stmt.compound.declarations)
822 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
823 InstDeclPassDeclaration(decl);
825 if(stmt.compound.statements)
827 for(s = stmt.compound.statements->first; s; s = s.next)
828 InstDeclPassStatement(s);
830 curContext = prevContext;
838 for(exp = stmt.expressions->first; exp; exp = exp.next)
839 InstDeclPassExpression(exp);
848 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
849 InstDeclPassExpression(exp);
852 InstDeclPassStatement(stmt.ifStmt.stmt);
853 if(stmt.ifStmt.elseStmt)
854 InstDeclPassStatement(stmt.ifStmt.elseStmt);
860 if(stmt.switchStmt.exp)
862 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
863 InstDeclPassExpression(exp);
865 InstDeclPassStatement(stmt.switchStmt.stmt);
871 if(stmt.whileStmt.exp)
873 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
874 InstDeclPassExpression(exp);
876 InstDeclPassStatement(stmt.whileStmt.stmt);
884 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
885 InstDeclPassExpression(exp);
887 if(stmt.doWhile.stmt)
888 InstDeclPassStatement(stmt.doWhile.stmt);
894 if(stmt.forStmt.init)
895 InstDeclPassStatement(stmt.forStmt.init);
896 if(stmt.forStmt.check)
897 InstDeclPassStatement(stmt.forStmt.check);
898 if(stmt.forStmt.increment)
900 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
901 InstDeclPassExpression(exp);
903 if(stmt.forStmt.stmt)
904 InstDeclPassStatement(stmt.forStmt.stmt);
918 for(exp = stmt.expressions->first; exp; exp = exp.next)
919 InstDeclPassExpression(exp);
920 AddPointerCast(stmt.expressions->last);
927 if(stmt.asmStmt.inputFields)
929 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
931 InstDeclPassExpression(field.expression);
933 if(stmt.asmStmt.outputFields)
935 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
937 InstDeclPassExpression(field.expression);
939 if(stmt.asmStmt.clobberedFields)
941 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
943 InstDeclPassExpression(field.expression);
950 void TopoSort(OldList * input)
958 for(n = input->first; n; n = next)
961 if(n.type == declarationExternal && !n.declaration)
964 if(n.symbol && n.symbol.structExternal == n)
965 n.symbol.structExternal = null;
968 else if(!n.incoming.count)
973 else if(!n.nonBreakableIncoming)
980 for(x = input->first; x; x = x.next)
983 for(e : x.incoming; !e.breakable)
985 if(count != x.nonBreakableIncoming)
986 printf("Bug in input");
988 if(!x.incoming.count)
989 printf("This node should be in S!\n");
992 External y, from = e.from;
993 for(y = input->first; y; y = y.next)
998 for(y = B.first; y; y = y.next)
1005 for(y = S.first; y; y = y.next)
1011 printf("This node is nowhere!\n");
1022 for(x = input->first; x; x = x.next)
1025 for(e : x.incoming; !e.breakable)
1027 if(count != x.nonBreakableIncoming)
1028 printf("Bug in input");
1029 if(!x.incoming.count)
1030 printf("This node should be in S!\n");
1033 External y, from = e.from;
1034 for(y = input->first; y; y = y.next)
1039 for(y = B.first; y; y = y.next)
1046 for(y = S.first; y; y = y.next)
1052 printf("This node is nowhere!\n");
1057 //DebugPrint("*** Free Node: [", n.id, "]\n\t", n.output);
1058 S.Remove((IteratorPointer)n);
1061 if(n && n.symbol && n.symbol.string && !strcmp(n.symbol.string, "ecere::com::Instance"))
1062 printf("Adding Instance\n");
1066 for(e = n.outgoing.first; e; e = ne)
1071 //DebugPrint(" This Free Node has an edge to [", m.id, "] ", m.output);
1072 if(m.nonBreakableIncoming)
1074 //DebugPrint("... which we think is in input");
1079 //DebugPrint("... which we think is in B");
1084 PrintLn("!!! Something's wrong !!!");
1090 if(!m.nonBreakableIncoming)
1093 m.nonBreakableIncoming--;
1094 //DebugPrint("Reducing non breakable incoming, now ", m.nonBreakableIncoming);
1097 n.outgoing.Remove((IteratorPointer)e);
1098 m.incoming.Remove((IteratorPointer)e);
1101 if(!m.incoming.count)
1103 //DebugPrint("Last edge to this node taken out, moving to S...");
1107 else if(!m.nonBreakableIncoming)
1109 //DebugPrint("Last non-breakable edge to this node taken out, moving to B...");
1115 else if((n = B.first))
1117 //DebugPrint("Breaking some of the ", n.incoming.count, " incoming edges to [", n.id, "] ", n.output);
1118 B.Remove((IteratorPointer)n);
1120 // Break the edges of this node
1121 for(e = n.incoming.first; e; e = ne)
1124 External m = e.from;
1127 for(x = input->first; x; x = x.next)
1130 for(e : x.incoming; !e.breakable)
1132 if(count != x.nonBreakableIncoming)
1133 printf("Bug in input");
1134 if(!x.incoming.count)
1135 printf("This node should be in S!\n");
1138 External y, from = e.from;
1139 for(y = input->first; y; y = y.next)
1144 for(y = B.first; y; y = y.next)
1151 for(y = S.first; y; y = y.next)
1157 printf("This node is nowhere!\n");
1162 f = m.ForwardDeclare();
1165 for(x = input->first; x; x = x.next)
1168 for(e : x.incoming; !e.breakable)
1170 if(count != x.nonBreakableIncoming)
1171 printf("Bug in input");
1172 if(!x.incoming.count)
1173 printf("This node should be in S!\n");
1176 External y, from = e.from;
1177 for(y = input->first; y; y = y.next)
1182 for(y = B.first; y; y = y.next)
1189 for(y = S.first; y; y = y.next)
1193 if(!y && from != n && from != f)
1195 printf("This node is nowhere!\n");
1200 // Recheck input for edges created by forward declaration
1203 for(c = input->first; c; c = next)
1206 if(!c.incoming.count)
1211 else if(!c.nonBreakableIncoming)
1219 //DebugPrint("Breaking edge from ", e.from.id, " to ", e.to.id);
1220 //DebugPrint("Creating a forward decl node [", f.id, "] for [", m.id, "]");
1222 for(e2 = m.outgoing.first; e2; e2 = n2)
1227 External to = e2.to;
1230 ;//DebugPrint("Breaking this particular connection");
1232 ;//DebugPrint("Also redirecting connection from ", m.id, " to ", to.id, " to come from ", f.id, " instead.");
1233 e2.breakable = false;
1235 m.outgoing.Remove((IteratorPointer)e2);
1237 to.nonBreakableIncoming++;
1238 if(e2 != e && to.nonBreakableIncoming == 1)
1240 // If this node was previously in B, move it to input
1245 //DebugPrint("Node ", e2.to.id, " now has ", e2.to.nonBreakableIncoming, " non-breakable incoming edges.");
1249 for(x = input->first; x; x = x.next)
1252 for(e : x.incoming; !e.breakable)
1254 if(count != x.nonBreakableIncoming)
1255 printf("Bug in input");
1256 if(!x.incoming.count)
1257 printf("This node should be in S!\n");
1260 External y, from = e.from;
1261 for(y = input->first; y; y = y.next)
1266 for(y = B.first; y; y = y.next)
1273 for(y = S.first; y; y = y.next)
1277 if(!y && from != n && from != f)
1279 printf("This node is nowhere!\n");
1283 if(!f.incoming.count)
1285 else if(!f.nonBreakableIncoming)
1290 for(x = input->first; x; x = x.next)
1293 for(e : x.incoming; !e.breakable)
1295 if(count != x.nonBreakableIncoming)
1296 printf("Bug in input");
1297 if(!x.incoming.count)
1298 printf("This node should be in S!\n");
1301 External y, from = e.from;
1302 for(y = input->first; y; y = y.next)
1307 for(y = B.first; y; y = y.next)
1314 for(y = S.first; y; y = y.next)
1321 for(y = L.first; y; y = y.next)
1324 PrintLn("This node is already in L!");
1331 ConsoleFile file { };
1332 printf("This node is nowhere!\n");
1333 OutputExternal(from, file);
1339 // Avoid needless edge breaking by processing a node as soon as one shows up in S
1344 // Put n back in input because it now has unbreakable edges
1353 External e = input->first;
1355 Compiler_Error("declarations cycles found\n");
1357 //OutputTree(input, f);
1359 for(x = input->first; x; x = x.next)
1362 for(e : x.incoming; !e.breakable)
1364 if(count != x.nonBreakableIncoming)
1365 printf("Bug in input");
1366 if(!x.incoming.count)
1367 printf("This node should be in S!\n");
1371 External y, from = e.from;
1372 for(y = input->first; y; y = y.next)
1377 for(y = B.first; y; y = y.next)
1384 for(y = S.first; y; y = y.next)
1390 printf("This node is nowhere!\n");
1395 SetOutputLineNumbers(false);
1396 OutputExternal(e, f);
1398 PrintLn("\nDepends on:\n");
1399 { TopoEdge i; for(i = e.incoming.last; i && !i.breakable && i.from.incoming.count; i = i.in.next) { e = i.from; break; } }
1401 OutputExternal(e, f);
1403 PrintLn("\nWhile that depends on:\n");
1404 { TopoEdge i; for(i = e.incoming.first; i && !i.breakable && i.from.incoming.count; i = i.in.next) { e = i.from; break; } }
1406 OutputExternal(e, f);
1408 PrintLn("\nWhile that depends on:\n");
1409 { TopoEdge i; for(i = e.incoming.first; i && !i.breakable && i.from.incoming.count; i = i.in.next) { e = i.from; break; } }
1411 OutputExternal(e, f);
1413 PrintLn("\nWhile that depends on:\n");
1414 { TopoEdge i; for(i = e.incoming.first; i && !i.breakable && i.from.incoming.count; i = i.in.next) { e = i.from; break; } }
1416 OutputExternal(e, f);
1421 while((e = input->first))
1435 for(n = input->first; n; n = next)
1438 if(n.type == declarationExternal && (!n.declaration || ((!n.declaration.specifiers || !n.declaration.specifiers->count) && (!n.declaration.declarators || !n.declaration.declarators->count))))
1441 if(n.symbol && n.symbol.structExternal == n)
1442 n.symbol.structExternal = null;
1448 public void ProcessInstanceDeclarations()
1451 curContext = globalContext;
1452 for(external = ast->first; external; external = external.next)
1454 curExternal = external;
1455 if(external.type == functionExternal)
1457 FunctionDefinition func = external.function;
1461 for(spec = func.specifiers->first; spec; spec = spec.next)
1464 if((type = ReplaceClassSpec(func.specifiers, spec, false)))
1465 ReplaceByInstancePtr(spec, &func.declarator, type);
1466 InstDeclPassSpecifier(spec, false);
1469 InstDeclPassDeclarator(func.declarator);
1471 InstDeclPassStatement(func.body);
1473 else if(external.type == declarationExternal)
1475 if(external.declaration)
1476 InstDeclPassDeclaration(external.declaration);
1480 // Perform topological sort