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
|
* periodic heap cleanup
|
||||||
* octal/hex character constants
|
* octal/hex character constants
|
||||||
* see if we can use ParserCopyPos() in other places rather than copying everything
|
* 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:
|
Need test/debug:
|
||||||
* all break/continue variations
|
* all break/continue variations
|
||||||
|
|
1
picoc.c
1
picoc.c
|
@ -17,6 +17,7 @@ void Initialise()
|
||||||
void Cleanup()
|
void Cleanup()
|
||||||
{
|
{
|
||||||
VariableCleanup();
|
VariableCleanup();
|
||||||
|
TypeCleanup();
|
||||||
TableStrFree();
|
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 *DerivedTypeList; /* first in a list of types derived from this one */
|
||||||
struct ValueType *Next; /* next item in the derived type list */
|
struct ValueType *Next; /* next item in the derived type list */
|
||||||
struct Table *Members; /* members of a struct or union */
|
struct Table *Members; /* members of a struct or union */
|
||||||
|
int OnHeap; /* true if allocated on the heap */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* function definition */
|
/* function definition */
|
||||||
|
@ -276,6 +277,7 @@ int ExpressionParseInt(struct ParseState *Parser);
|
||||||
|
|
||||||
/* type.c */
|
/* type.c */
|
||||||
void TypeInit();
|
void TypeInit();
|
||||||
|
void TypeCleanup();
|
||||||
int TypeSize(struct ValueType *Typ, int ArraySize);
|
int TypeSize(struct ValueType *Typ, int ArraySize);
|
||||||
int TypeSizeValue(struct Value *Val);
|
int TypeSizeValue(struct Value *Val);
|
||||||
int TypeStackSizeValue(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->Members = NULL;
|
||||||
NewType->FromType = ParentType;
|
NewType->FromType = ParentType;
|
||||||
NewType->DerivedTypeList = NULL;
|
NewType->DerivedTypeList = NULL;
|
||||||
|
NewType->OnHeap = TRUE;
|
||||||
NewType->Next = ParentType->DerivedTypeList;
|
NewType->Next = ParentType->DerivedTypeList;
|
||||||
ParentType->DerivedTypeList = NewType;
|
ParentType->DerivedTypeList = NewType;
|
||||||
|
|
||||||
|
@ -93,6 +94,7 @@ void TypeAddBaseType(struct ValueType *TypeNode, enum BaseType Base, int Sizeof)
|
||||||
TypeNode->Members = NULL;
|
TypeNode->Members = NULL;
|
||||||
TypeNode->FromType = NULL;
|
TypeNode->FromType = NULL;
|
||||||
TypeNode->DerivedTypeList = NULL;
|
TypeNode->DerivedTypeList = NULL;
|
||||||
|
TypeNode->OnHeap = FALSE;
|
||||||
TypeNode->Next = UberType.DerivedTypeList;
|
TypeNode->Next = UberType.DerivedTypeList;
|
||||||
UberType.DerivedTypeList = TypeNode;
|
UberType.DerivedTypeList = TypeNode;
|
||||||
}
|
}
|
||||||
|
@ -114,6 +116,26 @@ void TypeInit()
|
||||||
CharArrayType = TypeAdd(NULL, &CharType, TypeArray, 0, StrEmpty, sizeof(char));
|
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 */
|
/* parse a struct or union declaration */
|
||||||
void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsStruct)
|
void TypeParseStruct(struct ParseState *Parser, struct ValueType **Typ, int IsStruct)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue