Added .SCOPE/.ENDSCOPE

git-svn-id: svn://svn.cc65.org/cc65/trunk@2624 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-11-08 23:27:30 +00:00
parent 587b807921
commit 88e702db0f
4 changed files with 67 additions and 18 deletions

View File

@@ -7,7 +7,7 @@
/* */ /* */
/* */ /* */
/* (C) 2000-2003 Ullrich von Bassewitz */ /* (C) 2000-2003 Ullrich von Bassewitz */
/* R<>merstrasse 52 */ /* R<>merstra<EFBFBD>e 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@@ -216,7 +216,7 @@ unsigned GetFileIndex (const char* Name)
/* If we don't have this index, print a diagnostic and use the main file */ /* If we don't have this index, print a diagnostic and use the main file */
if (F == 0) { if (F == 0) {
Error ("File name `%s' not found in file table", Name); Error ("File name `%s' not found in file table", Name);
return 0; return 0;
} else { } else {
return F->Index; return F->Index;
} }
@@ -265,3 +265,4 @@ void WriteFiles (void)

View File

@@ -148,7 +148,7 @@ static void SetBoolOption (unsigned char* Flag)
/* Map the keyword to a number */ /* Map the keyword to a number */
switch (GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]))) { switch (GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]))) {
case 0: *Flag = 0; NextTok (); break; case 0: *Flag = 0; NextTok (); break;
case 1: *Flag = 1; NextTok (); break; case 1: *Flag = 1; NextTok (); break;
default: ErrorSkip ("`on' or `off' expected"); break; default: ErrorSkip ("`on' or `off' expected"); break;
} }
} else if (TokIsSep (Tok)) { } else if (TokIsSep (Tok)) {
@@ -256,7 +256,7 @@ static void ConDes (const char* Name, unsigned Type)
static void DoA16 (void) static void DoA16 (void)
/* Switch the accu to 16 bit mode (assembler only) */ /* Switch the accu to 16 bit mode (assembler only) */
{ {
if (GetCPU() != CPU_65816) { if (GetCPU() != CPU_65816) {
Error ("Command is only valid in 65816 mode"); Error ("Command is only valid in 65816 mode");
} else { } else {
@@ -410,7 +410,7 @@ static void DoAssert (void)
/* Read the message */ /* Read the message */
if (Tok != TOK_STRCON) { if (Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
} else { } else {
AddAssertion (Expr, Action, GetStringId (SVal)); AddAssertion (Expr, Action, GetStringId (SVal));
NextTok (); NextTok ();
@@ -710,6 +710,19 @@ static void DoEndProc (void)
static void DoEndScope (void)
/* Leave a lexical level */
{
if (CurrentScope != RootScope) {
SymLeaveLevel ();
} else {
/* No local scope */
ErrorSkip ("No open lexical level");
}
}
static void DoError (void) static void DoError (void)
/* User error */ /* User error */
{ {
@@ -792,7 +805,7 @@ static void DoFeature (void)
NextTok (); NextTok ();
} }
/* Allow more than one keyword */ /* Allow more than one keyword */
if (Tok == TOK_COMMA) { if (Tok == TOK_COMMA) {
NextTok (); NextTok ();
} else { } else {
@@ -1041,7 +1054,7 @@ static void DoIncBin (void)
size_t BytesRead = fread (Buf, 1, BytesToRead, F); size_t BytesRead = fread (Buf, 1, BytesToRead, F);
if (BytesToRead != BytesRead) { if (BytesToRead != BytesRead) {
/* Some sort of error */ /* Some sort of error */
ErrorSkip ("Cannot read from include file `%s': %s", ErrorSkip ("Cannot read from include file `%s': %s",
Name, strerror (errno)); Name, strerror (errno));
break; break;
} }
@@ -1396,6 +1409,35 @@ static void DoROData (void)
static void DoScope (void)
/* Start a local scope */
{
char Name[sizeof (SVal)];
if (Tok == TOK_IDENT) {
unsigned AddrSize;
/* The new scope has a name. Remember and skip it. */
strcpy (Name, SVal);
NextTok ();
/* Read an optional address size specifier */
AddrSize = OptionalAddrSize ();
/* Enter a new scope with the given name */
SymEnterLevel (Name, AddrSize);
} else {
/* An unnamed scope */
SymEnterLevel (AnonName (Name, sizeof (Name), "Scope"), ADDR_SIZE_DEFAULT);
}
}
static void DoSegment (void) static void DoSegment (void)
/* Switch to another segment */ /* Switch to another segment */
{ {
@@ -1570,6 +1612,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoUnexpected }, /* .ENDMACRO */ { ccNone, DoUnexpected }, /* .ENDMACRO */
{ ccNone, DoEndProc }, { ccNone, DoEndProc },
{ ccNone, DoUnexpected }, /* .ENDREPEAT */ { ccNone, DoUnexpected }, /* .ENDREPEAT */
{ ccNone, DoEndScope },
{ ccNone, DoUnexpected }, /* .ENDSTRUCT */ { ccNone, DoUnexpected }, /* .ENDSTRUCT */
{ ccNone, DoError }, { ccNone, DoError },
{ ccNone, DoExitMacro }, { ccNone, DoExitMacro },
@@ -1617,41 +1660,42 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoP02 }, { ccNone, DoP02 },
{ ccNone, DoP816 }, { ccNone, DoP816 },
{ ccNone, DoPageLength }, { ccNone, DoPageLength },
{ ccNone, DoUnexpected }, /* .PARAMCOUNT */ { ccNone, DoUnexpected }, /* .PARAMCOUNT */
{ ccNone, DoPC02 }, { ccNone, DoPC02 },
{ ccNone, DoPopSeg }, { ccNone, DoPopSeg },
{ ccNone, DoProc }, { ccNone, DoProc },
{ ccNone, DoPSC02 }, { ccNone, DoPSC02 },
{ ccNone, DoPushSeg }, { ccNone, DoPushSeg },
{ ccNone, DoUnexpected }, /* .REFERENCED */ { ccNone, DoUnexpected }, /* .REFERENCED */
{ ccNone, DoReloc }, { ccNone, DoReloc },
{ ccNone, DoRepeat }, { ccNone, DoRepeat },
{ ccNone, DoRes }, { ccNone, DoRes },
{ ccNone, DoInvalid }, /* .RIGHT */ { ccNone, DoInvalid }, /* .RIGHT */
{ ccNone, DoROData }, { ccNone, DoROData },
{ ccNone, DoScope },
{ ccNone, DoSegment }, { ccNone, DoSegment },
{ ccNone, DoSetCPU }, { ccNone, DoSetCPU },
{ ccNone, DoSmart }, { ccNone, DoSmart },
{ ccNone, DoUnexpected }, /* .STRAT */ { ccNone, DoUnexpected }, /* .STRAT */
{ ccNone, DoUnexpected }, /* .STRING */ { ccNone, DoUnexpected }, /* .STRING */
{ ccNone, DoUnexpected }, /* .STRLEN */ { ccNone, DoUnexpected }, /* .STRLEN */
{ ccNone, DoStruct }, { ccNone, DoStruct },
{ ccNone, DoSunPlus }, { ccNone, DoSunPlus },
{ ccNone, DoUnexpected }, /* .TAG */ { ccNone, DoUnexpected }, /* .TAG */
{ ccNone, DoUnexpected }, /* .TCOUNT */ { ccNone, DoUnexpected }, /* .TCOUNT */
{ ccNone, DoUnexpected }, /* .TIME */ { ccNone, DoUnexpected }, /* .TIME */
{ ccNone, DoUnion }, { ccNone, DoUnion },
{ ccNone, DoUnexpected }, /* .VERSION */ { ccNone, DoUnexpected }, /* .VERSION */
{ ccNone, DoWarning }, { ccNone, DoWarning },
{ ccNone, DoWord }, { ccNone, DoWord },
{ ccNone, DoUnexpected }, /* .XMATCH */ { ccNone, DoUnexpected }, /* .XMATCH */
{ ccNone, DoZeropage }, { ccNone, DoZeropage },
}; };
/*****************************************************************************/ /*****************************************************************************/
/* Code */ /* Code */
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -160,6 +160,7 @@ struct DotKeyword {
{ ".ENDPROC", TOK_ENDPROC }, { ".ENDPROC", TOK_ENDPROC },
{ ".ENDREP", TOK_ENDREP }, { ".ENDREP", TOK_ENDREP },
{ ".ENDREPEAT", TOK_ENDREP }, { ".ENDREPEAT", TOK_ENDREP },
{ ".ENDSCOPE", TOK_ENDSCOPE },
{ ".ENDSTRUCT", TOK_ENDSTRUCT }, { ".ENDSTRUCT", TOK_ENDSTRUCT },
{ ".ERROR", TOK_ERROR }, { ".ERROR", TOK_ERROR },
{ ".EXITMAC", TOK_EXITMACRO }, { ".EXITMAC", TOK_EXITMACRO },
@@ -227,6 +228,7 @@ struct DotKeyword {
{ ".RES", TOK_RES }, { ".RES", TOK_RES },
{ ".RIGHT", TOK_RIGHT }, { ".RIGHT", TOK_RIGHT },
{ ".RODATA", TOK_RODATA }, { ".RODATA", TOK_RODATA },
{ ".SCOPE", TOK_SCOPE },
{ ".SEGMENT", TOK_SEGMENT }, { ".SEGMENT", TOK_SEGMENT },
{ ".SETCPU", TOK_SETCPU }, { ".SETCPU", TOK_SETCPU },
{ ".SHL", TOK_SHL }, { ".SHL", TOK_SHL },

View File

@@ -148,6 +148,7 @@ enum Token {
TOK_ENDMACRO, TOK_ENDMACRO,
TOK_ENDPROC, TOK_ENDPROC,
TOK_ENDREP, TOK_ENDREP,
TOK_ENDSCOPE,
TOK_ENDSTRUCT, TOK_ENDSTRUCT,
TOK_ERROR, TOK_ERROR,
TOK_EXITMACRO, TOK_EXITMACRO,
@@ -191,7 +192,7 @@ enum Token {
TOK_MID, TOK_MID,
TOK_NULL, TOK_NULL,
TOK_ORG, TOK_ORG,
TOK_OUT, TOK_OUT,
TOK_P02, TOK_P02,
TOK_P816, TOK_P816,
TOK_PAGELENGTH, TOK_PAGELENGTH,
@@ -207,6 +208,7 @@ enum Token {
TOK_RES, TOK_RES,
TOK_RIGHT, TOK_RIGHT,
TOK_RODATA, TOK_RODATA,
TOK_SCOPE,
TOK_SEGMENT, TOK_SEGMENT,
TOK_SETCPU, TOK_SETCPU,
TOK_SMART, TOK_SMART,