Move scope type definitions to common/
git-svn-id: svn://svn.cc65.org/cc65/trunk@5095 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "addrsize.h"
|
#include "addrsize.h"
|
||||||
|
#include "scopedefs.h"
|
||||||
|
|
||||||
/* ca65 */
|
/* ca65 */
|
||||||
#include "condasm.h"
|
#include "condasm.h"
|
||||||
@@ -66,7 +67,7 @@ void DoEnum (void)
|
|||||||
int Anon = (CurTok.Tok != TOK_IDENT);
|
int Anon = (CurTok.Tok != TOK_IDENT);
|
||||||
if (!Anon) {
|
if (!Anon) {
|
||||||
/* Enter a new scope, then skip the name */
|
/* Enter a new scope, then skip the name */
|
||||||
SymEnterLevel (&CurTok.SVal, ST_ENUM, ADDR_SIZE_ABS, 0);
|
SymEnterLevel (&CurTok.SVal, SCOPETYPE_ENUM, ADDR_SIZE_ABS, 0);
|
||||||
NextTok ();
|
NextTok ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
#include "cmdline.h"
|
#include "cmdline.h"
|
||||||
#include "mmodel.h"
|
#include "mmodel.h"
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
|
#include "scopedefs.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
#include "tgttrans.h"
|
#include "tgttrans.h"
|
||||||
@@ -868,7 +869,7 @@ int main (int argc, char* argv [])
|
|||||||
/* Enter the base lexical level. We must do that here, since we may
|
/* Enter the base lexical level. We must do that here, since we may
|
||||||
* define symbols using -D.
|
* define symbols using -D.
|
||||||
*/
|
*/
|
||||||
SymEnterLevel (&GlobalNameSpace, ST_GLOBAL, ADDR_SIZE_DEFAULT, 0);
|
SymEnterLevel (&GlobalNameSpace, SCOPETYPE_FILE, ADDR_SIZE_DEFAULT, 0);
|
||||||
|
|
||||||
/* Initialize the line infos. Must be done here, since we need line infos
|
/* Initialize the line infos. Must be done here, since we need line infos
|
||||||
* for symbol definitions.
|
* for symbol definitions.
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
#include "cddefs.h"
|
#include "cddefs.h"
|
||||||
#include "coll.h"
|
#include "coll.h"
|
||||||
#include "intstack.h"
|
#include "intstack.h"
|
||||||
|
#include "scopedefs.h"
|
||||||
#include "symdefs.h"
|
#include "symdefs.h"
|
||||||
#include "tgttrans.h"
|
#include "tgttrans.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
@@ -816,7 +817,7 @@ static void DoEnd (void)
|
|||||||
static void DoEndProc (void)
|
static void DoEndProc (void)
|
||||||
/* Leave a lexical level */
|
/* Leave a lexical level */
|
||||||
{
|
{
|
||||||
if (GetCurrentSymTabType () != ST_PROC) {
|
if (GetCurrentSymTabType () != SCOPETYPE_PROC) {
|
||||||
/* No local scope */
|
/* No local scope */
|
||||||
ErrorSkip ("No open .PROC");
|
ErrorSkip ("No open .PROC");
|
||||||
} else {
|
} else {
|
||||||
@@ -829,7 +830,7 @@ static void DoEndProc (void)
|
|||||||
static void DoEndScope (void)
|
static void DoEndScope (void)
|
||||||
/* Leave a lexical level */
|
/* Leave a lexical level */
|
||||||
{
|
{
|
||||||
if ( GetCurrentSymTabType () != ST_SCOPE) {
|
if ( GetCurrentSymTabType () != SCOPETYPE_SCOPE) {
|
||||||
/* No local scope */
|
/* No local scope */
|
||||||
ErrorSkip ("No open .SCOPE");
|
ErrorSkip ("No open .SCOPE");
|
||||||
} else {
|
} else {
|
||||||
@@ -1538,7 +1539,7 @@ static void DoProc (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Enter a new scope */
|
/* Enter a new scope */
|
||||||
SymEnterLevel (&Name, ST_PROC, AddrSize, Sym);
|
SymEnterLevel (&Name, SCOPETYPE_PROC, AddrSize, Sym);
|
||||||
|
|
||||||
/* Free memory for Name */
|
/* Free memory for Name */
|
||||||
SB_Done (&Name);
|
SB_Done (&Name);
|
||||||
@@ -1665,7 +1666,7 @@ static void DoScope (void)
|
|||||||
AddrSize = OptionalAddrSize ();
|
AddrSize = OptionalAddrSize ();
|
||||||
|
|
||||||
/* Enter the new scope */
|
/* Enter the new scope */
|
||||||
SymEnterLevel (&Name, ST_SCOPE, AddrSize, 0);
|
SymEnterLevel (&Name, SCOPETYPE_SCOPE, AddrSize, 0);
|
||||||
|
|
||||||
/* Free memory for Name */
|
/* Free memory for Name */
|
||||||
SB_Done (&Name);
|
SB_Done (&Name);
|
||||||
@@ -1759,7 +1760,7 @@ static void DoTag (void)
|
|||||||
ErrorSkip ("Unknown struct");
|
ErrorSkip ("Unknown struct");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (GetSymTabType (Struct) != ST_STRUCT) {
|
if (GetSymTabType (Struct) != SCOPETYPE_STRUCT) {
|
||||||
ErrorSkip ("Not a struct");
|
ErrorSkip ("Not a struct");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "addrsize.h"
|
#include "addrsize.h"
|
||||||
|
#include "scopedefs.h"
|
||||||
|
|
||||||
/* ca65 */
|
/* ca65 */
|
||||||
#include "condasm.h"
|
#include "condasm.h"
|
||||||
@@ -107,7 +108,7 @@ static long DoStructInternal (long Offs, unsigned Type)
|
|||||||
int Anon = (CurTok.Tok != TOK_IDENT);
|
int Anon = (CurTok.Tok != TOK_IDENT);
|
||||||
if (!Anon) {
|
if (!Anon) {
|
||||||
/* Enter a new scope, then skip the name */
|
/* Enter a new scope, then skip the name */
|
||||||
SymEnterLevel (&CurTok.SVal, ST_STRUCT, ADDR_SIZE_ABS, 0);
|
SymEnterLevel (&CurTok.SVal, SCOPETYPE_STRUCT, ADDR_SIZE_ABS, 0);
|
||||||
NextTok ();
|
NextTok ();
|
||||||
/* Start at zero offset in the new scope */
|
/* Start at zero offset in the new scope */
|
||||||
Offs = 0;
|
Offs = 0;
|
||||||
@@ -194,7 +195,7 @@ static long DoStructInternal (long Offs, unsigned Type)
|
|||||||
Struct = ParseScopedSymTable ();
|
Struct = ParseScopedSymTable ();
|
||||||
if (Struct == 0) {
|
if (Struct == 0) {
|
||||||
ErrorSkip ("Unknown struct/union");
|
ErrorSkip ("Unknown struct/union");
|
||||||
} else if (GetSymTabType (Struct) != ST_STRUCT) {
|
} else if (GetSymTabType (Struct) != SCOPETYPE_STRUCT) {
|
||||||
ErrorSkip ("Not a struct/union");
|
ErrorSkip ("Not a struct/union");
|
||||||
} else {
|
} else {
|
||||||
SymEntry* SizeSym = GetSizeOfScope (Struct);
|
SymEntry* SizeSym = GetSizeOfScope (Struct);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "hashstr.h"
|
#include "hashstr.h"
|
||||||
#include "mmodel.h"
|
#include "mmodel.h"
|
||||||
|
#include "scopedefs.h"
|
||||||
#include "symdefs.h"
|
#include "symdefs.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
@@ -117,7 +118,7 @@ static SymTable* NewSymTable (SymTable* Parent, const StrBuf* Name)
|
|||||||
S->SegRanges = AUTO_COLLECTION_INITIALIZER;
|
S->SegRanges = AUTO_COLLECTION_INITIALIZER;
|
||||||
S->Flags = ST_NONE;
|
S->Flags = ST_NONE;
|
||||||
S->AddrSize = ADDR_SIZE_DEFAULT;
|
S->AddrSize = ADDR_SIZE_DEFAULT;
|
||||||
S->Type = ST_UNDEF;
|
S->Type = SCOPETYPE_UNDEF;
|
||||||
S->Level = Level;
|
S->Level = Level;
|
||||||
S->TableSlots = Slots;
|
S->TableSlots = Slots;
|
||||||
S->TableEntries = 0;
|
S->TableEntries = 0;
|
||||||
@@ -223,7 +224,7 @@ void SymEnterLevel (const StrBuf* ScopeName, unsigned char Type,
|
|||||||
* does not allocate memory for useless data (unhandled types here don't
|
* does not allocate memory for useless data (unhandled types here don't
|
||||||
* occupy space in any segment).
|
* occupy space in any segment).
|
||||||
*/
|
*/
|
||||||
if (CurrentScope->Type <= ST_SCOPE_HAS_DATA) {
|
if (CurrentScope->Type <= SCOPETYPE_HAS_DATA) {
|
||||||
AddSegRanges (&CurrentScope->SegRanges);
|
AddSegRanges (&CurrentScope->SegRanges);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -913,7 +914,7 @@ void WriteScopes (void)
|
|||||||
while (S) {
|
while (S) {
|
||||||
|
|
||||||
/* Type must be defined */
|
/* Type must be defined */
|
||||||
CHECK (S->Type != ST_UNDEF);
|
CHECK (S->Type != SCOPETYPE_UNDEF);
|
||||||
|
|
||||||
/* Id of scope */
|
/* Id of scope */
|
||||||
ObjWriteVar (S->Id);
|
ObjWriteVar (S->Id);
|
||||||
|
|||||||
@@ -60,17 +60,6 @@
|
|||||||
#define ST_NONE 0x00 /* No flags */
|
#define ST_NONE 0x00 /* No flags */
|
||||||
#define ST_DEFINED 0x01 /* Scope has been defined */
|
#define ST_DEFINED 0x01 /* Scope has been defined */
|
||||||
|
|
||||||
/* Symbol table types */
|
|
||||||
enum {
|
|
||||||
ST_GLOBAL, /* Root level */
|
|
||||||
ST_PROC, /* .PROC */
|
|
||||||
ST_SCOPE, /* .SCOPE */
|
|
||||||
ST_SCOPE_HAS_DATA = ST_SCOPE, /* Last scope that contains data */
|
|
||||||
ST_STRUCT, /* .STRUCT/.UNION */
|
|
||||||
ST_ENUM, /* .ENUM */
|
|
||||||
ST_UNDEF = 0xFF
|
|
||||||
};
|
|
||||||
|
|
||||||
/* A symbol table */
|
/* A symbol table */
|
||||||
typedef struct SymTable SymTable;
|
typedef struct SymTable SymTable;
|
||||||
struct SymTable {
|
struct SymTable {
|
||||||
|
|||||||
66
src/common/scopedefs.h
Normal file
66
src/common/scopedefs.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* symdefs.h */
|
||||||
|
/* */
|
||||||
|
/* Scope definitions for the bin65 binary utils */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2011, Ullrich von Bassewitz */
|
||||||
|
/* Roemerstrasse 52 */
|
||||||
|
/* D-70794 Filderstadt */
|
||||||
|
/* EMail: uz@cc65.org */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SCOPEDEFS_H
|
||||||
|
#define SCOPEDEFS_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Scope types */
|
||||||
|
enum {
|
||||||
|
SCOPETYPE_GLOBAL, /* Global level */
|
||||||
|
SCOPETYPE_FILE, /* File level */
|
||||||
|
SCOPETYPE_PROC, /* .PROC */
|
||||||
|
SCOPETYPE_SCOPE, /* .SCOPE */
|
||||||
|
SCOPETYPE_HAS_DATA = SCOPETYPE_SCOPE, /* Last scope that contains data */
|
||||||
|
SCOPETYPE_STRUCT, /* .STRUCT/.UNION */
|
||||||
|
SCOPETYPE_ENUM, /* .ENUM */
|
||||||
|
SCOPETYPE_UNDEF = 0xFF
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of scopedefs.h */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user