More work on .sizeof
git-svn-id: svn://svn.cc65.org/cc65/trunk@2702 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -42,6 +42,7 @@
|
|||||||
#include "exprdefs.h"
|
#include "exprdefs.h"
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
#include "shift.h"
|
#include "shift.h"
|
||||||
|
#include "strbuf.h"
|
||||||
#include "tgttrans.h"
|
#include "tgttrans.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
@@ -385,16 +386,43 @@ static ExprNode* FuncReferenced (void)
|
|||||||
static ExprNode* FuncSizeOf (void)
|
static ExprNode* FuncSizeOf (void)
|
||||||
/* Handle the .SIZEOF function */
|
/* Handle the .SIZEOF function */
|
||||||
{
|
{
|
||||||
/* Get the struct for the scoped struct name */
|
StrBuf FullName = AUTO_STRBUF_INITIALIZER;
|
||||||
SymTable* Struct = ParseScopedSymTable (SYM_FIND_EXISTING);
|
char Name[sizeof (SVal)];
|
||||||
|
SymTable* Scope;
|
||||||
|
SymEntry* Sym;
|
||||||
|
SymEntry* SizeSym;
|
||||||
|
long Size;
|
||||||
|
|
||||||
/* Check if the given symbol is really a struct */
|
|
||||||
if (GetSymTabType (Struct) != ST_STRUCT) {
|
/* Parse the scope and the name */
|
||||||
Error ("Argument to .SIZEOF is not a struct");
|
SymTable* ParentScope = ParseScopedIdent (Name, &FullName);
|
||||||
|
|
||||||
|
/* Check if the parent scope is valid */
|
||||||
|
if (ParentScope == 0) {
|
||||||
|
/* No such scope */
|
||||||
|
DoneStrBuf (&FullName);
|
||||||
return GenLiteralExpr (0);
|
return GenLiteralExpr (0);
|
||||||
} else {
|
|
||||||
return Symbol (GetSizeOfScope (Struct));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The scope is valid, search first for a child scope, then for a symbol */
|
||||||
|
if ((Scope = SymFindScope (ParentScope, Name, SYM_FIND_EXISTING)) != 0) {
|
||||||
|
/* Yep, it's a scope */
|
||||||
|
SizeSym = GetSizeOfScope (Scope);
|
||||||
|
} else if ((Sym = SymFind (ParentScope, Name, SYM_FIND_EXISTING)) != 0) {
|
||||||
|
SizeSym = GetSizeOfSymbol (Sym);
|
||||||
|
} else {
|
||||||
|
Error ("Unknown symbol or scope: `%s'", SB_GetConstBuf (&FullName));
|
||||||
|
return GenLiteralExpr (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if we have a size */
|
||||||
|
if (SizeSym == 0 || !SymIsConst (SizeSym, &Size)) {
|
||||||
|
Error ("Size of `%s' is unknown", SB_GetConstBuf (&FullName));
|
||||||
|
return GenLiteralExpr (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the size */
|
||||||
|
return GenLiteralExpr (Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
#include "pseudo.h"
|
#include "pseudo.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "segment.h"
|
#include "segment.h"
|
||||||
|
#include "sizeof.h"
|
||||||
#include "spool.h"
|
#include "spool.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
#include "ulabel.h"
|
#include "ulabel.h"
|
||||||
@@ -373,8 +374,11 @@ static void DoPCAssign (void)
|
|||||||
|
|
||||||
static void OneLine (void)
|
static void OneLine (void)
|
||||||
/* Assemble one line */
|
/* Assemble one line */
|
||||||
{
|
{
|
||||||
int Done = 0;
|
Segment* Seg = 0;
|
||||||
|
unsigned long PC = 0;
|
||||||
|
SymEntry* Sym = 0;
|
||||||
|
int Done = 0;
|
||||||
|
|
||||||
/* Initialize the new listing line if we are actually reading from file
|
/* Initialize the new listing line if we are actually reading from file
|
||||||
* and not from internally pushed input.
|
* and not from internally pushed input.
|
||||||
@@ -396,7 +400,6 @@ static void OneLine (void)
|
|||||||
int HadWS = WS;
|
int HadWS = WS;
|
||||||
|
|
||||||
/* Generate the symbol table entry, then skip the name */
|
/* Generate the symbol table entry, then skip the name */
|
||||||
SymEntry* Sym;
|
|
||||||
if (Tok == TOK_IDENT) {
|
if (Tok == TOK_IDENT) {
|
||||||
Sym = SymFind (CurrentScope, SVal, SYM_ALLOC_NEW);
|
Sym = SymFind (CurrentScope, SVal, SYM_ALLOC_NEW);
|
||||||
} else {
|
} else {
|
||||||
@@ -417,8 +420,15 @@ static void OneLine (void)
|
|||||||
/* Don't allow anything after a symbol definition */
|
/* Don't allow anything after a symbol definition */
|
||||||
Done = 1;
|
Done = 1;
|
||||||
} else {
|
} else {
|
||||||
/* Define a label */
|
/* A label. Remember the current segment, so we can later
|
||||||
|
* determine the size of the data stored under the label.
|
||||||
|
*/
|
||||||
|
Seg = ActiveSeg;
|
||||||
|
PC = GetPC ();
|
||||||
|
|
||||||
|
/* Define the label */
|
||||||
SymDef (Sym, GenCurrentPC (), ADDR_SIZE_DEFAULT, SF_LABEL);
|
SymDef (Sym, GenCurrentPC (), ADDR_SIZE_DEFAULT, SF_LABEL);
|
||||||
|
|
||||||
/* Skip the colon. If NoColonLabels is enabled, allow labels
|
/* Skip the colon. If NoColonLabels is enabled, allow labels
|
||||||
* without a colon if there is no whitespace before the
|
* without a colon if there is no whitespace before the
|
||||||
* identifier.
|
* identifier.
|
||||||
@@ -461,6 +471,22 @@ static void OneLine (void)
|
|||||||
DoPCAssign ();
|
DoPCAssign ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we have defined a label, remember its size. Sym is also set by
|
||||||
|
* a symbol assignment, but in this case Done is false, so we don't
|
||||||
|
* come here.
|
||||||
|
*/
|
||||||
|
if (Sym) {
|
||||||
|
unsigned long Size;
|
||||||
|
if (Seg == ActiveSeg) {
|
||||||
|
/* Same segment */
|
||||||
|
Size = GetPC () - PC;
|
||||||
|
} else {
|
||||||
|
/* The line has switched the segment */
|
||||||
|
Size = 0;
|
||||||
|
}
|
||||||
|
DefSizeOfSymbol (Sym, Size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Line separator must come here */
|
/* Line separator must come here */
|
||||||
|
|||||||
@@ -69,6 +69,7 @@
|
|||||||
#include "pseudo.h"
|
#include "pseudo.h"
|
||||||
#include "repeat.h"
|
#include "repeat.h"
|
||||||
#include "segment.h"
|
#include "segment.h"
|
||||||
|
#include "sizeof.h"
|
||||||
#include "spool.h"
|
#include "spool.h"
|
||||||
#include "struct.h"
|
#include "struct.h"
|
||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
@@ -1507,11 +1508,12 @@ static void DoSunPlus (void)
|
|||||||
|
|
||||||
static void DoTag (void)
|
static void DoTag (void)
|
||||||
/* Allocate space for a struct */
|
/* Allocate space for a struct */
|
||||||
{
|
{
|
||||||
|
SymEntry* SizeSym;
|
||||||
long Size;
|
long Size;
|
||||||
|
|
||||||
/* Read the struct name */
|
/* Read the struct name */
|
||||||
SymTable* Struct = ParseScopedSymTable (SYM_FIND_EXISTING);
|
SymTable* Struct = ParseScopedSymTable ();
|
||||||
|
|
||||||
/* Check the supposed struct */
|
/* Check the supposed struct */
|
||||||
if (Struct == 0) {
|
if (Struct == 0) {
|
||||||
@@ -1523,8 +1525,14 @@ static void DoTag (void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the size of the struct */
|
/* Get the symbol that defines the size of the struct */
|
||||||
Size = GetSymVal (SymFind (Struct, ".size", SYM_FIND_EXISTING));
|
SizeSym = GetSizeOfScope (Struct);
|
||||||
|
|
||||||
|
/* Check if it does exist and if its value is known */
|
||||||
|
if (SizeSym == 0 || !SymIsConst (SizeSym, &Size)) {
|
||||||
|
ErrorSkip ("Size of struct/union is unknown");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Optional multiplicator may follow */
|
/* Optional multiplicator may follow */
|
||||||
if (Tok == TOK_COMMA) {
|
if (Tok == TOK_COMMA) {
|
||||||
|
|||||||
@@ -33,6 +33,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "addrsize.h"
|
||||||
|
|
||||||
/* ca65 */
|
/* ca65 */
|
||||||
#include "sizeof.h"
|
#include "sizeof.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
@@ -80,3 +83,21 @@ SymEntry* GetSizeOfSymbol (SymEntry* Sym)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SymEntry* DefSizeOfScope (SymTable* Scope, long Size)
|
||||||
|
/* Define the size of a scope and return the size symbol */
|
||||||
|
{
|
||||||
|
SymEntry* SizeSym = GetSizeOfScope (Scope);
|
||||||
|
SymDef (SizeSym, GenLiteralExpr (Size), ADDR_SIZE_DEFAULT, SF_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SymEntry* DefSizeOfSymbol (SymEntry* Sym, long Size)
|
||||||
|
/* Define the size of a symbol and return the size symbol */
|
||||||
|
{
|
||||||
|
SymEntry* SizeSym = GetSizeOfSymbol (Sym);
|
||||||
|
SymDef (SizeSym, GenLiteralExpr (Size), ADDR_SIZE_DEFAULT, SF_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ struct SymEntry* GetSizeOfSymbol (struct SymEntry* Sym);
|
|||||||
* does not exist.
|
* does not exist.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
struct SymEntry* DefSizeOfScope (struct SymTable* Scope, long Size);
|
||||||
|
/* Define the size of a scope and return the size symbol */
|
||||||
|
|
||||||
|
struct SymEntry* DefSizeOfSymbol (struct SymEntry* Sym, long Size);
|
||||||
|
/* Define the size of a symbol and return the size symbol */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End of sizeof.h */
|
/* End of sizeof.h */
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ static long DoStructInternal (long Offs, unsigned Type)
|
|||||||
while (Tok != TOK_ENDSTRUCT && Tok != TOK_ENDUNION && Tok != TOK_EOF) {
|
while (Tok != TOK_ENDSTRUCT && Tok != TOK_ENDUNION && Tok != TOK_EOF) {
|
||||||
|
|
||||||
long MemberSize;
|
long MemberSize;
|
||||||
SymEntry* Sym;
|
|
||||||
SymTable* Struct;
|
SymTable* Struct;
|
||||||
|
|
||||||
/* The format is "[identifier] storage-allocator [, multiplicator]" */
|
/* The format is "[identifier] storage-allocator [, multiplicator]" */
|
||||||
|
SymEntry* Sym = 0;
|
||||||
if (Tok == TOK_IDENT) {
|
if (Tok == TOK_IDENT) {
|
||||||
/* We have an identifier, generate a symbol */
|
/* We have an identifier, generate a symbol */
|
||||||
Sym = SymFind (CurrentScope, SVal, SYM_ALLOC_NEW);
|
Sym = SymFind (CurrentScope, SVal, SYM_ALLOC_NEW);
|
||||||
@@ -168,7 +168,7 @@ static long DoStructInternal (long Offs, unsigned Type)
|
|||||||
|
|
||||||
case TOK_TAG:
|
case TOK_TAG:
|
||||||
NextTok ();
|
NextTok ();
|
||||||
Struct = ParseScopedSymTable (SYM_FIND_EXISTING);
|
Struct = ParseScopedSymTable ();
|
||||||
if (Struct == 0) {
|
if (Struct == 0) {
|
||||||
Error ("Unknown struct/union");
|
Error ("Unknown struct/union");
|
||||||
} else if (GetSymTabType (Struct) != ST_STRUCT) {
|
} else if (GetSymTabType (Struct) != ST_STRUCT) {
|
||||||
@@ -200,6 +200,11 @@ static long DoStructInternal (long Offs, unsigned Type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Assign the size to the member if it has a name */
|
||||||
|
if (Sym) {
|
||||||
|
DefSizeOfSymbol (Sym, MemberSize);
|
||||||
|
}
|
||||||
|
|
||||||
/* Next member */
|
/* Next member */
|
||||||
if (Type == STRUCT) {
|
if (Type == STRUCT) {
|
||||||
/* Struct */
|
/* Struct */
|
||||||
|
|||||||
@@ -35,6 +35,9 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/* common */
|
||||||
|
#include "strbuf.h"
|
||||||
|
|
||||||
/* ca65 */
|
/* ca65 */
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "nexttok.h"
|
#include "nexttok.h"
|
||||||
@@ -45,14 +48,103 @@
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Data */
|
/* Code */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
SymTable* ParseScopedIdent (char* Name, StrBuf* FullName)
|
||||||
/* Code */
|
/* Parse a (possibly scoped) identifer. Name must point to a buffer big enough
|
||||||
/*****************************************************************************/
|
* to hold such an identifier. The scope of the name must exist and is returned
|
||||||
|
* as function result, while the last part (the identifier) which may be either
|
||||||
|
* a symbol or a scope depending on the context is returned in Name. FullName
|
||||||
|
* is a string buffer that is used to store the full name of the identifier
|
||||||
|
* including the scope. It is used internally and may be used by the caller
|
||||||
|
* for error messages or similar.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* Get the starting table */
|
||||||
|
SymTable* Scope;
|
||||||
|
if (Tok == TOK_NAMESPACE) {
|
||||||
|
|
||||||
|
/* Start from the root scope */
|
||||||
|
Scope = RootScope;
|
||||||
|
|
||||||
|
} else if (Tok == TOK_IDENT) {
|
||||||
|
|
||||||
|
/* Remember the name and skip it */
|
||||||
|
SB_AppendStr (FullName, strcpy (Name, SVal));
|
||||||
|
NextTok ();
|
||||||
|
|
||||||
|
/* If no namespace symbol follows, we're already done */
|
||||||
|
if (Tok != TOK_NAMESPACE) {
|
||||||
|
SB_Terminate (FullName);
|
||||||
|
return CurrentScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The scope must exist, so search for it starting with the current
|
||||||
|
* scope.
|
||||||
|
*/
|
||||||
|
Scope = SymFindAnyScope (CurrentScope, Name);
|
||||||
|
if (Scope == 0) {
|
||||||
|
/* Scope not found */
|
||||||
|
SB_Terminate (FullName);
|
||||||
|
Error ("No such scope: `%s'", SB_GetConstBuf (FullName));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/* Invalid token */
|
||||||
|
Error ("Identifier expected");
|
||||||
|
SB_Terminate (FullName);
|
||||||
|
Name[0] = '\0';
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Skip the namespace token that follows */
|
||||||
|
SB_AppendStr (FullName, "::");
|
||||||
|
NextTok ();
|
||||||
|
|
||||||
|
/* Resolve scopes. */
|
||||||
|
while (1) {
|
||||||
|
|
||||||
|
/* Next token must be an identifier. */
|
||||||
|
if (Tok != TOK_IDENT) {
|
||||||
|
Error ("Identifier expected");
|
||||||
|
SB_Terminate (FullName);
|
||||||
|
Name[0] = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remember and skip the identifier */
|
||||||
|
SB_AppendStr (FullName, strcpy (Name, SVal));
|
||||||
|
NextTok ();
|
||||||
|
|
||||||
|
/* If a namespace token follows, we search for another scope, otherwise
|
||||||
|
* the name is a symbol and we're done.
|
||||||
|
*/
|
||||||
|
if (Tok != TOK_NAMESPACE) {
|
||||||
|
/* Symbol */
|
||||||
|
SB_Terminate (FullName);
|
||||||
|
return Scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search for the child scope */
|
||||||
|
Scope = SymFindScope (Scope, Name, SYM_FIND_EXISTING);
|
||||||
|
if (Scope == 0) {
|
||||||
|
/* Scope not found */
|
||||||
|
SB_Terminate (FullName);
|
||||||
|
Error ("No such scope: `%s'", SB_GetConstBuf (FullName));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Skip the namespace token that follows */
|
||||||
|
SB_AppendStr (FullName, "::");
|
||||||
|
NextTok ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -61,110 +153,57 @@ SymEntry* ParseScopedSymName (int AllocNew)
|
|||||||
* and return the symbol table entry.
|
* and return the symbol table entry.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Get the starting table */
|
StrBuf FullName = AUTO_STRBUF_INITIALIZER;
|
||||||
SymTable* Scope;
|
char Ident[sizeof (SVal)];
|
||||||
if (Tok == TOK_NAMESPACE) {
|
|
||||||
Scope = RootScope;
|
/* Parse the scoped symbol name */
|
||||||
NextTok ();
|
SymTable* Scope = ParseScopedIdent (Ident, &FullName);
|
||||||
|
|
||||||
|
/* We don't need FullName any longer */
|
||||||
|
DoneStrBuf (&FullName);
|
||||||
|
|
||||||
|
/* Check if the scope is valid. Errors have already been diagnosed by
|
||||||
|
* the routine, so just exit.
|
||||||
|
*/
|
||||||
|
if (Scope) {
|
||||||
|
/* Search for the symbol and return it */
|
||||||
|
return SymFind (Scope, Ident, AllocNew);
|
||||||
} else {
|
} else {
|
||||||
Scope = CurrentScope;
|
/* No scope ==> no symbol. To avoid errors in the calling routine that
|
||||||
/* ### Need to walk up the tree */
|
* may not expect NULL to be returned if AllocNew is true, create a new
|
||||||
}
|
* symbol.
|
||||||
|
|
||||||
/* Resolve scopes */
|
|
||||||
while (1) {
|
|
||||||
|
|
||||||
/* An identifier must follow. Remember and skip it. */
|
|
||||||
char Name[sizeof (SVal)];
|
|
||||||
if (Tok != TOK_IDENT) {
|
|
||||||
Error ("Identifier expected");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
strcpy (Name, SVal);
|
|
||||||
NextTok ();
|
|
||||||
|
|
||||||
/* If the next token is a namespace token, handle the name as the
|
|
||||||
* name of a scope, otherwise it's the name of a symbol in that
|
|
||||||
* scope.
|
|
||||||
*/
|
*/
|
||||||
|
if (AllocNew) {
|
||||||
if (Tok == TOK_NAMESPACE) {
|
return NewSymEntry (Ident);
|
||||||
|
|
||||||
/* Search for the child scope */
|
|
||||||
Scope = SymFindScope (Scope, Name, AllocNew);
|
|
||||||
|
|
||||||
/* Skip the namespace token */
|
|
||||||
NextTok ();
|
|
||||||
|
|
||||||
/* If we didn't find the scope, bail out */
|
|
||||||
if (Scope == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
return 0;
|
||||||
/* Search for the symbol and return it */
|
|
||||||
return SymFind (Scope, Name, AllocNew);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SymTable* ParseScopedSymTable (int AllocNew)
|
SymTable* ParseScopedSymTable (void)
|
||||||
/* Parse a (possibly scoped) symbol table (scope) name, search for it in the
|
/* Parse a (possibly scoped) symbol table (scope) name, search for it in the
|
||||||
* symbol space and return the symbol table struct.
|
* symbol space and return the symbol table struct.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Get the starting table */
|
StrBuf FullName = AUTO_STRBUF_INITIALIZER;
|
||||||
SymTable* Scope;
|
char Ident[sizeof (SVal)];
|
||||||
if (Tok == TOK_NAMESPACE) {
|
|
||||||
Scope = RootScope;
|
|
||||||
NextTok ();
|
|
||||||
} else {
|
|
||||||
Scope = CurrentScope;
|
|
||||||
if (Tok != TOK_IDENT) {
|
|
||||||
Error ("Identifier expected");
|
|
||||||
return Scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If no new scope should be allocated, the scope may specify any
|
/* Parse the scoped symbol name */
|
||||||
* scope in any of the parent scopes, so search for it.
|
SymTable* Scope = ParseScopedIdent (Ident, &FullName);
|
||||||
*/
|
|
||||||
if (!AllocNew) {
|
/* We don't need FullName any longer */
|
||||||
Scope = SymFindAnyScope (Scope, SVal);
|
DoneStrBuf (&FullName);
|
||||||
NextTok ();
|
|
||||||
if (Tok != TOK_NAMESPACE) {
|
/* Check if the scope is valid. Errors have already been diagnosed by
|
||||||
return Scope;
|
* the routine, so just exit.
|
||||||
}
|
*/
|
||||||
NextTok ();
|
if (Scope) {
|
||||||
}
|
/* Search for the last scope */
|
||||||
|
Scope = SymFindScope (Scope, Ident, SYM_FIND_EXISTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resolve scopes. */
|
|
||||||
while (Tok == TOK_IDENT) {
|
|
||||||
|
|
||||||
/* Search for the child scope if we have a valid parent */
|
|
||||||
if (Scope) {
|
|
||||||
Scope = SymFindScope (Scope, SVal, AllocNew);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Skip the name token */
|
|
||||||
NextTok ();
|
|
||||||
|
|
||||||
/* If a namespace token follows, read on, otherwise bail out */
|
|
||||||
if (Tok == TOK_NAMESPACE) {
|
|
||||||
NextTok ();
|
|
||||||
if (Tok != TOK_IDENT) {
|
|
||||||
Error ("Identifier expected");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return the scope we found or created */
|
|
||||||
return Scope;
|
return Scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,23 +39,38 @@
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Data */
|
/* Forwards */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct StrBuf;
|
||||||
|
struct SymTable;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Code */
|
/* Code */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct SymTable* ParseScopedIdent (char* Name, struct StrBuf* FullName);
|
||||||
|
/* Parse a (possibly scoped) identifer. Name must point to a buffer big enough
|
||||||
|
* to hold such an identifier. The scope of the name must exist and is returned
|
||||||
|
* as function result, while the last part (the identifier) which may be either
|
||||||
|
* a symbol or a scope depending on the context is returned in Name. FullName
|
||||||
|
* is a string buffer that is used to store the full name of the identifier
|
||||||
|
* including the scope. It is used internally and may be used by the caller
|
||||||
|
* for error messages or similar.
|
||||||
|
*/
|
||||||
|
|
||||||
struct SymEntry* ParseScopedSymName (int AllowNew);
|
struct SymEntry* ParseScopedSymName (int AllowNew);
|
||||||
/* Parse a (possibly scoped) symbol name, search for it in the symbol table
|
/* Parse a (possibly scoped) symbol name, search for it in the symbol table
|
||||||
* and return the symbol table entry.
|
* and return the symbol table entry.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct SymTable* ParseScopedSymTable (int AllocNew);
|
struct SymTable* ParseScopedSymTable (void);
|
||||||
/* Parse a (possibly scoped) symbol table (scope) name, search for it in the
|
/* Parse a (possibly scoped) symbol table (scope) name, search for it in the
|
||||||
* symbol space and return the symbol table struct.
|
* symbol space and return the symbol table struct.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user