Finished implemenation of commands to delete macros. Added the new commands to
the docs. git-svn-id: svn://svn.cc65.org/cc65/trunk@5050 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -206,15 +206,39 @@ static IdDesc* NewIdDesc (const StrBuf* Id)
|
||||
/* Create a new IdDesc, initialize and return it */
|
||||
{
|
||||
/* Allocate memory */
|
||||
IdDesc* I = xmalloc (sizeof (IdDesc));
|
||||
IdDesc* ID = xmalloc (sizeof (IdDesc));
|
||||
|
||||
/* Initialize the struct */
|
||||
I->Next = 0;
|
||||
SB_Init (&I->Id);
|
||||
SB_Copy (&I->Id, Id);
|
||||
ID->Next = 0;
|
||||
SB_Init (&ID->Id);
|
||||
SB_Copy (&ID->Id, Id);
|
||||
|
||||
/* Return the new struct */
|
||||
return I;
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void FreeIdDesc (IdDesc* ID)
|
||||
/* Free an IdDesc */
|
||||
{
|
||||
/* Free the name */
|
||||
SB_Done (&ID->Id);
|
||||
|
||||
/* Free the structure itself */
|
||||
xfree (ID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void FreeIdDescList (IdDesc* ID)
|
||||
/* Free a complete list of IdDesc structures */
|
||||
{
|
||||
while (ID) {
|
||||
IdDesc* This = ID;
|
||||
ID = ID->Next;
|
||||
FreeIdDesc (This);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -249,6 +273,32 @@ static Macro* NewMacro (const StrBuf* Name, unsigned char Style)
|
||||
|
||||
|
||||
|
||||
static void FreeMacro (Macro* M)
|
||||
/* Free a macro entry which has already been removed from the macro table. */
|
||||
{
|
||||
TokNode* T;
|
||||
|
||||
/* Free locals */
|
||||
FreeIdDescList (M->Locals);
|
||||
|
||||
/* Free identifiers of parameters */
|
||||
FreeIdDescList (M->Params);
|
||||
|
||||
/* Free the token list for the macro */
|
||||
while ((T = M->TokRoot) != 0) {
|
||||
M->TokRoot = T->Next;
|
||||
FreeTokNode (T);
|
||||
}
|
||||
|
||||
/* Free the macro name */
|
||||
SB_Done (&M->Name);
|
||||
|
||||
/* Free the macro structure itself */
|
||||
xfree (M);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static MacExp* NewMacExp (Macro* M)
|
||||
/* Create a new expansion structure for the given macro */
|
||||
{
|
||||
@@ -552,14 +602,16 @@ Done:
|
||||
|
||||
|
||||
|
||||
void MacUndef (const StrBuf* Name)
|
||||
/* Undefine the macro with the given name. */
|
||||
void MacUndef (const StrBuf* Name, unsigned char Style)
|
||||
/* Undefine the macro with the given name and style. A style mismatch is
|
||||
* treated as if the macro didn't exist.
|
||||
*/
|
||||
{
|
||||
/* Search for the macro */
|
||||
Macro* M = HT_FindEntry (&MacroTab, Name);
|
||||
|
||||
/* Don't let the user kid with us */
|
||||
if (M == 0) {
|
||||
if (M == 0 || M->Style != Style) {
|
||||
Error ("No such macro: %m%p", Name);
|
||||
return;
|
||||
}
|
||||
@@ -570,6 +622,9 @@ void MacUndef (const StrBuf* Name)
|
||||
|
||||
/* Remove the macro from the macro table */
|
||||
HT_RemoveEntry (&MacroTab, M);
|
||||
|
||||
/* Free the macro structure */
|
||||
FreeMacro (M);
|
||||
}
|
||||
|
||||
|
||||
@@ -928,11 +983,11 @@ int IsMacro (const StrBuf* Name)
|
||||
|
||||
int IsDefine (const StrBuf* Name)
|
||||
/* Return true if the given name is the name of a define style macro */
|
||||
{
|
||||
{
|
||||
Macro* M;
|
||||
|
||||
/* Never if disabled */
|
||||
if (DisableDefines) {
|
||||
if (DisableDefines) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,8 +69,10 @@ struct StrBuf;
|
||||
void MacDef (unsigned Style);
|
||||
/* Parse a macro definition */
|
||||
|
||||
void MacUndef (const struct StrBuf* Name);
|
||||
/* Undefine the macro with the given name. */
|
||||
void MacUndef (const StrBuf* Name, unsigned char Style);
|
||||
/* Undefine the macro with the given name and style. A style mismatch is
|
||||
* treated as if the macro didn't exist.
|
||||
*/
|
||||
|
||||
void MacExpandStart (void);
|
||||
/* Start expanding the macro in SVal */
|
||||
|
||||
@@ -753,6 +753,20 @@ static void DoDefine (void)
|
||||
|
||||
|
||||
|
||||
static void DoDelMac (void)
|
||||
/* Delete a classic macro */
|
||||
{
|
||||
/* We expect an identifier */
|
||||
if (CurTok.Tok != TOK_IDENT) {
|
||||
ErrorSkip ("Identifier expected");
|
||||
} else {
|
||||
MacUndef (&CurTok.SVal, MAC_STYLE_CLASSIC);
|
||||
NextTok ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void DoDestructor (void)
|
||||
/* Export a symbol as destructor */
|
||||
{
|
||||
@@ -1779,11 +1793,11 @@ static void DoTag (void)
|
||||
|
||||
|
||||
static void DoUnDef (void)
|
||||
/* Undefine a macro */
|
||||
{
|
||||
/* Undefine a define style macro */
|
||||
{
|
||||
/* The function is called with the .UNDEF token in place, because we need
|
||||
* to disable .define macro expansions before reading the next token.
|
||||
* Otherwise the name of the macro would be expanded, so we would never
|
||||
* to disable .define macro expansions before reading the next token.
|
||||
* Otherwise the name of the macro would be expanded, so we would never
|
||||
* see it.
|
||||
*/
|
||||
DisableDefineStyleMacros ();
|
||||
@@ -1794,7 +1808,7 @@ static void DoUnDef (void)
|
||||
if (CurTok.Tok != TOK_IDENT) {
|
||||
ErrorSkip ("Identifier expected");
|
||||
} else {
|
||||
MacUndef (&CurTok.SVal);
|
||||
MacUndef (&CurTok.SVal, MAC_STYLE_DEFINE);
|
||||
NextTok ();
|
||||
}
|
||||
}
|
||||
@@ -1893,6 +1907,7 @@ static CtrlDesc CtrlCmdTab [] = {
|
||||
{ ccNone, DoDebugInfo },
|
||||
{ ccNone, DoDefine },
|
||||
{ ccNone, DoUnexpected }, /* .DEFINED */
|
||||
{ ccNone, DoDelMac },
|
||||
{ ccNone, DoDestructor },
|
||||
{ ccNone, DoDWord },
|
||||
{ ccKeepToken, DoConditionals }, /* .ELSE */
|
||||
|
||||
@@ -166,6 +166,8 @@ struct DotKeyword {
|
||||
{ ".DEF", TOK_DEFINED },
|
||||
{ ".DEFINE", TOK_DEFINE },
|
||||
{ ".DEFINED", TOK_DEFINED },
|
||||
{ ".DELMAC", TOK_DELMAC },
|
||||
{ ".DELMACRO", TOK_DELMAC },
|
||||
{ ".DESTRUCTOR", TOK_DESTRUCTOR },
|
||||
{ ".DWORD", TOK_DWORD },
|
||||
{ ".ELSE", TOK_ELSE },
|
||||
|
||||
@@ -147,6 +147,7 @@ typedef enum token_t {
|
||||
TOK_DEBUGINFO,
|
||||
TOK_DEFINE,
|
||||
TOK_DEFINED,
|
||||
TOK_DELMAC,
|
||||
TOK_DESTRUCTOR,
|
||||
TOK_DWORD,
|
||||
TOK_ELSE,
|
||||
|
||||
Reference in New Issue
Block a user