mirror of
https://github.com/ZDoom/acc.git
synced 2024-11-26 22:01:00 +00:00
- Fixed: Inside an ACS library, you could not use a normal #define to specify
the size of an array. Now #defines are fully processed inside an import but are forgotten when the import is popped if they weren't created with #libdefine. SVN r280 (trunk)
This commit is contained in:
parent
ae59218dba
commit
a96324456a
6 changed files with 122 additions and 14 deletions
4
Makefile
4
Makefile
|
@ -16,9 +16,9 @@ EXENAME = acc
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS = -Os -Wall -W -march=pentium -mtune=athlon-4 -fomit-frame-pointer
|
CFLAGS = -Os -Wall -W -fomit-frame-pointer
|
||||||
LDFLAGS = -s
|
LDFLAGS = -s
|
||||||
VERNUM = 137
|
VERNUM = 142
|
||||||
|
|
||||||
OBJS = \
|
OBJS = \
|
||||||
acc.o \
|
acc.o \
|
||||||
|
|
11
parse.c
11
parse.c
|
@ -1169,9 +1169,6 @@ static void OuterDefine(boolean force)
|
||||||
int value;
|
int value;
|
||||||
symbolNode_t *sym;
|
symbolNode_t *sym;
|
||||||
|
|
||||||
// Don't define inside an import
|
|
||||||
if(ImportMode != IMPORT_Importing || force)
|
|
||||||
{
|
|
||||||
MS_Message(MSG_DEBUG, "---- OuterDefine %s----\n",
|
MS_Message(MSG_DEBUG, "---- OuterDefine %s----\n",
|
||||||
force ? "(forced) " : "");
|
force ? "(forced) " : "");
|
||||||
TK_NextTokenMustBe(TK_IDENTIFIER, ERR_INVALID_IDENTIFIER);
|
TK_NextTokenMustBe(TK_IDENTIFIER, ERR_INVALID_IDENTIFIER);
|
||||||
|
@ -1180,12 +1177,14 @@ static void OuterDefine(boolean force)
|
||||||
value = EvalConstExpression();
|
value = EvalConstExpression();
|
||||||
MS_Message(MSG_DEBUG, "Constant value: %d\n", value);
|
MS_Message(MSG_DEBUG, "Constant value: %d\n", value);
|
||||||
sym->info.constant.value = value;
|
sym->info.constant.value = value;
|
||||||
|
// Defines inside an import are deleted when the import is popped.
|
||||||
|
if(ImportMode != IMPORT_Importing || force)
|
||||||
|
{
|
||||||
|
sym->info.constant.fileDepth = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TK_NextToken();
|
sym->info.constant.fileDepth = TK_GetDepth();
|
||||||
TK_NextToken();
|
|
||||||
EvalConstExpression();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
94
symbol.c
94
symbol.c
|
@ -40,6 +40,8 @@ static symbolNode_t *Find(char *name, symbolNode_t *root);
|
||||||
static symbolNode_t *Insert(char *name, symbolType_t type,
|
static symbolNode_t *Insert(char *name, symbolType_t type,
|
||||||
symbolNode_t **root);
|
symbolNode_t **root);
|
||||||
static void FreeNodes(symbolNode_t *root);
|
static void FreeNodes(symbolNode_t *root);
|
||||||
|
static void FreeNodesAtDepth(symbolNode_t **root, int depth);
|
||||||
|
static void DeleteNode(symbolNode_t *node, symbolNode_t **parent_p);
|
||||||
static void ClearShared(symbolNode_t *root);
|
static void ClearShared(symbolNode_t *root);
|
||||||
|
|
||||||
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
||||||
|
@ -448,6 +450,98 @@ static void FreeNodes(symbolNode_t *root)
|
||||||
free(root);
|
free(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// SY_FreeConstants
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
void SY_FreeConstants(int depth)
|
||||||
|
{
|
||||||
|
MS_Message(MSG_DEBUG, "Freeing constants for depth %d\n", depth);
|
||||||
|
FreeNodesAtDepth(&GlobalRoot, depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// FreeNodesAtDepth
|
||||||
|
//
|
||||||
|
// Like FreeNodes, but it only frees the nodes of type SY_CONSTANT that are
|
||||||
|
// marked at the specified depth. The other nodes are relinked to maintain a
|
||||||
|
// proper binary tree.
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
static void FreeNodesAtDepth(symbolNode_t **root, int depth)
|
||||||
|
{
|
||||||
|
symbolNode_t *node = *root;
|
||||||
|
|
||||||
|
if(node == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FreeNodesAtDepth(&node->left, depth);
|
||||||
|
FreeNodesAtDepth(&node->right, depth);
|
||||||
|
if(node->type == SY_CONSTANT && node->info.constant.fileDepth == depth)
|
||||||
|
{
|
||||||
|
MS_Message(MSG_DEBUG, "Deleting constant %s\n", node->name);
|
||||||
|
DeleteNode(node, root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// DeleteNode
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
static void DeleteNode(symbolNode_t *node, symbolNode_t **parent_p)
|
||||||
|
{
|
||||||
|
symbolNode_t **temp;
|
||||||
|
|
||||||
|
if(node->left == NULL)
|
||||||
|
{
|
||||||
|
*parent_p = node->right;
|
||||||
|
free(node->name);
|
||||||
|
free(node);
|
||||||
|
}
|
||||||
|
else if(node->right == NULL)
|
||||||
|
{
|
||||||
|
*parent_p = node->left;
|
||||||
|
free(node->name);
|
||||||
|
free(node);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// "Randomly" pick the in-order successor or predecessor to take
|
||||||
|
// the place of the deleted node.
|
||||||
|
if(rand() & 1)
|
||||||
|
{
|
||||||
|
// predecessor
|
||||||
|
temp = &node->left;
|
||||||
|
while((*temp)->right != NULL)
|
||||||
|
{
|
||||||
|
temp = &(*temp)->right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// successor
|
||||||
|
temp = &node->right;
|
||||||
|
while((*temp)->left != NULL)
|
||||||
|
{
|
||||||
|
temp = &(*temp)->left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node->name = (*temp)->name;
|
||||||
|
node->type = (*temp)->type;
|
||||||
|
node->unused = (*temp)->unused;
|
||||||
|
node->imported = (*temp)->imported;
|
||||||
|
node->info = (*temp)->info;
|
||||||
|
DeleteNode(*temp, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// SY_ClearShared
|
// SY_ClearShared
|
||||||
|
|
2
symbol.h
2
symbol.h
|
@ -64,6 +64,7 @@ typedef struct
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
|
int fileDepth;
|
||||||
} symConstant_t;
|
} symConstant_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -120,6 +121,7 @@ symbolNode_t *SY_InsertGlobal(char *name, symbolType_t type);
|
||||||
symbolNode_t *SY_InsertGlobalUnique(char *name, symbolType_t type);
|
symbolNode_t *SY_InsertGlobalUnique(char *name, symbolType_t type);
|
||||||
void SY_FreeLocals(void);
|
void SY_FreeLocals(void);
|
||||||
void SY_FreeGlobals(void);
|
void SY_FreeGlobals(void);
|
||||||
|
void SY_FreeConstants(int depth);
|
||||||
void SY_ClearShared(void);
|
void SY_ClearShared(void);
|
||||||
|
|
||||||
// PUBLIC DATA DECLARATIONS ------------------------------------------------
|
// PUBLIC DATA DECLARATIONS ------------------------------------------------
|
||||||
|
|
12
token.c
12
token.c
|
@ -382,6 +382,7 @@ static int PopNestedSource(enum ImportModes *prevMode)
|
||||||
|
|
||||||
MS_Message(MSG_DEBUG, "*Leaving %s\n", tk_SourceName);
|
MS_Message(MSG_DEBUG, "*Leaving %s\n", tk_SourceName);
|
||||||
free(FileStart);
|
free(FileStart);
|
||||||
|
SY_FreeConstants(NestDepth);
|
||||||
tk_IncludedLines += tk_Line;
|
tk_IncludedLines += tk_Line;
|
||||||
info = &OpenFiles[--NestDepth];
|
info = &OpenFiles[--NestDepth];
|
||||||
tk_SourceName = info->name;
|
tk_SourceName = info->name;
|
||||||
|
@ -418,6 +419,17 @@ void TK_CloseSource(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// TK_GetDepth
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
int TK_GetDepth(void)
|
||||||
|
{
|
||||||
|
return NestDepth;
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// TK_NextToken
|
// TK_NextToken
|
||||||
|
|
1
token.h
1
token.h
|
@ -136,6 +136,7 @@ void TK_OpenSource(char *fileName);
|
||||||
void TK_Include(char *fileName);
|
void TK_Include(char *fileName);
|
||||||
void TK_Import(char *fileName, enum ImportModes prevMode);
|
void TK_Import(char *fileName, enum ImportModes prevMode);
|
||||||
void TK_CloseSource(void);
|
void TK_CloseSource(void);
|
||||||
|
int TK_GetDepth(void);
|
||||||
tokenType_t TK_NextToken(void);
|
tokenType_t TK_NextToken(void);
|
||||||
int TK_NextCharacter(void);
|
int TK_NextCharacter(void);
|
||||||
boolean TK_NextTokenMustBe(tokenType_t token, error_t error);
|
boolean TK_NextTokenMustBe(tokenType_t token, error_t error);
|
||||||
|
|
Loading…
Reference in a new issue