Now cleaning up types too
git-svn-id: http://picoc.googlecode.com/svn/trunk@195 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
028c98d665
commit
6f7daf0145
1
TODO
1
TODO
|
@ -22,6 +22,7 @@ Improvements:
|
|||
* periodic heap cleanup
|
||||
* octal/hex character constants
|
||||
* see if we can use ParserCopyPos() in other places rather than copying everything
|
||||
* how to deallocate char arrays allocated in the lexer?
|
||||
|
||||
Need test/debug:
|
||||
* all break/continue variations
|
||||
|
|
1
picoc.c
1
picoc.c
|
@ -17,6 +17,7 @@ void Initialise()
|
|||
void Cleanup()
|
||||
{
|
||||
VariableCleanup();
|
||||
TypeCleanup();
|
||||
TableStrFree();
|
||||
}
|
||||
|
||||
|
|
2
picoc.h
2
picoc.h
|
@ -116,6 +116,7 @@ struct ValueType
|
|||
struct ValueType *DerivedTypeList; /* first in a list of types derived from this one */
|
||||
struct ValueType *Next; /* next item in the derived type list */
|
||||
struct Table *Members; /* members of a struct or union */
|
||||
int OnHeap; /* true if allocated on the heap */
|
||||
};
|
||||
|
||||
/* function definition */
|
||||
|
@ -276,6 +277,7 @@ int ExpressionParseInt(struct ParseState *Parser);
|
|||
|
||||
/* type.c */
|
||||
void TypeInit();
|
||||
void TypeCleanup();
|
||||
int TypeSize(struct ValueType *Typ, int ArraySize);
|
||||
int TypeSizeValue(struct Value *Val);
|
||||
int TypeStackSizeValue(struct Value *Val);
|
||||
|
|
22
type.c
22
type.c
|
@ -28,6 +28,7 @@ struct ValueType *TypeAdd(struct ParseState *Parser, struct ValueType *ParentTyp
|
|||
NewType->Members = NULL;
|
||||
NewType->FromType = ParentType;
|
||||
NewType->DerivedTypeList = NULL;
|
||||
NewType->OnHeap = TRUE;
|
||||
NewType->Next = ParentType->DerivedTypeList;
|
||||
ParentType->DerivedTypeList = NewType;
|
||||
|
||||
|
@ -93,6 +94,7 @@ void TypeAddBaseType(struct ValueType *TypeNode, enum BaseType Base, int Sizeof)
|
|||
TypeNode->Members = NULL;
|
||||
TypeNode->FromType = NULL;
|
||||
TypeNode->DerivedTypeList = NULL;
|
||||
TypeNode->OnHeap = FALSE;
|
||||
TypeNode->Next = UberType.DerivedTypeList;
|
||||
UberType.DerivedTypeList = TypeNode;
|
||||
}
|
||||
|
@ -114,6 +116,26 @@ void TypeInit()
|
|||
CharArrayType = TypeAdd(NULL, &CharType, TypeArray, 0, StrEmpty, sizeof(char));
|
||||
}
|
||||
|
||||
/* deallocate heap-allocated types */
|
||||
void TypeCleanupNode(struct ValueType *Typ)
|
||||
{
|
||||
struct ValueType *SubType;
|
||||
struct ValueType *NextSubType;
|
||||
|
||||
for (SubType = Typ->DerivedTypeList; SubType != NULL; SubType = NextSubType)
|
||||
{
|
||||
NextSubType = SubType->Next;
|
||||
TypeCleanupNode(SubType);
|
||||
if (SubType->OnHeap)
|
||||
HeapFree(SubType);
|
||||
}
|
||||
}
|
||||
|
||||
void TypeCleanup()
|
||||
{
|
||||
TypeCleanupNode(&UberType);
|
||||
}
|
||||
|
||||
/* parse a struct or union declaration */
|
||||
void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsStruct)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue