Introduction Projects and Files Statements Expressions Symbols Types
Attributes Labels Non-Member Functions Constructing Declarations Example Programs Index



SgSymbol is the base class for the classes representing symbols. As with the other classes there is a variant() which identifies the subclass and an integer identifier id() that is unique for each symbol. The symbols in each file are organized as a list which is accessible from the file object as SgFile::firstSymbol() and the following symbol to the current symbol is located with next(). Every symbol has a character string identifier(), a type(), which is described in detail below, and a statement called scope() that is the statement in which declaration is scoped. The scope is the control parent of the declaration statement.

In addition, there are functions that can be used to generate a copy of the symbol. There are three forms of the copy. The basic copy make a simple copy of the symbol table entry. The level one copy also generates new type information. The level two copy also copies the declaration body.

class SgSymbol {
  // basic class contains
  PTR_SYMB thesymb;
  SgSymbol(int variant, char *identifier, SgType &t, SgStatement &scope);
  SgSymbol(int variant, char *identifier, SgType *t, SgStatement *scope);
  SgSymbol(int variant, char *identifier,  SgStatement &scope);
  SgSymbol(int variant, char *identifier,  SgStatement *scope);
  SgSymbol(int variant, char *identifier,   SgType *type, SgStatement *scope, 
           SgSymbol *structsymb, SgSymbol *nextfield );

SgSymbol(int variant, char *name); SgSymbol(int variant); SgSymbol(PTR_SYMB symb); inline SgSymbol(SgSymbol &); ~SgSymbol(); inline int variant(); inline int id(); // unique identifier inline char *identifier(); // the text name for the symbol. inline SgType *type(); // the type of the symbol inline void setType(SgType &t); // the type of the symbol inline void setType(SgType *t); // the type of the symbol inline SgStatement *scope(); // the SgControlStatement where defined. inline SgSymbol *next(); // next symbol reference. SgStatement *declaredInStmt(); // the declaration statement inline SgSymbol &copy(); inline SgSymbol &copyLevel1(); // copy also parameters inline SgSymbol &copyLevel2(); // copy parameters, body also inline SgSymbol &copyAcrossFiles(SgStatement &where); // special copy to // move things from a file. int attributes(); // the Fortran 90 attributes void setAttribute(int attribute); void removeAttribute(int attribute); void declareTheSymbol(SgStatement &st); inline void declareTheSymbolWithParamList (SgStatement &st, SgExpression &parlist); SgExpression *makeDeclExpr(); inline SgExpression *makeDeclExprWithParamList (SgExpression &parlist); SgVarDeclStmt *makeVarDeclStmt(); SgVarDeclStmt *makeVarDeclStmtWithParamList (SgExpression &parlist); SgStatement *body(); // the body of the symbol if has one (like, function // call, class,...)

/////////////// FOR ATTRIBUTES //////////////////////////

int numberOfAttributes(); int numberOfAttributes(int type); // of a specified type; void *attributeValue(int i); int attributeType(int i); void *attributeValue(int i,int type); // only considering one type attribute void *deleteAttribute(int i); void addAttribute(int type, void *a, int size); // void * can be NULL; void addAttribute(int type); //void * is NULL; void addAttribute(void *a, int size); //no type specifed; void addAttribute(SgAttribute *att); SgAttribute *getAttribute(int i); SgAttribute *getAttribute(int i,int type); }

Member Functions

SgSymbol(int variant, char *identifier, SgType &t, SgStatement &scope)

SgSymbol(int variant, char *identifier, SgStatement &scope)

SgSymbol(int variant, char *name)

SgSymbol(int variant)

SgSymbol(PTR_SYMB symb)

int variant()

int id()

char *identifier()

SgType *type()

void setType(SgType &t)

SgStatement *scope()

SgSymbol *next()

SgStatement *declaredInStmt()

SgSymbol &copy()

SgSymbol &copyLevel1()

SgSymbol &copyLevel2()

int attributes()

void setAttribute(int attribute)

void removeAttribute(int attribute)

void declareTheSymbol(SgStatement &st)

void declareTheSymbolWithParamList(SgStatement &st)

SgExpression *makeDeclExpr()

SgExpression *makeDeclExprWithParamList(SgExpression &parlist)

SgVarDeclStmt *makeVarDeclStmt()

SgVarDeclStmt *makeVarDeclStmtWithParamList(SgExpression &parlist)

SgStatement *body()

SgSymbol Usage

As an example of how to traverse the symbol table, consider the problem of looking for a symbol table entry for a given member function in a given class. There are several ways to do this. The scheme shown below will search the table for the class by name. Then it searches the field list for the member function and returns the pointer to the symbol object if it is found.

As another example, consider the task of generating temporary variables that match the type and initial constructor parameters of a given variable symbol. More specifically, consider the declarations

Each of these statements is of class SgVarDeclStmt which has a type and an expression list. In the first case the expression list has two items (called values in SgExprListExp): x[100], y[34], and the second declaration has one item object(parm1, parm2). The following function creates a new temporary symbol with name _Ti where i is an integer counter and given a symbol table entry, finds the declaration of the symbol, and creates an identical declaration for the temporary.

Example Programs

SgSymbol is used in the following example programs:


Represents variable symbols, for all languages.

class SgVariableSymb: public SgSymbol {
  // a variable
  // variant = VARIABLE_NAME
  inline SgVariableSymb(char *identifier, SgType &t, SgStatement &scope);
  inline SgVariableSymb(char *identifier, SgType *t, SgStatement *scope);
  inline SgVariableSymb(char *identifier, SgType &t);
  inline SgVariableSymb(char *identifier,  SgStatement &scope);
  inline SgVariableSymb(char *identifier,  SgStatement *scope);
  inline SgVariableSymb(char *identifier);
  inline ~SgVariableSymb();

/* This function allocates and returns a new variable reference expression to this symbol. (ajm) */ inline SgVarRefExp *varRef (void); };

Member Functions

SgVariableSymb(char *identifier, SgType &t, SgStatement &scope)

SgVariableSymb(char *identifier, SgType &t)

SgVariableSymb(char *identifier, SgStatement &scope)

SgVariableSymb(char *identifier)

Example Programs

SgVariableSymb is used in the following example programs:


Represents symbols for constants, for all languages.

class SgConstantSymb: public SgSymbol {
  // a symbol for a constant object
  // variant == CONST_NAME 
  inline SgConstantSymb(char *identifier, SgStatement &scope, 
                 SgExpression &value);
  inline ~SgConstantSymb();
  inline SgExpression *constantValue();

Member Functions

SgConstantSymb(char *identifier, SgStatement &scope, SgExpression &value)

SgExpression *constantValue()

Example Programs

SgConstantSymb is used in the following example programs:


Represents symbols for subroutine, function, and main program, for all languages.

class SgFunctionSymb: public SgSymbol {
  // a subroutine, function or main program
  SgFunctionSymb(int variant);
  SgFunctionSymb(int variant, char *identifier, SgType &t, 
                 SgStatement &scope);
  inline void addParameter(SgSymbol ¶meters);
  void insertParameter(int position, SgSymbol &symb);
  int numberOfParameters();
  SgSymbol *parameter(int i); 
  SgSymbol *result();
  void  setResult(SgSymbol &symbol);

Member Functions

SgFunctionSymb(int variant)

SgFunctionSymb(int variant, char *identifier, SgType &t, SgStatement &scope)

void addParameter(int n, SgSymbol ¶meters)

void insertParameter(int position, SgSymbol &symb)

int numberOfParameters()

SgSymbol *parameter(int i)

SgSymbol *result()

void setResult(SgSymbol &symbol)

int isRecursive()

int setRecursive()

Example Programs

SgFunctionSymb is used in the following example programs:


Represents C label symbols.

class SgLabelSymb: public SgSymbol {
  // a C label name
  // variant == LABEL_NAME
  inline SgLabelSymb(char *name);
  inline SgLabelSymb(char *name, SgStatement &scope);
  inline ~SgLabelSymb();

Member Functions

SgLabelSymb(char *name)


Represents the C typedef symbols.

class SgTypeSymb: public SgSymbol {
  // a C typedef.  the type() function returns the base type.
  // variant == TYPE_NAME
  SgTypeSymb(char *name, SgType &baseType);
  SgType &baseType();

Member Functions

SgTypeSymb(char *name, SgType &baseType)

SgType &baseType()


Represents the C symbols for class, union, struct, and collection.

class SgClassSymb: public SgSymbol {
  // the class, union, struct and collection type.
  inline SgClassSymb(int variant, char *name, SgStatement &scope);
  inline ~SgClassSymb();
  inline int numberOfFields();
  inline SgSymbol *field(int i); //i=0,1,...

Member Functions

SgClassSymb(int variant, char *name, SgStatement &scope)

int numberOfFields()

SgSymbol *field(int i)

Further Notes

For a SgClassSymb that represents a class that has already been defined, type() returns a pointer to SgClassType (i.e., isSgClassType(symb->type()) should return a non-NULL SgClassType pointer). The class SgClassType contains the method SgStatement *structureDecl() that can be used to access the statement that contains the definition of the class.


Represents C symbols for fields in enums, symbols for fields in structs, and symbols for fields in classes.

class SgFieldSymb: public SgSymbol {
  // a field in an enum or in a struct.
  // variant == ENUM_NAME or FIELD_NAME
  // no check is made to see if the field "identifier"
  //   already exists in the structure. 
  inline SgFieldSymb(char *identifier, SgType &t, SgSymbol &structureName);
  inline ~SgFieldSymb();
  inline int offset();        // position in the structure
  inline SgSymbol *structureName();  // parent structure
  inline SgSymbol *nextField();
  inline int isMethodOfElement();

Member Functions

SgFieldSymb(char *identifier, SgType &t, SgSymbol &structureName)

int offset()

SgSymbol *structureName()

SgSymbol *nextField()

int isMethodOfElement()

int isPrivate()

int isSequence()

void setPrivate()

void setSequence()

Example Programs

SgFieldSymb is used in the following example programs:


Represents C symbols for members of structs and classes.

class SgMemberFuncSymb: public SgFunctionSymb {
  // a member function for a class or struct or collection
  // variant = MEMBER_FUNC
  // may be either MEMB_PRIVATE, MEMB_PUBLIC,
  inline SgMemberFuncSymb(char *identifier, SgType &t, SgStatement &cla,
                          int status);
  inline ~SgMemberFuncSymb();
  inline int isMethodOfElement();
  inline SgSymbol *className();
  inline void setClassName(SgSymbol &symb);

Member Functions

SgMemberFuncSymb(char *identifier, SgType &t, SgStatement &cla, int status)

int status()

int isVirtual()

int isMethodOfElement()

SgSymbol *className()

void setClassName(SgSymbol &symb)

Example Programs

SgMemberFuncSymb is used in the following example programs:


Represents Fortran symbols for label variables for assigned goto statements.

class SgLabelVarSymb: public SgSymbol {
  // a Fortran label variable for an assigned goto stmt
  // variant == LABEL_NAME
  inline SgLabelVarSymb(char *name, SgStatement &scope);
  inline ~SgLabelVarSymb();

Member Functions

SgLabelVarSymb(char *name, SgStatement &scope)

Example Programs

SgLabelVarSymb is used in the following example programs:


Represents Fortran symbols for external functions.

class SgExternalSymb: public SgSymbol {
  // for fortran external statement
  // variant == ROUTINE_NAME
  inline SgExternalSymb(char *name, SgStatement &scope);
  inline ~SgExternalSymb();

Member Functions

SgExternalSymb(char *name, SgStatement &scope)

Example Programs

SgExternalSymb is used in the following example programs:


Represents Fortran symbols for construct names.

class SgConstructSymb: public SgSymbol {
  // for fortran statement with construct names
  // variant == CONSTRUCT_NAME
  inline SgConstructSymb(char *name, SgStatement &scope);
  inline ~SgConstructSymb();

Member Functions

SgConstructSymb(char *name, SgStatement &scope)

Example Programs

SgConstructSymb is used in the following example programs:


Represents Fortran symbols for module statements.

class SgModuleSymb: public SgSymbol {
  // for fortran module statement
  // variant == MODULE_NAME
  inline SgModuleSymb(char *name);
  inline ~SgModuleSymb();

Member Functions

SgModuleSymb(char *name)

Example Program

SgModuleSymb is used in the following example programs:


Represents Fortran 90 symbols for module interface statements.

class SgInterfaceSymb: public SgSymbol {
  // for fortran interface statement
  // variant == INTERFACE_NAME
  inline SgInterfaceSymb(char *name, SgStatement &scope);
  inline ~SgInterfaceSymb();

Member Functions

SgInterfaceSymb(char *name, SgStatement &scope)

Example Programs

SgInterfaceSymb is used in the following example programs:

Exit Sage++ User's Guide