mirror of
https://github.com/ZDoom/acc.git
synced 2024-11-25 21:31:31 +00:00
Don't convert string constants to numbers for #define
- Fixed: You could not #define a string for use in a library, because it was converted to a number at definition time and not at use time. This is no longer the case. Symbolic constants now store the string in its original form, and they now expand into the string when encountered instead of their string table index.
This commit is contained in:
parent
9487be3e67
commit
c447410ad8
7 changed files with 32 additions and 3 deletions
2
acc.dsp
2
acc.dsp
|
@ -66,7 +66,7 @@ LINK32=link.exe
|
|||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX- /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
|
|
1
parse.c
1
parse.c
|
@ -1223,6 +1223,7 @@ static void OuterDefine(boolean force)
|
|||
value = EvalConstExpression();
|
||||
MS_Message(MSG_DEBUG, "Constant value: %d\n", value);
|
||||
sym->info.constant.value = value;
|
||||
sym->info.constant.strValue = pa_ConstExprIsString ? strdup(STR_Get(value)) : NULL;
|
||||
// Defines inside an import are deleted when the import is popped.
|
||||
if(ImportMode != IMPORT_Importing || force)
|
||||
{
|
||||
|
|
11
strlist.c
11
strlist.c
|
@ -120,6 +120,17 @@ int STR_FindLanguage(char *name)
|
|||
return i;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// STR_Get
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
char *STR_Get(int num)
|
||||
{
|
||||
return LanguageInfo[0]->list.strings[num].name;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// STR_Find
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
void STR_Init(void);
|
||||
int STR_Find(char *name);
|
||||
char *STR_Get(int index);
|
||||
void STR_WriteStrings(void);
|
||||
void STR_WriteList(void);
|
||||
int STR_FindLanguage(char *name);
|
||||
|
|
5
symbol.c
5
symbol.c
|
@ -523,6 +523,11 @@ static void DeleteNode(symbolNode_t *node, symbolNode_t **parent_p)
|
|||
symbolNode_t **temp;
|
||||
char *nametemp;
|
||||
|
||||
if(node->type == SY_CONSTANT && node->info.constant.strValue != NULL)
|
||||
{
|
||||
free(node->info.constant.strValue);
|
||||
node->info.constant.strValue = NULL;
|
||||
}
|
||||
if(node->left == NULL)
|
||||
{
|
||||
*parent_p = node->right;
|
||||
|
|
1
symbol.h
1
symbol.h
|
@ -64,6 +64,7 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
int value;
|
||||
char *strValue;
|
||||
int fileDepth;
|
||||
} symConstant_t;
|
||||
|
||||
|
|
14
token.c
14
token.c
|
@ -591,6 +591,7 @@ tokenType_t TK_NextToken(void)
|
|||
AlreadyGot = FALSE;
|
||||
return tk_Token;
|
||||
}
|
||||
tk_String = TokenStringBuffer;
|
||||
validToken = NO;
|
||||
PrevMasterSourcePos = MasterSourcePos;
|
||||
do
|
||||
|
@ -914,8 +915,17 @@ static boolean CheckForConstant(void)
|
|||
{
|
||||
return FALSE;
|
||||
}
|
||||
tk_Token = TK_NUMBER;
|
||||
tk_Number = sym->info.constant.value;
|
||||
if(sym->info.constant.strValue != NULL)
|
||||
{
|
||||
MS_Message(MSG_DEBUG, "Constant string: %s\n", sym->info.constant.strValue);
|
||||
tk_Token = TK_STRING;
|
||||
tk_String = sym->info.constant.strValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
tk_Token = TK_NUMBER;
|
||||
tk_Number = sym->info.constant.value;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue