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

Symbols


SgSymbol

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 {
public:
  // 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:


SgVariableSymb

Represents variable symbols, for all languages.

class SgVariableSymb: public SgSymbol {
  // a variable
  // variant = VARIABLE_NAME
public:
  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:


SgConstantSymb

Represents symbols for constants, for all languages.

class SgConstantSymb: public SgSymbol {
  // a symbol for a constant object
  // variant == CONST_NAME 
public:
  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:


SgFunctionSymb

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

class SgFunctionSymb: public SgSymbol {
  // a subroutine, function or main program
  // variant == PROGRAM_NAME, PROCEDURE_NAME, or FUNCTION_NAME
public:
  SgFunctionSymb(int variant);
  SgFunctionSymb(int variant, char *identifier, SgType &t, 
                 SgStatement &scope);
  ~SgFunctionSymb();
  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:


SgLabelSymb

Represents C label symbols.

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

Member Functions

SgLabelSymb(char *name)


SgTypeSymb

Represents the C typedef symbols.

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

Member Functions

SgTypeSymb(char *name, SgType &baseType)

SgType &baseType()


SgClassSymb

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

class SgClassSymb: public SgSymbol {
  // the class, union, struct and collection type.
  // variant == CLASS_NAME, UNION_NAME, STRUCT_NAME or COLLECTION_NAME
public:
  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.


SgFieldSymb

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
public:
  // 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:


SgMemberFuncSymb

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,
  // MEMP_METHOELEM or MEMB_PROTECTED
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:


SgLabelVarSymb

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
public:
  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:


SgExternalSymb

Represents Fortran symbols for external functions.

class SgExternalSymb: public SgSymbol {
  // for fortran external statement
  // variant == ROUTINE_NAME
public:
  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:


SgConstructSymb

Represents Fortran symbols for construct names.

class SgConstructSymb: public SgSymbol {
  // for fortran statement with construct names
  // variant == CONSTRUCT_NAME
public:
  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:


SgModuleSymb

Represents Fortran symbols for module statements.

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

Member Functions

SgModuleSymb(char *name)

Example Program

SgModuleSymb is used in the following example programs:


SgInterfaceSymb

Represents Fortran 90 symbols for module interface statements.

class SgInterfaceSymb: public SgSymbol {
  // for fortran interface statement
  // variant == INTERFACE_NAME
public:
  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