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 NamedLink member, next;
33 for(member = type.members.first; member; member = next)
36 type.members.Remove(member);
47 for(member = type.members.first; member; member = next)
50 // Remove from list only when reaching last reference
51 // (The list is copied)
52 if(member.refCount == 1)
53 type.members.Remove(member);
62 FreeType(type.returnType);
63 for(param = type.params.first; param; param = next)
66 // WARNING: Don't unlink these as they might be reused
67 // type.params.Remove(param);
73 if(type.freeExp && type.arraySizeExp)
74 FreeExpression(type.arraySizeExp);
87 void FreeSymbol(Symbol symbol)
91 if(symbol.propCategory)
92 FreeExpression(symbol.propCategory);
94 FreeType(symbol.type);
96 while(link = symbol.templatedClasses.first)
97 symbol.templatedClasses.Delete(link);
101 if(symbol.templateParams)
102 FreeList(symbol.templateParams, FreeTemplateParameter);
104 // Used to be in ClassDefinition
105 delete symbol.constructorName;
106 delete symbol.structName;
107 delete symbol.className;
108 delete symbol.destructorName;
109 delete symbol.shortName;
112 FreeContext(symbol.ctx);
118 void FreeMethodImport(MethodImport imp)
123 void FreePropertyImport(MethodImport imp)
128 void FreeClassImport(ClassImport imp)
131 imp.methods.Free(FreeMethodImport);
132 imp.properties.Free(FreePropertyImport);
135 void FreeFunctionImport(ClassImport imp)
140 public void FreeModuleImport(ModuleImport imp)
143 imp.classes.Free(FreeClassImport);
144 imp.functions.Free(FreeFunctionImport);
147 public void FreeModuleDefine(Definition def)
152 public void FreeExcludedSymbols(OldList excludedSymbols)
156 while(symbol = excludedSymbols.first)
158 excludedSymbols.Remove(symbol);
163 public void FreeTemplateArgument(TemplateArgument arg)
169 FreeExpression(arg.expression);
173 FreeIdentifier(arg.identifier);
176 if(arg.templateDatatype)
177 FreeTemplateDataType(arg.templateDatatype);
181 FreeIdentifier(arg.name);
185 public void FreeTemplateDataType(TemplateDatatype type)
188 FreeDeclarator(type.decl);
190 FreeList(type.specifiers, FreeSpecifier);
194 public void FreeTemplateParameter(TemplateParameter param)
198 FreeIdentifier(param.identifier);
200 if(param.type == type || param.type == expression)
203 FreeTemplateDataType(param.dataType);
205 if(param.defaultArgument)
206 FreeTemplateArgument(param.defaultArgument);
208 FreeType(param.baseType);
212 public void FreeTemplateType(TemplatedType type)
216 FreeTemplateParameter(type.param);
221 public void FreeContext(Context context)
225 if(context == curContext)
226 curContext = globalContext;
228 while(symbol = (Symbol)context.types.root)
230 context.types.Remove((BTNode)symbol);
233 while(symbol = (Symbol)context.classes.root)
235 context.classes.Remove((BTNode)symbol);
238 while(symbol = (Symbol)context.symbols.root)
240 context.symbols.Remove((BTNode)symbol);
243 while(symbol = (Symbol)context.structSymbols.root)
245 context.structSymbols.Remove((BTNode)symbol);
248 while(symbol = (Symbol)context.templateTypes.root)
250 context.templateTypes.Remove((BTNode)symbol);
251 FreeTemplateType((TemplatedType)symbol);
255 context.simpleID = 0;
256 context.parent = null;
259 void FreeEnumerator(Enumerator enumerator)
262 FreeIdentifier(enumerator.id);
264 FreeExpression(enumerator.exp);
269 void FreeSpecifier(Specifier spec)
276 //case classSpecifier:
278 if(spec.templateArgs)
279 FreeList(spec.templateArgs, FreeTemplateArgument);
281 case extendedSpecifier:
283 FreeExtDecl(spec.extDecl);
287 FreeList(spec.baseSpecs, FreeSpecifier);
289 FreeIdentifier(spec.id);
291 FreeList(spec.list, FreeEnumerator);
293 FreeList(spec.definitions, FreeClassDef);
295 case structSpecifier:
298 FreeIdentifier(spec.id);
300 FreeList(spec.definitions, FreeClassDef);
302 FreeList(spec.baseSpecs, FreeSpecifier);
303 if(spec.extDeclStruct)
304 FreeExtDecl(spec.extDeclStruct);
307 FreeContext(spec.ctx);
311 case subClassSpecifier:
313 FreeSpecifier(spec._class);
320 public void FreeIdentifier(Identifier id)
323 FreeIdentifier(id.badID);
326 FreeSpecifier(id._class);
330 void FreeTypeName(TypeName typeName)
332 if(typeName.qualifiers)
333 FreeList(typeName.qualifiers, FreeSpecifier);
334 if(typeName.declarator)
335 FreeDeclarator(typeName.declarator);
336 if(typeName.bitCount)
337 FreeExpression(typeName.bitCount);
342 public void FreeExpContents(Expression exp)
344 _FreeExpression(exp, false);
347 public void FreeExpression(Expression exp)
349 _FreeExpression(exp, true);
352 static void _FreeExpression(Expression exp, bool freePointer)
355 char debugExpString[4096];
356 debugExpString[0] = '\0';
357 PrintExpression(exp, debugExpString);
363 FreeExpression(exp._new.size);
364 FreeTypeName(exp._new.typeName);
368 FreeExpression(exp._renew.exp);
369 FreeExpression(exp._renew.size);
370 FreeTypeName(exp._renew.typeName);
377 FreeIdentifier(exp.identifier);
382 FreeInstance(exp.instance);
391 FreeExpression(exp.op.exp1);
393 FreeExpression(exp.op.exp2);
397 FreeList(exp.list, FreeExpression);
403 FreeExpression(exp.index.exp);
405 FreeList(exp.index.index, FreeExpression);
410 FreeExpression(exp.call.exp);
411 if(exp.call.arguments)
412 FreeList(exp.call.arguments, FreeExpression);
418 FreeExpression(exp.member.exp);
419 if(exp.member.member)
420 FreeIdentifier(exp.member.member);
423 FreeTypeName(exp._new.typeName);
426 FreeTypeName(exp._new.typeName);
430 FreeExpression(exp.cast.exp);
431 FreeTypeName(exp.cast.typeName);
436 FreeExpression(exp.cond.cond);
438 FreeList(exp.cond.exp, FreeExpression);
440 FreeExpression(exp.cond.elseExp);
443 case extensionCompoundExp:
446 FreeStatement(exp.compound);
449 case extensionExpressionExp:
452 FreeList(exp.list, FreeExpression);
455 case extensionInitializerExp:
457 if(exp.initializer.typeName)
458 FreeTypeName(exp.initializer.typeName);
459 if(exp.initializer.initializer)
460 FreeInitializer(exp.initializer.initializer);
466 if(exp._classExp.specifiers)
467 FreeList(exp._classExp.specifiers, FreeSpecifier);
468 if(exp._classExp.decl)
469 FreeDeclarator(exp._classExp.decl);
475 FreeIdentifier(exp.db.id);
480 if(exp.call.arguments)
481 FreeList(exp.call.arguments, FreeExpression);
484 FreeExpression(exp.dbopen.ds);
486 FreeExpression(exp.dbopen.name);
490 FreeExpression(exp.vaArg.exp);
491 if(exp.vaArg.typeName)
492 FreeTypeName(exp.vaArg.typeName);
496 FreeList(exp.list, FreeExpression);
500 FreeSpecifier(exp._class);
504 FreeIdentifier(exp.classData.id);
508 FreeIdentifier(exp.identifier);
513 case memberPropertyErrorExp:
514 case memberSymbolErrorExp:
516 FreeExpression(exp.member.exp);
517 if(exp.member.member)
518 FreeIdentifier(exp.member.member);
520 case dereferenceErrorExp:
521 case unknownErrorExp:
522 case noDebuggerErrorExp:
528 FreeType(exp.expType);
530 FreeType(exp.destType);
535 void FreePointer(Pointer pointer)
538 FreePointer(pointer.pointer);
539 if(pointer.qualifiers)
540 FreeList(pointer.qualifiers, FreeSpecifier);
544 void FreeAttrib(Attrib attr)
547 FreeList(attr.attribs, FreeAttribute);
551 void FreeAttribute(Attribute attr)
555 FreeExpression(attr.exp);
559 void FreeExtDecl(ExtDecl extDecl)
561 if(extDecl.type == extDeclAttrib && extDecl.attr)
562 FreeAttrib(extDecl.attr);
563 else if(extDecl.type == extDeclString)
568 void FreeDeclarator(Declarator decl)
571 FreeDeclarator(decl.declarator);
575 case structDeclarator:
576 if(decl.structDecl.exp)
577 FreeExpression(decl.structDecl.exp);
578 if(decl.structDecl.posExp)
579 FreeExpression(decl.structDecl.posExp);
580 if(decl.structDecl.attrib)
581 FreeAttrib(decl.structDecl.attrib);
583 case identifierDeclarator:
584 FreeIdentifier(decl.identifier);
586 case bracketsDeclarator:
588 case arrayDeclarator:
590 FreeExpression(decl.array.exp);
591 if(decl.array.enumClass)
592 FreeSpecifier(decl.array.enumClass);
594 case functionDeclarator:
595 FreeList(decl.function.parameters, FreeTypeName);
597 case pointerDeclarator:
598 if(decl.pointer.pointer)
599 FreePointer(decl.pointer.pointer);
601 case extendedDeclarator:
602 case extendedDeclaratorEnd:
603 if(decl.extended.extended)
604 FreeExtDecl(decl.extended.extended);
610 void FreePropertyWatch(PropertyWatch watcher)
612 if(watcher.properties)
613 FreeList(watcher.properties, FreeIdentifier);
615 FreeStatement(watcher.compound);
619 void FreeAsmField(AsmField field)
622 FreeExpression(field.expression);
624 FreeIdentifier(field.symbolic);
625 delete field.command;
629 void FreeStatement(Statement stmt)
635 if(stmt.asmStmt.spec)
636 FreeSpecifier(stmt.asmStmt.spec);
637 if(stmt.asmStmt.inputFields)
638 FreeList(stmt.asmStmt.inputFields, FreeAsmField);
639 if(stmt.asmStmt.outputFields)
640 FreeList(stmt.asmStmt.outputFields, FreeAsmField);
641 if(stmt.asmStmt.clobberedFields)
642 FreeList(stmt.asmStmt.clobberedFields, FreeAsmField);
643 delete stmt.asmStmt.statements;
647 if(stmt.labeled.stmt)
648 FreeStatement(stmt.labeled.stmt);
651 if(stmt.caseStmt.exp)
652 FreeExpression(stmt.caseStmt.exp);
653 if(stmt.caseStmt.stmt)
654 FreeStatement(stmt.caseStmt.stmt);
656 case badDeclarationStmt:
658 FreeDeclaration(stmt.decl);
662 if(stmt.compound.declarations)
663 FreeList(stmt.compound.declarations, FreeDeclaration);
664 if(stmt.compound.statements)
665 FreeList(stmt.compound.statements, FreeStatement);
666 if(stmt.compound.context)
668 FreeContext(stmt.compound.context);
669 delete stmt.compound.context;
676 FreeList(stmt.expressions, FreeExpression);
682 FreeList(stmt.ifStmt.exp, FreeExpression);
684 FreeStatement(stmt.ifStmt.stmt);
685 if(stmt.ifStmt.elseStmt)
686 FreeStatement(stmt.ifStmt.elseStmt);
691 if(stmt.switchStmt.exp)
692 FreeList(stmt.switchStmt.exp, FreeExpression);
693 if(stmt.switchStmt.stmt)
694 FreeStatement(stmt.switchStmt.stmt);
699 if(stmt.whileStmt.exp)
700 FreeList(stmt.whileStmt.exp, FreeExpression);
701 if(stmt.whileStmt.stmt)
702 FreeStatement(stmt.whileStmt.stmt);
707 if(stmt.doWhile.stmt)
708 FreeStatement(stmt.doWhile.stmt);
711 FreeList(stmt.doWhile.exp, FreeExpression);
716 if(stmt.forStmt.init)
717 FreeStatement(stmt.forStmt.init);
719 if(stmt.forStmt.check)
720 FreeStatement(stmt.forStmt.check);
722 if(stmt.forStmt.increment)
723 FreeList(stmt.forStmt.increment, FreeExpression);
724 if(stmt.forStmt.stmt)
725 FreeStatement(stmt.forStmt.stmt);
730 if(stmt.forEachStmt.id)
731 FreeIdentifier(stmt.forEachStmt.id);
732 if(stmt.forEachStmt.exp)
733 FreeList(stmt.forEachStmt.exp, FreeExpression);
734 if(stmt.forEachStmt.filter)
735 FreeList(stmt.forEachStmt.filter, FreeExpression);
736 if(stmt.forEachStmt.stmt)
737 FreeStatement(stmt.forEachStmt.stmt);
748 FreeList(stmt.expressions, FreeExpression);
751 case fireWatchersStmt:
752 case stopWatchingStmt:
754 if(stmt._watch.watcher)
755 FreeExpression(stmt._watch.watcher);
756 if(stmt._watch.object)
757 FreeExpression(stmt._watch.object);
758 if(stmt._watch.watches)
759 FreeList(stmt._watch.watches, (stmt.type == watchStmt) ? FreePropertyWatch : FreeIdentifier);
766 void FreeInitializer(Initializer initializer)
768 switch(initializer.type)
770 case listInitializer:
772 FreeList(initializer.list, FreeInitializer);
777 FreeExpression(initializer.exp);
783 void FreeInitDeclarator(InitDeclarator decl)
786 FreeDeclarator(decl.declarator);
788 FreeInitializer(decl.initializer);
792 void FreeDeclaration(Declaration decl)
794 if(decl.symbol && !decl.symbol.type)
796 //FreeSymbol(decl.symbol);
800 case structDeclaration:
803 FreeList(decl.specifiers, FreeSpecifier);
805 FreeList(decl.declarators, FreeDeclarator);
807 FreeSpecifier(decl.extStorage);
810 case initDeclaration:
813 FreeList(decl.specifiers, FreeSpecifier);
815 FreeList(decl.declarators, FreeInitDeclarator);
818 case instDeclaration:
820 FreeInstance(decl.inst);
822 case defineDeclaration:
825 FreeExpression(decl.exp);
827 FreeIdentifier(decl.id);
834 void FreeFunction(FunctionDefinition func)
837 FreeStatement(func.body);
839 FreeDeclarator(func.declarator);
841 FreeList(func.specifiers, FreeSpecifier);
842 if(func.declarations)
843 FreeList(func.declarations, FreeDeclaration);
851 void FreeMemberInit(MemberInit init)
854 FreeInitializer(init.initializer);
856 FreeList(init.identifiers, FreeIdentifier);
860 void FreeMembersInit(MembersInit init)
862 if(init.type == dataMembersInit && init.dataMembers)
863 FreeList(init.dataMembers, FreeMemberInit);
865 if(init.type == methodMembersInit && init.function)
867 FreeClassFunction(init.function);
872 void FreeInstance(Instantiation inst)
876 FreeList(inst.members, FreeMembersInit);
880 FreeExpression(inst.exp);
884 Symbol classSym = FindClass(inst._class.name);
885 Class _class = classSym ? classSym.registered : null;
888 if(_class.type == normalClass)
890 Instance instance = (Instance)inst.data;
893 else if(_class.type == noHeadClass)
895 if(_class.Destructor)
896 _class.Destructor((Instance)inst.data);
899 else if(_class.type == structClass)
906 Instance instance = (Instance)inst.data;
912 FreeSpecifier(inst._class);
920 public void FreeClassFunction(ClassFunction func)
923 if(func.declarator && func.declarator.symbol)
925 //FreeSymbol(func.declarator.symbol);
932 FreeStatement(func.body);
934 FreeDeclarator(func.declarator);
936 FreeList(func.specifiers, FreeSpecifier);
937 if(func.declarations)
938 FreeList(func.declarations, FreeDeclaration);
940 func.attached.Free(null);
945 void FreeProperty(PropertyDef def)
948 FreeList(def.specifiers, FreeSpecifier);
950 FreeDeclarator(def.declarator);
952 FreeIdentifier(def.id);
954 FreeStatement(def.getStmt);
956 FreeStatement(def.setStmt);
958 FreeStatement(def.issetStmt);
960 FreeExpression(def.category);
964 FreeFunction(def.getFunction);
966 FreeFunction(def.setFunction);
970 // FreeSymbol(def.symbol);
976 void FreeClassDef(ClassDef def)
980 case declarationClassDef:
982 FreeDeclaration(def.decl);
984 case defaultPropertiesClassDef:
986 FreeList(def.defProperties, FreeMemberInit);
989 case functionClassDef:
991 FreeClassFunction(def.function);
993 case propertyClassDef:
995 FreeProperty(def.propertyDef);
997 case classPropertyClassDef:
999 FreeProperty(def.propertyDef);
1001 case accessOverrideClassDef:
1003 case classDataClassDef:
1006 FreeDeclaration(def.decl);
1009 case classDesignerClassDef:
1011 delete def.designer;
1014 case classFixedClassDef:
1016 case classNoExpansionClassDef:
1018 case classPropertyValueClassDef:
1020 FreeIdentifier(def.id);
1022 FreeInitializer(def.initializer);
1024 case designerDefaultPropertyClassDef:
1026 if(def.defaultProperty)
1027 FreeIdentifier(def.defaultProperty);
1030 case memberAccessClassDef:
1032 case propertyWatchClassDef:
1034 if(def.propertyWatch)
1035 FreePropertyWatch(def.propertyWatch);
1042 void FreeClass(ClassDefinition _class)
1044 if(_class.definitions)
1045 FreeList(_class.definitions, FreeClassDef);
1047 FreeSpecifier(_class._class);
1048 if(_class.baseSpecs)
1049 FreeList(_class.baseSpecs, FreeSpecifier);
1054 void FreeDBIndexItem(DBIndexItem item)
1057 FreeIdentifier(item.id);
1061 void FreeDBTableEntry(DBTableEntry entry)
1064 FreeIdentifier(entry.id);
1069 FreeTypeName(entry.dataType);
1075 FreeList(entry.items, FreeDBIndexItem);
1081 void FreeDBTable(DBTableDef table)
1083 if(table.definitions)
1084 FreeList(table.definitions, FreeDBTableEntry);
1086 FreeIdentifier(table.symbol);*/
1092 void FreeExternal(External external)
1094 switch(external.type)
1096 case functionExternal:
1097 if(external.function)
1098 FreeFunction(external.function);
1100 case declarationExternal:
1101 if(external.declaration)
1102 FreeDeclaration(external.declaration);
1106 FreeClass(external._class);
1108 case importExternal:
1109 delete external.importString;
1111 case nameSpaceExternal:
1112 FreeIdentifier(external.id);
1114 case dbtableExternal:
1116 FreeDBTable(external.table);
1122 public void FreeASTTree(OldList ast)
1127 while(external = ast.first)
1129 ast.Remove(external);
1130 FreeExternal(external);
1136 static void FreeDataMember(DataMember parentMember)
1138 DataMember dataMember;
1140 for(dataMember = parentMember.members.first; dataMember; dataMember = dataMember.next)
1142 if(dataMember.type == structMember || dataMember.type == unionMember)
1143 FreeDataMember(dataMember);
1145 if(dataMember.dataType)
1147 FreeType(dataMember.dataType);
1148 dataMember.dataType = null;
1153 static void FreeClassProperties(ClassProperty classProp)
1155 if(classProp.left) FreeClassProperties(classProp.left);
1156 if(classProp.right) FreeClassProperties(classProp.right);
1157 if(classProp.dataType)
1159 FreeType(classProp.dataType);
1160 classProp.dataType = null;
1164 void FreeModuleData(Module module)
1167 GlobalFunction function;
1170 for(_class = module.classes.first; _class; _class = _class.next)
1172 DataMember dataMember;
1174 ClassTemplateParameter param;
1175 ClassProperty classProp;
1179 FreeType(_class.dataType);
1180 _class.dataType = null;
1182 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
1184 if(dataMember.isProperty)
1186 Property prop = (Property)dataMember;
1189 FreeSymbol(prop.symbol);
1194 if(dataMember.type == structMember || dataMember.type == unionMember)
1195 FreeDataMember(dataMember);
1197 if(dataMember.dataType)
1199 FreeType(dataMember.dataType);
1200 dataMember.dataType = null;
1203 for(dataMember = _class.conversions.first; dataMember; dataMember = dataMember.next)
1205 Property prop = (Property) dataMember;
1208 FreeSymbol(prop.symbol);
1212 FreeType(prop.dataType);
1213 prop.dataType = null;
1216 if(_class.classProperties.first)
1217 FreeClassProperties((ClassProperty)_class.classProperties.first);
1218 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
1222 FreeType(method.dataType);
1223 method.dataType = null;
1228 FreeSymbol(method.symbol);
1231 for(param = _class.templateParams.first; param; param = param.next)
1235 FreeTemplateParameter(param.param);
1241 for(function = module.functions.first; function; function = function.next)
1243 if(function.dataType)
1244 FreeType(function.dataType);
1246 FreeSymbol(function.symbol);
1249 // Free the extra module instance on closing the last code editor using it
1252 MapIterator <String, List<Module> > mapIt { map = loadedModules };
1255 List<Module> list = mapIt.data;
1256 Iterator<Module> it { list };
1260 if(it.data == module)
1262 list.Remove(it.pointer);
1271 // Unload the initial module that we loaded for safe sharing
1272 Module mod = list[0];
1273 list.Remove(list.GetFirst());
1274 loadedModules.Remove(mapIt.pointer);
1276 eModule_Unload(__thisModule.application, mod);
1284 public void FreeTypeData(Module privateModule)
1287 for(m = privateModule.application.allModules.first; m; m = m.next)
1291 FreeModuleData(privateModule);