5 void FreeList(OldList list, void (* FreeFunction)(void *))
10 while((item = list.first))
19 public void FreeType(Type type)
24 if(type.refCount <= 0)
30 NamedLink64 member, next;
32 for(member = type.members.first; member; member = next)
35 type.members.Remove(member);
46 for(member = type.members.first; member; member = next)
49 // Remove from list only when reaching last reference
50 // (The list is copied)
51 if(member.refCount == 1)
52 type.members.Remove(member);
61 FreeType(type.returnType);
62 for(param = type.params.first; param; param = next)
65 // WARNING: Don't unlink these as they might be reused
66 // type.params.Remove(param);
72 if(type.freeExp && type.arraySizeExp)
73 FreeExpression(type.arraySizeExp);
86 void FreeSymbol(Symbol symbol)
90 if(symbol.propCategory)
91 FreeExpression(symbol.propCategory);
93 FreeType(symbol.type);
95 while((link = symbol.templatedClasses.first))
96 symbol.templatedClasses.Delete(link);
100 if(symbol.templateParams)
101 FreeList(symbol.templateParams, FreeTemplateParameter);
103 // Used to be in ClassDefinition
104 delete symbol.constructorName;
105 delete symbol.structName;
106 delete symbol.className;
107 delete symbol.destructorName;
108 delete symbol.shortName;
111 FreeContext(symbol.ctx);
117 void FreeMethodImport(MethodImport imp)
122 void FreePropertyImport(MethodImport imp)
127 void FreeClassImport(ClassImport imp)
130 imp.methods.Free(FreeMethodImport);
131 imp.properties.Free(FreePropertyImport);
134 void FreeFunctionImport(ClassImport imp)
139 public void FreeModuleImport(ModuleImport imp)
142 imp.classes.Free(FreeClassImport);
143 imp.functions.Free(FreeFunctionImport);
146 public void FreeModuleDefine(Definition def)
151 public void FreeExcludedSymbols(OldList excludedSymbols)
155 while((symbol = excludedSymbols.first))
157 excludedSymbols.Remove(symbol);
162 public void FreeTemplateArgument(TemplateArgument arg)
168 FreeExpression(arg.expression);
172 FreeIdentifier(arg.identifier);
175 if(arg.templateDatatype)
176 FreeTemplateDataType(arg.templateDatatype);
180 FreeIdentifier(arg.name);
184 public void FreeTemplateDataType(TemplateDatatype type)
187 FreeDeclarator(type.decl);
189 FreeList(type.specifiers, FreeSpecifier);
193 public void FreeTemplateParameter(TemplateParameter param)
197 FreeIdentifier(param.identifier);
199 if(param.type == type || param.type == expression)
202 FreeTemplateDataType(param.dataType);
204 if(param.defaultArgument)
205 FreeTemplateArgument(param.defaultArgument);
207 FreeType(param.baseType);
211 public void FreeTemplateType(TemplatedType type)
215 FreeTemplateParameter(type.param);
220 public void FreeContext(Context context)
224 if(context == curContext)
225 curContext = globalContext;
227 while((symbol = (Symbol)context.types.root))
229 context.types.Remove((BTNode)symbol);
232 while((symbol = (Symbol)context.classes.root))
234 context.classes.Remove((BTNode)symbol);
237 while((symbol = (Symbol)context.symbols.root))
239 context.symbols.Remove((BTNode)symbol);
242 while((symbol = (Symbol)context.structSymbols.root))
244 context.structSymbols.Remove((BTNode)symbol);
247 while((symbol = (Symbol)context.templateTypes.root))
249 context.templateTypes.Remove((BTNode)symbol);
250 FreeTemplateType((TemplatedType)symbol);
254 context.simpleID = 0;
255 context.parent = null;
258 void FreeEnumerator(Enumerator enumerator)
261 FreeIdentifier(enumerator.id);
263 FreeExpression(enumerator.exp);
268 void FreeSpecifier(Specifier spec)
272 FreeSpecifierContents(spec);
277 void FreeSpecifierContents(Specifier spec)
282 //case classSpecifier:
284 if(spec.templateArgs)
286 FreeList(spec.templateArgs, FreeTemplateArgument);
287 spec.templateArgs = null;
291 FreeSpecifier(spec.nsSpec);
295 case extendedSpecifier:
298 FreeExtDecl(spec.extDecl);
305 FreeList(spec.baseSpecs, FreeSpecifier);
306 spec.baseSpecs = null;
310 FreeIdentifier(spec.id);
315 FreeList(spec.list, FreeEnumerator);
320 FreeList(spec.definitions, FreeClassDef);
321 spec.definitions = null;
324 case structSpecifier:
328 FreeIdentifier(spec.id);
333 FreeList(spec.definitions, FreeClassDef);
334 spec.definitions = null;
338 FreeList(spec.baseSpecs, FreeSpecifier);
339 spec.baseSpecs = null;
341 if(spec.extDeclStruct)
343 FreeExtDecl(spec.extDeclStruct);
344 spec.extDeclStruct = null;
348 FreeContext(spec.ctx);
352 case subClassSpecifier:
355 FreeSpecifier(spec._class);
362 public void FreeIdentifier(Identifier id)
365 FreeIdentifier(id.badID);
368 FreeSpecifier(id._class);
372 void FreeTypeName(TypeName typeName)
374 if(typeName.qualifiers)
375 FreeList(typeName.qualifiers, FreeSpecifier);
376 if(typeName.declarator)
377 FreeDeclarator(typeName.declarator);
378 if(typeName.bitCount)
379 FreeExpression(typeName.bitCount);
384 public void FreeExpContents(Expression exp)
386 _FreeExpression(exp, false);
389 public void FreeExpression(Expression exp)
391 _FreeExpression(exp, true);
394 static void _FreeExpression(Expression exp, bool freePointer)
397 char debugExpString[4096];
398 debugExpString[0] = '\0';
399 PrintExpression(exp, debugExpString);
405 FreeExpression(exp._new.size);
406 FreeTypeName(exp._new.typeName);
410 FreeExpression(exp._renew.exp);
411 FreeExpression(exp._renew.size);
412 FreeTypeName(exp._renew.typeName);
419 FreeIdentifier(exp.identifier);
424 FreeInstance(exp.instance);
433 FreeExpression(exp.op.exp1);
435 FreeExpression(exp.op.exp2);
439 FreeList(exp.list, FreeExpression);
445 FreeExpression(exp.index.exp);
447 FreeList(exp.index.index, FreeExpression);
453 FreeExpression(exp.call.exp);
454 if(exp.call.arguments)
455 FreeList(exp.call.arguments, FreeExpression);
461 FreeExpression(exp.member.exp);
462 if(exp.member.member)
463 FreeIdentifier(exp.member.member);
466 FreeTypeName(exp.typeName);
469 FreeTypeName(exp.typeName);
472 if(exp.offset.typeName)
473 FreeTypeName(exp.offset.typeName);
475 FreeIdentifier(exp.offset.id);
479 FreeExpression(exp.cast.exp);
480 FreeTypeName(exp.cast.typeName);
485 FreeExpression(exp.cond.cond);
487 FreeList(exp.cond.exp, FreeExpression);
489 FreeExpression(exp.cond.elseExp);
492 case extensionCompoundExp:
495 FreeStatement(exp.compound);
498 case extensionExpressionExp:
501 FreeList(exp.list, FreeExpression);
504 case extensionInitializerExp:
506 if(exp.initializer.typeName)
507 FreeTypeName(exp.initializer.typeName);
508 if(exp.initializer.initializer)
509 FreeInitializer(exp.initializer.initializer);
515 if(exp._classExp.specifiers)
516 FreeList(exp._classExp.specifiers, FreeSpecifier);
517 if(exp._classExp.decl)
518 FreeDeclarator(exp._classExp.decl);
524 FreeIdentifier(exp.db.id);
529 if(exp.call.arguments)
530 FreeList(exp.call.arguments, FreeExpression);
533 FreeExpression(exp.dbopen.ds);
535 FreeExpression(exp.dbopen.name);
539 FreeExpression(exp.vaArg.exp);
540 if(exp.vaArg.typeName)
541 FreeTypeName(exp.vaArg.typeName);
545 FreeList(exp.list, FreeExpression);
549 FreeSpecifier(exp._class);
553 FreeIdentifier(exp.classData.id);
557 FreeIdentifier(exp.identifier);
562 case memberPropertyErrorExp:
563 case memberSymbolErrorExp:
565 FreeExpression(exp.member.exp);
566 if(exp.member.member)
567 FreeIdentifier(exp.member.member);
569 case functionCallErrorExp:
571 FreeExpression(exp.call.exp);
572 if(exp.call.arguments)
573 FreeList(exp.call.arguments, FreeExpression);
575 case dereferenceErrorExp:
576 case unknownErrorExp:
577 case noDebuggerErrorExp:
583 FreeType(exp.expType);
585 FreeType(exp.destType);
590 void FreePointer(Pointer pointer)
593 FreePointer(pointer.pointer);
594 if(pointer.qualifiers)
595 FreeList(pointer.qualifiers, FreeSpecifier);
599 void FreeAttrib(Attrib attr)
602 FreeList(attr.attribs, FreeAttribute);
606 void FreeAttribute(Attribute attr)
610 FreeExpression(attr.exp);
614 void FreeExtDecl(ExtDecl extDecl)
616 if(extDecl.type == extDeclAttrib && extDecl.attr)
617 FreeAttrib(extDecl.attr);
618 else if(extDecl.type == extDeclString)
623 void FreeDeclarator(Declarator decl)
626 FreeDeclarator(decl.declarator);
630 case structDeclarator:
631 if(decl.structDecl.exp)
632 FreeExpression(decl.structDecl.exp);
633 if(decl.structDecl.posExp)
634 FreeExpression(decl.structDecl.posExp);
635 if(decl.structDecl.attrib)
636 FreeAttrib(decl.structDecl.attrib);
638 case identifierDeclarator:
639 FreeIdentifier(decl.identifier);
641 case bracketsDeclarator:
643 case arrayDeclarator:
645 FreeExpression(decl.array.exp);
646 if(decl.array.enumClass)
647 FreeSpecifier(decl.array.enumClass);
649 case functionDeclarator:
650 FreeList(decl.function.parameters, FreeTypeName);
652 case pointerDeclarator:
653 if(decl.pointer.pointer)
654 FreePointer(decl.pointer.pointer);
656 case extendedDeclarator:
657 case extendedDeclaratorEnd:
658 if(decl.extended.extended)
659 FreeExtDecl(decl.extended.extended);
665 void FreePropertyWatch(PropertyWatch watcher)
667 if(watcher.properties)
668 FreeList(watcher.properties, FreeIdentifier);
670 FreeStatement(watcher.compound);
674 void FreeAsmField(AsmField field)
677 FreeExpression(field.expression);
679 FreeIdentifier(field.symbolic);
680 delete field.command;
684 void FreeStatement(Statement stmt)
690 if(stmt.asmStmt.spec)
691 FreeSpecifier(stmt.asmStmt.spec);
692 if(stmt.asmStmt.inputFields)
693 FreeList(stmt.asmStmt.inputFields, FreeAsmField);
694 if(stmt.asmStmt.outputFields)
695 FreeList(stmt.asmStmt.outputFields, FreeAsmField);
696 if(stmt.asmStmt.clobberedFields)
697 FreeList(stmt.asmStmt.clobberedFields, FreeAsmField);
698 delete stmt.asmStmt.statements;
702 if(stmt.labeled.stmt)
703 FreeStatement(stmt.labeled.stmt);
706 if(stmt.caseStmt.exp)
707 FreeExpression(stmt.caseStmt.exp);
708 if(stmt.caseStmt.stmt)
709 FreeStatement(stmt.caseStmt.stmt);
711 case badDeclarationStmt:
713 FreeDeclaration(stmt.decl);
717 if(stmt.compound.declarations)
718 FreeList(stmt.compound.declarations, FreeDeclaration);
719 if(stmt.compound.statements)
720 FreeList(stmt.compound.statements, FreeStatement);
721 if(stmt.compound.context)
723 FreeContext(stmt.compound.context);
724 delete stmt.compound.context;
731 FreeList(stmt.expressions, FreeExpression);
737 FreeList(stmt.ifStmt.exp, FreeExpression);
739 FreeStatement(stmt.ifStmt.stmt);
740 if(stmt.ifStmt.elseStmt)
741 FreeStatement(stmt.ifStmt.elseStmt);
746 if(stmt.switchStmt.exp)
747 FreeList(stmt.switchStmt.exp, FreeExpression);
748 if(stmt.switchStmt.stmt)
749 FreeStatement(stmt.switchStmt.stmt);
754 if(stmt.whileStmt.exp)
755 FreeList(stmt.whileStmt.exp, FreeExpression);
756 if(stmt.whileStmt.stmt)
757 FreeStatement(stmt.whileStmt.stmt);
762 if(stmt.doWhile.stmt)
763 FreeStatement(stmt.doWhile.stmt);
766 FreeList(stmt.doWhile.exp, FreeExpression);
771 if(stmt.forStmt.init)
772 FreeStatement(stmt.forStmt.init);
774 if(stmt.forStmt.check)
775 FreeStatement(stmt.forStmt.check);
777 if(stmt.forStmt.increment)
778 FreeList(stmt.forStmt.increment, FreeExpression);
779 if(stmt.forStmt.stmt)
780 FreeStatement(stmt.forStmt.stmt);
785 if(stmt.forEachStmt.id)
786 FreeIdentifier(stmt.forEachStmt.id);
787 if(stmt.forEachStmt.exp)
788 FreeList(stmt.forEachStmt.exp, FreeExpression);
789 if(stmt.forEachStmt.filter)
790 FreeList(stmt.forEachStmt.filter, FreeExpression);
791 if(stmt.forEachStmt.stmt)
792 FreeStatement(stmt.forEachStmt.stmt);
803 FreeList(stmt.expressions, FreeExpression);
806 case fireWatchersStmt:
807 case stopWatchingStmt:
809 if(stmt._watch.watcher)
810 FreeExpression(stmt._watch.watcher);
811 if(stmt._watch.object)
812 FreeExpression(stmt._watch.object);
813 if(stmt._watch.watches)
814 FreeList(stmt._watch.watches, (stmt.type == watchStmt) ? (void *)FreePropertyWatch : (void *)FreeIdentifier);
821 void FreeInitializer(Initializer initializer)
823 switch(initializer.type)
825 case listInitializer:
826 FreeList(initializer.list, FreeInitializer);
830 FreeExpression(initializer.exp);
834 FreeIdentifier(initializer.id);
838 void FreeInitDeclarator(InitDeclarator decl)
841 FreeDeclarator(decl.declarator);
843 FreeInitializer(decl.initializer);
847 void FreeDeclaration(Declaration decl)
849 if(decl.symbol && !decl.symbol.type)
851 //FreeSymbol(decl.symbol);
855 case structDeclaration:
858 FreeList(decl.specifiers, FreeSpecifier);
860 FreeList(decl.declarators, FreeDeclarator);
862 FreeSpecifier(decl.extStorage);
865 case initDeclaration:
868 FreeList(decl.specifiers, FreeSpecifier);
870 FreeList(decl.declarators, FreeInitDeclarator);
873 case instDeclaration:
875 FreeInstance(decl.inst);
877 case defineDeclaration:
880 FreeExpression(decl.exp);
882 FreeIdentifier(decl.id);
889 void FreeFunction(FunctionDefinition func)
892 FreeStatement(func.body);
894 FreeDeclarator(func.declarator);
896 FreeList(func.specifiers, FreeSpecifier);
897 if(func.declarations)
898 FreeList(func.declarations, FreeDeclaration);
906 void FreeMemberInit(MemberInit init)
909 FreeInitializer(init.initializer);
911 FreeList(init.identifiers, FreeIdentifier);
915 void FreeMembersInit(MembersInit init)
917 if(init.type == dataMembersInit && init.dataMembers)
918 FreeList(init.dataMembers, FreeMemberInit);
920 if(init.type == methodMembersInit && init.function)
922 FreeClassFunction(init.function);
927 public void FreeInstance(Instantiation inst)
931 FreeList(inst.members, FreeMembersInit);
935 FreeExpression(inst.exp);
939 Symbol classSym = FindClass(inst._class.name);
940 Class _class = classSym ? classSym.registered : null;
943 if(_class.type == normalClass)
945 Instance instance = (Instance)inst.data;
948 else if(_class.type == noHeadClass)
950 if(_class.Destructor)
951 _class.Destructor((Instance)inst.data);
954 else if(_class.type == structClass)
961 Instance instance = (Instance)inst.data;
967 FreeSpecifier(inst._class);
975 public void FreeClassFunction(ClassFunction func)
978 if(func.declarator && func.declarator.symbol)
980 //FreeSymbol(func.declarator.symbol);
987 FreeStatement(func.body);
989 FreeDeclarator(func.declarator);
991 FreeList(func.specifiers, FreeSpecifier);
992 if(func.declarations)
993 FreeList(func.declarations, FreeDeclaration);
995 func.attached.Free(null);
1000 void FreeProperty(PropertyDef def)
1003 FreeList(def.specifiers, FreeSpecifier);
1005 FreeDeclarator(def.declarator);
1007 FreeIdentifier(def.id);
1009 FreeStatement(def.getStmt);
1011 FreeStatement(def.setStmt);
1013 FreeStatement(def.issetStmt);
1015 FreeExpression(def.category);
1019 FreeFunction(def.getFunction);
1021 FreeFunction(def.setFunction);
1025 // FreeSymbol(def.symbol);
1031 void FreeClassDef(ClassDef def)
1035 case declarationClassDef:
1037 FreeDeclaration(def.decl);
1039 case defaultPropertiesClassDef:
1041 FreeList(def.defProperties, FreeMemberInit);
1044 case functionClassDef:
1046 FreeClassFunction(def.function);
1048 case propertyClassDef:
1050 FreeProperty(def.propertyDef);
1052 case classPropertyClassDef:
1054 FreeProperty(def.propertyDef);
1056 case accessOverrideClassDef:
1058 case classDataClassDef:
1061 FreeDeclaration(def.decl);
1064 case classDesignerClassDef:
1066 delete def.designer;
1069 case classFixedClassDef:
1071 case classNoExpansionClassDef:
1073 case classPropertyValueClassDef:
1075 FreeIdentifier(def.id);
1077 FreeInitializer(def.initializer);
1079 case designerDefaultPropertyClassDef:
1081 if(def.defaultProperty)
1082 FreeIdentifier(def.defaultProperty);
1085 case memberAccessClassDef:
1087 case propertyWatchClassDef:
1089 if(def.propertyWatch)
1090 FreePropertyWatch(def.propertyWatch);
1097 void FreeClass(ClassDefinition _class)
1099 if(_class.definitions)
1100 FreeList(_class.definitions, FreeClassDef);
1102 FreeSpecifier(_class._class);
1103 if(_class.baseSpecs)
1104 FreeList(_class.baseSpecs, FreeSpecifier);
1109 void FreeDBIndexItem(DBIndexItem item)
1112 FreeIdentifier(item.id);
1116 void FreeDBTableEntry(DBTableEntry entry)
1119 FreeIdentifier(entry.id);
1124 FreeTypeName(entry.dataType);
1130 FreeList(entry.items, FreeDBIndexItem);
1136 void FreeDBTable(DBTableDef table)
1138 if(table.definitions)
1139 FreeList(table.definitions, FreeDBTableEntry);
1141 FreeIdentifier(table.symbol);*/
1147 void FreeExternal(External external)
1150 while((e = external.incoming.first))
1152 e.from.outgoing.Remove((IteratorPointer)e);
1153 external.incoming.Remove((IteratorPointer)e);
1156 while((e = external.outgoing.first))
1158 e.to.incoming.Remove((IteratorPointer)e);
1159 external.outgoing.Remove((IteratorPointer)e);
1161 e.to.nonBreakableIncoming--;
1164 switch(external.type)
1166 case functionExternal:
1167 if(external.function)
1168 FreeFunction(external.function);
1170 case declarationExternal:
1171 if(external.declaration)
1172 FreeDeclaration(external.declaration);
1176 FreeClass(external._class);
1178 case importExternal:
1179 delete external.importString;
1181 case nameSpaceExternal:
1182 FreeIdentifier(external.id);
1184 case dbtableExternal:
1186 FreeDBTable(external.table);
1192 public void FreeASTTree(OldList ast)
1197 while((external = ast.first))
1199 ast.Remove(external);
1200 FreeExternal(external);
1206 static void FreeDataMember(DataMember parentMember)
1208 DataMember dataMember;
1210 for(dataMember = parentMember.members.first; dataMember; dataMember = dataMember.next)
1212 if(dataMember.type == structMember || dataMember.type == unionMember)
1213 FreeDataMember(dataMember);
1215 if(dataMember.dataType)
1217 FreeType(dataMember.dataType);
1218 dataMember.dataType = null;
1223 static void FreeClassProperties(ClassProperty classProp)
1225 if(classProp.left) FreeClassProperties(classProp.left);
1226 if(classProp.right) FreeClassProperties(classProp.right);
1227 if(classProp.dataType)
1229 FreeType(classProp.dataType);
1230 classProp.dataType = null;
1234 void FreeModuleData(Module module)
1237 GlobalFunction function;
1240 for(_class = module.classes.first; _class; _class = _class.next)
1242 DataMember dataMember;
1244 ClassTemplateParameter param;
1248 FreeType(_class.dataType);
1249 _class.dataType = null;
1251 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
1253 if(dataMember.isProperty)
1255 Property prop = (Property)dataMember;
1258 FreeSymbol(prop.symbol);
1263 if(dataMember.type == structMember || dataMember.type == unionMember)
1264 FreeDataMember(dataMember);
1266 if(dataMember.dataType)
1268 FreeType(dataMember.dataType);
1269 dataMember.dataType = null;
1272 for(dataMember = _class.conversions.first; dataMember; dataMember = dataMember.next)
1274 Property prop = (Property) dataMember;
1277 FreeSymbol(prop.symbol);
1281 FreeType(prop.dataType);
1282 prop.dataType = null;
1285 if(_class.classProperties.first)
1286 FreeClassProperties((ClassProperty)_class.classProperties.first);
1287 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
1291 FreeType(method.dataType);
1292 method.dataType = null;
1297 FreeSymbol(method.symbol);
1300 for(param = _class.templateParams.first; param; param = param.next)
1304 FreeTemplateParameter(param.param);
1310 for(function = module.functions.first; function; function = function.next)
1312 if(function.dataType)
1313 FreeType(function.dataType);
1315 FreeSymbol(function.symbol);
1318 // Free the extra module instance on closing the last code editor using it
1321 MapIterator <String, List<Module> > mapIt { map = loadedModules };
1324 List<Module> list = mapIt.data;
1325 Iterator<Module> it { list };
1329 if(it.data == module)
1331 list.Remove(it.pointer);
1340 // Unload the initial module that we loaded for safe sharing
1341 Module mod = list[0];
1342 list.Remove(list.GetFirst());
1343 loadedModules.Remove(mapIt.pointer);
1345 eModule_Unload(__thisModule.application, mod);
1353 public void FreeTypeData(Module privateModule)
1356 for(m = privateModule.application.allModules.first; m; m = m.next)
1360 FreeModuleData(privateModule);