Auxiliary Classes for Sage++2.0

Class SgName

Base class for any name (variable, symbol, type , function name etc.)

Data Members:

private: char * p_char;

Function Members:

public: /* constructors */ SgName(); SgName(const char * str); SgName(const SgName& n); SgName(const char *str, int n); // get first n chars in the string ~SgName(); //destructor /* class operators */ int operator!=(const SgName& n1) const; int operator==(const SgName& n1) const; int operator<(const SgName& n1) const; SgName& operator<<(const char* str);//concatenation static SgName itoname(int val); SgName& operator<<(int val); SgName& operator=(const SgName& n1); SgName& tail(int n); // keep string after n SgName& head(int n); // keep first n chars int is_null(void) const; // replaces a space inside string p_char by char t void replace_space(char t); const char* str() const { return p_char;} operator char*() { return p_char; } };

Class SgInitializedName

For all initialized names, function arguments, etc.

Data Members:

private: SgName p_name; SgType *p_typeptr; union { SgInitializer *p_initptr; SgInitializedName *p_prev_itemptr; }; short p_is_initializer; SgDeclarationStatement *p_declptr; // var decl pt to defn item, var defn pt to decl item SgInitializedName *p_itemptr; friend class Sg_Copy_Info; /* does cloning of a tree */

Function Members:

public: /* constructors */ SgInitializedName() : p_typeptr(0), p_initptr(0), p_declptr(0), p_itemptr(0), p_prev_itemptr(0), p_is_initializer(1) {} SgInitializedName(const SgName& name, SgType *typeptr, SgInitializer* iptr=0, SgDeclarationStatement *declptr=0 , SgInitializedName *itemptr=0, SgInitializedName *prev_itemptr=0 ) : p_name(name), p_typeptr(typeptr), p_initptr(iptr),p_declptr(declptr), p_itemptr(itemptr), p_is_initializer(1) { if(prev_itemptr) set_prev_decl_item(prev_itemptr); } SgInitializedName(const SgInitializedName& ptr); /* destructor */ ~SgInitializedName() { /*delete p_ptr;*/ } /* operators */ SgInitializedName& operator= (const SgInitializedName& ptr); inline bool operator== (const SgInitializedName& ) const; inline bool operator< (const SgInitializedName&) const; SgName get_name() const { return p_name; } SgType *get_type() const { return p_typeptr; } void set_type(SgType *t) { p_typeptr=t; } SgInitializer *get_initializer() const; void set_initializer(SgInitializer* i); SgDeclarationStatement *get_declaration() const; void set_declaration(SgDeclarationStatement * decl); SgInitializedName *get_prev_decl_item() const; void set_prev_decl_item(SgInitializedName * item); SgInitializedName *get_named_item() const { return p_itemptr; } void set_named_item(SgInitializedName * item) { p_itemptr=item; } };

Class SgBaseClass

A generic class for all inheritances. (See SgClassDefinition)

Data Members:

private: int p_specifier; int p_direct; SgClassDeclaration* p_ptr; friend class Sg_Copy_Info; public: typedef SgDeclarationStatement::decl_specifier_enum;

Function Members:

public: /* constructors */ SgBaseClass(int specifier=0,SgClassDeclaration* ptr = 0, int dir = 0) : p_specifier(specifier), p_ptr(ptr), p_direct(dir) { } SgBaseClass(const SgBaseClass& ptr); /* destructor */ ~SgBaseClass() { /*delete p_ptr;*/ } int get_base_specifier() const; SgClassDeclaration* get_base_class() const; SgClassDeclaration* replace_base_class(SgClassDeclaration *); /* operators */ SgBaseClass& operator= (const SgBaseClass& ptr); inline bool operator== (const SgBaseClass& ) const { return false; } inline bool operator< (const SgBaseClass&) const { return false; } };

Class SgSymbolTable

Manages symbol/type tables.
(See SgScopeStatement and SgFunctionTypeTable )

Data Members:

private: SgSymbolHashBase::iterator p_iterator; SgName p_name; bool p_no_name; SgSymbolHashMultiMap * p_table;

Function Members:

public: /* constructors */ SgSymbolTable() : p_no_name(1) { p_table = 0; } SgSymbolTable(int sz); /* destructor */ inline ~SgSymbolTable(); void insert(const SgName &, SgSymbol *sp); int find(const SgName &, SgSymbol *sp); SgVariableSymbol * findfirstvar(); SgClassSymbol * findfirstclass(); SgFunctionSymbol * findfirstfunction(); SgSymbol * findfirstany(); SgSymbol * findany(const SgName &); SgSymbol * nextany(); SgVariableSymbol * findvar(const SgName &); SgVariableSymbol * nextvar(); SgClassSymbol * findclass(const SgName &); SgClassSymbol * nextclass(); SgTypedefSymbol * findtypedef(const SgName &); SgEnumSymbol * findenum(const SgName &); SgEnumFieldSymbol * findenumfield(const SgName &); // for both global function and member functions SgFunctionSymbol * findfunc(const SgName&, const SgType*); SgFunctionSymbol * findfunc(const SgName&); SgFunctionSymbol * nextfunc(); SgFunctionTypeSymbol * findfunctype(const SgName&) const; // for func type table SgLabelSymbol * findlabel(const SgName &) const; SgSymbol * operator[](const SgName &); int count(const SgName &nm); void print(ostream&); void print(); // size of the table int size() const; };

Class SgStatementPtr

Handles a pointer to an SgStatement object.

Data Members

private: SgStatement* p_ptr;

Function Members:

public: /* constructors */ SgStatementPtr(SgStatement* ptr = 0) : p_ptr(ptr) { } SgStatementPtr(const SgStatementPtr& ptr); /* destructor */ ~SgStatementPtr() { /*delete p_ptr;*/ } /* operators */ SgStatement* operator->() { return p_ptr; } const SgStatement* operator->() const { return p_ptr; } SgStatementPtr& operator= (const SgStatementPtr& ptr); SgStatementPtr& operator= (SgStatement *ptr); inline bool operator== (const SgStatementPtr& p) const; inline bool operator< (const SgStatementPtr&) const; SgStatement* irep(void) const { return p_ptr; } SgStatement* replace(SgStatement *); };

Class SgDeclarationStatementPtr

Manipulating functions for pointers to SgDeclarationStatement objects.

Data Members

private: SgDeclarationStatement* p_ptr;

Function Members:

public: /* constructors */ SgDeclarationStatementPtr(SgDeclarationStatement* ptr = 0) : p_ptr(ptr) { } SgDeclarationStatementPtr(const SgDeclarationStatementPtr& ptr); /* destructor */ ~SgDeclarationStatementPtr() { /*delete p_ptr;*/ } /* operators */ SgDeclarationStatement* operator->() { return p_ptr; } const SgDeclarationStatement* operator->() const { return p_ptr; } SgDeclarationStatementPtr& operator= (const SgDeclarationStatementPtr& ptr); SgDeclarationStatementPtr& operator= (SgDeclarationStatement* ptr); inline bool operator== (const SgDeclarationStatementPtr& p) const; inline bool operator< (const SgDeclarationStatementPtr&) const; SgDeclarationStatement* irep(void) const { return p_ptr; } SgDeclarationStatement* replace(SgDeclarationStatement *); };

Class SgTypePtr

Handles a pointer to an SgType object.

Data Members

private: SgType* p_ptr;

Function Members:

public: /* constructors */ SgTypePtr(SgType* ptr = 0) : p_ptr(ptr) { } SgTypePtr(const SgTypePtr& ptr); /* destructor */ ~SgTypePtr() { /*delete p_ptr;*/ } SgType* operator->() { return p_ptr; } const SgType* operator->() const { return p_ptr; } SgType* irep() const { return p_ptr; } SgType* replace(SgType *); SgTypePtr& operator= (const SgTypePtr& ptr); inline bool operator== (const SgTypePtr& p) const; inline bool operator< (const SgTypePtr&) const; };

Class SgExpressionPtr

Handles a pointer to an SgExpression object.

Data Members

private: SgExpression* p_ptr;

Function Members:

public: /* constructors */ SgExpressionPtr(SgExpression* ptr = 0) : p_ptr(ptr) { } SgExpressionPtr(const SgExpressionPtr& ptr) { p_ptr = ptr.p_ptr; /* p_ptr = ptr() ? ptr()->clone() : 0 */; } /* destructor */ ~SgExpressionPtr() { /*delete p_ptr;*/ } /* operators */ SgExpression* operator->() { return p_ptr; } const SgExpression* operator->() const { return p_ptr; } SgExpressionPtr& operator= (const SgExpressionPtr& ptr); SgExpressionPtr& operator= (SgExpression* ptr); inline bool operator== (const SgExpressionPtr& p) const { return (p_ptr == p.p_ptr); } inline bool operator< (const SgExpressionPtr&) const { return false; } SgExpression* irep() const { return p_ptr; } SgExpression* replace(SgExpression *); };

Class SgAttribute

The abstract base class from which all attribute classes including user attributes and also pragma attributes should be derived from.

Data Members

private: char *p_name; // attribute name or pragma name

Function Members:

public: /* constructors */ SgAttribute(); SgAttribute(char *str); /* destructor */ ~SgAttribute() { if(p_name) delete [] p_name; } int isSame(char *str); virtual int isPragma() const =0; char *get_name() const { return p_name; } };

Class SgPragma

For base class see SgAttribute.

Data Members

private: short printed;

Function Members:

public: /* constructors */ SgPragma(char *name) : SgAttribute(name), printed(0) {}; char *get_pragma() const { return get_name(); } int samePragma(char *str) { return (strcmp(get_name(),str)==0); } int isPragma() const { return 1; } int gotPrinted() const { return printed; } void setPrinted(int s=1) { printed=s; } };

Class SgBitAttribute

For base class see SgAttribute.

Data Members

private: unsigned long int p_bitflag;

Function Members:

public: /* constructors */ SgBitAttribute(char *str): SgAttribute(str), p_bitflag(0) {} int isAttributeSet(unsigned long int bit) const { return (p_bitflag & bit); } void setAttribute(unsigned long int bit) { p_bitflag |=bit; } void unsetAttribute(unsigned long int bit) { p_bitflag &= ~bit; } int isPragma() const { return 0; } };

Class FuncDecl_attr

For base class see SgBitAttribute. Attribute class for SgFunctionDeclaration sage node.

/* attribute class */
/* to suppress the printing of atomic keyword */

Data Members

private: enum { e_suppressatomic = 0x00000001 };

Function Members:

public: FuncDecl_attr() : SgBitAttribute("FuncDecl_attr") {} void set_suppress_atomic() { setAttribute(e_suppressatomic); } int get_suppress_atomic() const { return isAttributeSet(e_suppressatomic); } };

Class ClassDecl_attr

For base class see SgBitAttribute. Attribute class for SgClassDeclaration sage node.
/* local attribute class */
/* to suppress the printing of global keyword */

Data Members

private: enum { e_suppress_global = 0x00000001 };

Function Members:

public: ClassDecl_attr() : SgBitAttribute("ClassDecl_attr") {} void set_suppress_global() { setAttribute(e_suppress_global); } int get_suppress_global() const { return isAttributeSet(e_suppress_global); } };

Class SgAttributePtr

For keeping a list of user attributes/pragma first is always a system bitmap attributes and the 2nd and so on are either pragma or user attributes.

Data Members

private: SgAttribute* p_ptr;

Function Members:

public: /* constructors */ SgAttributePtr(SgAttribute *ptr=0): p_ptr(ptr) {} SgAttributePtr(const SgAttributePtr& ptr); /* destructor*/ ~SgAttributePtr() { /* delete p_ptr; */} /* operators */ SgAttributePtr& operator= (const SgAttributePtr& ptr); SgAttribute* irep(void) const { return p_ptr; } SgAttribute* replace(SgAttribute *); int isPragma() const; int isSame(char *str) const; inline bool operator== (const SgAttributePtr& p) const { return (p_ptr == p.p_ptr); } inline bool operator< (const SgAttributePtr&) const { return false; } };

Class SgModifierNodes

Data Members

private: SgModifierType* nodes[4]; SgModifierNodes* next;

Function Members:

public: /* constructors */ SgModifierNodes(){ nodes[0] = nodes[1] = nodes[2] = nodes[3] = (SgModifierType*)0L; next = (SgModifierNodes*)0L; } /* destructor */ ~SgModifierNodes(){ delete next; } SgModifierType* match(SgType*, unsigned int); };

Class Unparse_Info

Holds the information needed for the unparsing phase.

Private Members

// space for unparse_type_num tag unsigned int unparse_attribute; // space for access_attr_enum tag int access_attribute; int nested_expression; // for those complicated statemenet unparser that has a special // unparser helper SgNode* unparse_helper; // for carrying along the variable name when printing out function/array // type with the symbol's name const char * operator_name; SgName var_name; // keep ptr to the declaration statement SgDeclarationStatement *declstatement_ptr; // keep current scope's type, set in SgClassDefinition's unparser SgNamedType *current_context; // keep track of previous array type's index string -- this is because // array is built like this A[2][3] Array(Array(A,3),2) SgName array_index_list; int checkBit(unsigned int bit) const { if(unparse_attribute & bit) return 1; else return 0; } void setBit(unsigned int bit) { unparse_attribute |= bit; } void unsetBit(unsigned int bit) { unparse_attribute &= ~bit; }

Pulic Members

enum unparse_type_num { // to postponing the printing of name for ptr of function or array etc b_isPointerToSomething = 0x00000001, b_isReferenceToSomething = 0x00000002, // if it is in Variable Declaration, output either , or ; for SgExprStmt b_inVarDecl = 0x00000004, // in a function header, output type+ symbol b_inArgList = 0x00000008, // no ';' for declaration statement b_SkipSemiColon = 0x00000010, // to setup for printing of enum var in a VariableDeclaration b_inEnumDecl = 0x00000020, // not really being used b_inTemplateList = 0x00000040, // suppress printing of the base type b_SkipBaseType = 0x00000080, // for skip "=" if in aggregate initializer b_inAggregateInitializer = 0x00000100, // for print both type & sym name b_isWithType = 0x00000200, // it is in conditional expr b_inConditional = 0x00000400, // skip printing definition part of a declaration b_SkipDefinition = 0x00000800, // need to put in either class/struct/union keyword b_SkipClassSpecifier = 0x00001000, // printing something within a variable declaration b_inEmbeddedDecl = 0x00002000, // suppress the printing of global and atomic b_SkipGlobal = 0x00004000, b_SkipAtomic = 0x00008000, // used by set/unsetName and set/unsetPrintName to bring down the // Name to lower tree structure b_PrintName = 0x00010000, // to set the need to check if need access specifier b_CheckAccess = 0x00020000, // to skip function qualifiers b_SkipFunctionQualifier = 0x00040000, // to show that the type above current one is an array b_isArrayType = 0x00080000, // to indicate that this is at the right hand side of a // binary op b_inRhsExpr = 0x00100000 }; enum access_attr_enum { a_unset_access = 1, a_private_access = 2, a_protected_access = 3, a_public_access = 4 }; /* constructor */ Unparse_Info() { unparse_attribute=0; access_attribute=a_unset_access; nested_expression =0; operator_name =0; var_name=0; unparse_helper=0; declstatement_ptr=0; current_context=0; array_index_list=0; }
/* accessor functions */
// access function to Unparse_Info int get_access_attribute() const { return access_attribute; } void set_access_attribute(int a) { access_attribute=a; } int isUnsetAccess() const { return access_attribute == a_unset_access; } void set_isUnsetAccess() { access_attribute = a_unset_access; } int isPrivateAccess() const { return access_attribute == a_private_access; } void set_isPrivateAccess() { access_attribute = a_private_access; } int isProtectedAccess() const { return access_attribute == a_protected_access; } void set_isProtectedAccess() { access_attribute = a_protected_access; } int isPublicAccess() const { return access_attribute == a_public_access; } void set_isPublicAccess() { access_attribute = a_public_access; } int isPointerToSomething() const { return checkBit(b_isPointerToSomething); } void set_isPointerToSomething() { setBit(b_isPointerToSomething); } void unset_isPointerToSomething() { unsetBit(b_isPointerToSomething); } int isReferenceToSomething() const { return checkBit(b_isReferenceToSomething); } void set_isReferenceToSomething() { setBit(b_isReferenceToSomething); } void unset_isReferenceToSomething() { unsetBit(b_isReferenceToSomething); } int inVarDecl() const { return checkBit(b_inVarDecl); } void set_inVarDecl() { setBit(b_inVarDecl); } void unset_inVarDecl() { unsetBit(b_inVarDecl); } int inArgList() const { return checkBit(b_inArgList); } void set_inArgList() { setBit(b_inArgList); } void unset_inArgList() { unsetBit(b_inArgList); } int SkipSemiColon() const { return checkBit(b_SkipSemiColon); } void set_SkipSemiColon() { setBit(b_SkipSemiColon); } void unset_SkipSemiColon() { unsetBit(b_SkipSemiColon); } int inEnumDecl() const { return checkBit(b_inEnumDecl); } void set_inEnumDecl() { setBit(b_inEnumDecl); } void unset_inEnumDecl() { unsetBit(b_inEnumDecl); } int inTemplateList() const { return checkBit(b_inTemplateList); } void set_inTemplateList() { setBit(b_inTemplateList); } void unset_inTemplateList() { unsetBit(b_inTemplateList); } int SkipBaseType() const { return checkBit(b_SkipBaseType); } void set_SkipBaseType() { setBit(b_SkipBaseType); } void unset_SkipBaseType() { unsetBit(b_SkipBaseType); } int inAggregateInitializer() const { return checkBit(b_inAggregateInitializer); } void set_inAggregateInitializer() { setBit(b_inAggregateInitializer); } void unset_inAggregateInitializer() { unsetBit(b_inAggregateInitializer); } int isWithType() const { return checkBit(b_isWithType); } void set_isWithType() { setBit(b_isWithType); } void unset_isWithType() { unsetBit(b_isWithType); } int inConditional() const { return checkBit(b_inConditional); } void set_inConditional() { setBit(b_inConditional); } void unset_inConditional() { unsetBit(b_inConditional); } int SkipDefinition() const { return checkBit(b_SkipDefinition); } void set_SkipDefinition() { setBit(b_SkipDefinition); } void unset_SkipDefinition() { unsetBit(b_SkipDefinition); } int SkipClassSpecifier() const { return checkBit(b_SkipClassSpecifier); } void set_SkipClassSpecifier() { setBit(b_SkipClassSpecifier); } void unset_SkipClassSpecifier() { unsetBit(b_SkipClassSpecifier); } int inEmbeddedDecl() const { return checkBit(b_inEmbeddedDecl); } void set_inEmbeddedDecl() { setBit(b_inEmbeddedDecl); } void unset_inEmbeddedDecl() { unsetBit(b_inEmbeddedDecl); } int SkipGlobal() const { return checkBit(b_SkipGlobal); } void set_SkipGlobal() { setBit(b_SkipGlobal); } void unset_SkipGlobal() { unsetBit(b_SkipGlobal); } int SkipAtomic() const { return checkBit(b_SkipAtomic); } void set_SkipAtomic() { setBit(b_SkipAtomic); } void unset_SkipAtomic() { unsetBit(b_SkipAtomic); } int PrintName() const { return checkBit(b_PrintName); } void set_PrintName() { if(!var_name.is_null()) setBit(b_PrintName); } void unset_PrintName() { unsetBit(b_PrintName); } int CheckAccess() const { return checkBit(b_CheckAccess); } void set_CheckAccess() { setBit(b_CheckAccess); } void unset_CheckAccess() { unsetBit(b_CheckAccess); } int SkipFunctionQualifier() const { return checkBit(b_SkipFunctionQualifier); } void set_SkipFunctionQualifier() { setBit(b_SkipFunctionQualifier); } void unset_SkipFunctionQualifier() { unsetBit(b_SkipFunctionQualifier); } int isArrayType() const { return checkBit(b_isArrayType); } void set_isArrayType() { setBit(b_isArrayType); } void unset_isArrayType() { unsetBit(b_isArrayType); } int inRhsExpr() const { return checkBit(b_inRhsExpr); } void set_inRhsExpr() { setBit(b_inRhsExpr); } void unset_inRhsExpr() { unsetBit(b_inRhsExpr); } const char * get_operator_name() { return operator_name; } void set_operator_name(const char * on) { operator_name = on; } SgName& get_name() { return var_name; } void set_name(SgName& name ) { var_name = name; set_PrintName(); } void unset_name() { unset_PrintName(); var_name=0; } SgDeclarationStatement* get_decl_stmt() { return declstatement_ptr; } void set_decl_stmt(SgDeclarationStatement* stmt ) { declstatement_ptr = stmt; } void unset_decl_stmt() { declstatement_ptr=0; } int get_nested_expression() { return nested_expression; } void set_nested_expression() { nested_expression++; } void unset_nested_expression() { nested_expression--; } SgNode* get_unparse_helper() { return unparse_helper; } void set_unparse_helper(SgNode* fd) { unparse_helper=fd; } void unset_unparse_helper() { unparse_helper=0; } SgNamedType *get_current_context() { return current_context; } void set_current_context(SgNamedType *t) { current_context=t; } void unset_currrent_context() { current_context=0; } SgName get_array_index_list() { return array_index_list; } void set_array_index_list(SgExpression *e, Unparse_Info finfo ) { array_index_list << "["; ostrstream buffer; if(e) e->unparse(finfo,buffer); buffer << ends; array_index_list << buffer.str() << "]"; } void unset_array_index_list() { array_index_list=0; } };

Class Sg_Copy_Info

Holds information that is passed around during the copying of a tree. For now, MAX_COPY_STORE defines the size of the tree that may be copied. Should be replaced by lists that can expand arbirarily. #define MAX_COPY_STORE 1000

Private Members

private: class SgNodePair { public: SgNodePair() :p_original(0), p_copy(0){} SgNodePair(SgNode* original, SgNode* copy) :p_original(original), p_copy(copy){} const SgNode* p_original; SgNode* p_copy; }; SgNodePair p_store[MAX_COPY_STORE]; /* this holds the pointers */ int p_num_stored;

Public Mambers

public: Sg_Copy_Info(); /* * to_be_copied(SgNode* node) * takes a pointer to a node from the source tree, * if the node has already been copied it returns a pointer to the copy * if the node does not need to be copied (because it is outside the * tree to be copied (for example a definition, or builtin type) * it returns a pointer to itself * otherwise it creates a copy and returns it. */ SgNode* copy_sage_type(const SgNode* node); /* * insert pair is used to add an association between an original node * and a copy */ void insert_pair(const SgNode* original, SgNode* copy); /* * look_for_copy * returns cpy of the original node if such has been made, * otherwise returns zero */ SgNode* look_for_copy(const SgNode* original); Sg_File_Info* copy_file_info(Sg_File_Info* file_info); /* * copy is defined for all the other, non-sage types, and chosen using * overloading */ void copy(SgName& target, const SgName& source); void copy(SgInitializedNameList& target,const SgInitializedNameList& source); void copy(SgSymbolTable& target, const SgSymbolTable& source); void copy(SgDeclarationStatementPtrList& target, const SgDeclarationStatementPtrList& source); void copy(SgBaseClassList& target, const SgBaseClassList& source); void copy(SgTypePtrList& target, const SgTypePtrList& source); void copy(SgExpressionPtrList& target, const SgExpressionPtrList& source); void copy(SgInitializedName& target, const SgInitializedName& source); void copy(SgInitializedName* target, const SgInitializedName* source); void copy(SgUnaryOp::op_mode& target, const SgUnaryOp::op_mode& source); void copy(SgCastExp::e_cast_type& target, const SgCastExp::e_cast_type& source); void copy(SgStatementPtrList& target, const SgStatementPtrList& source); void copy(SgBaseClass& target, const SgBaseClass& source); void copy(SgDeclarationStatementPtr& target, const SgDeclarationStatementPtr& source); void copy(SgTypePtr& target, const SgTypePtr& source); void copy(SgExpressionPtr& target, const SgExpressionPtr& source); void copy(SgStatementPtr& target, const SgStatementPtr& source); /* * copys for builtins */ void copy(unsigned int& target, const unsigned int& source) {target=source;} void copy(char* target, const char* source); { if (target != source){ delete target; target=new char[::strlen(source) +1]; strcpy(target,source); } } void copy(int& target, const int& source) {target=source;} void copy(unsigned long& target, const unsigned long& source) {target=source;} void copy(long& target, const long& source) {target=source;} void copy(long long& target, const long long& source) {target=source;} void copy(unsigned long long& target, const unsigned long long& source) {target=source;} void copy(unsigned short& target, const unsigned short& source) {target=source;} void copy(short& target, const short& source) {target=source;} void copy(char& target, const char& source) {target=source;} void copy(wchar_t& target, const wchar_t& source) {target=source;} void copy(unsigned char& target, const unsigned char& source) {target=source;} void copy(float& target, const float& source) {target=source;} void copy(double& target, const double& source) {target=source;} void copy(long double& target, const long double& source) {target=source;} };

Class Sg_File_Info

Class that represents and manipulates file information. (ex file names, line numbers, pragmas, column positions, etc. ).
#define NULL_FILE ((Sg_File_Info*) 0)

Private Members

private: char* p_filename; int p_line; int p_col; static int cur_line; static char* cur_file;

Public Members

public: void register_node(SgLocatedNode* node){} /* register interest */ void deregister_node(SgLocatedNode* node){} Sg_File_Info(); Sg_File_Info(const char* filename, int line, int col); void set_line(int line) { p_line = line; } void set_filename(char* filename) { p_filename = filename; } void output(ostream& os); char* get_filename() { return p_filename; } int get_line() { return p_line; } int get_col() { return p_col; } };

Class Sg_Print_Info

Deals with keeping track of information during a recursive print of a sage tree.

Private Members

private: const SgNode *p_store[MAX_STORE]; /* this holds the pointers */ int p_num_stored; int p_max_depth; Sg_Print_Info(); /* these will be a singleton, globally visible */ ostream *p_stream; friend Sg_Print_Info& sg_print_info();/* accessor to the single instance*/

Public Members

public: void reset(ostream* os, int max_depth);/* sets everything up for new print*/ ostream& stream() {return *p_stream;} bool already_printed(const SgNode *node, int& new_number); /* * output_class returns a bool indicating whether the subfields need to * be output. */ bool output_class(const SgNode *node, const char* name, int depth); bool output_class(const SgGlobal *node, const char* name, int depth); bool output_class(const SgBasicBlock *node, const char* name, int depth); bool output_class(const SgVariableDeclaration *node, const char* name, int depth); bool output_class(const SgClassDefinition *node, const char* name, int depth); bool output_class(const SgEnumDeclaration *node, const char* name, int depth); bool output_class(const SgFunctionType *node, const char* name, int depth); bool output_class(const SgMemberFunctionType *node, const char* name, int depth); void output_parent(int variant, int depth); void output_field(const SgNode *node, const char* name, int depth); void output_field(const SgName& id, const char* name, int depth); void output_field(const SgName* id, const char* name, int depth); void output_field(const SgInitializedName * id, const char* name, int depth); void output_field(const SgInitializedName&, const char* name, int depth); void output_field(const SgBaseClass * id, const char* name, int depth); void output_field(const char* id, const char* name, int depth); void output_field(SgIter&, const char* name, int depth); void output_field(const SgStatementPtrList&, const char* name, int depth); void output_field(const SgDeclarationStatementPtrList&, const char* name, int depth); void output_field(const SgInitializedNameList&, const char* name, int depth); void output_field(const SgTypePtrList&, const char* name, int depth); void output_field(const SgExpressionPtrList&, const char* name, int depth); void output_field(const SgBaseClassList&, const char* name, int depth); void output_field(unsigned int val, const char* name, int depth); void output_field(unsigned long val, const char* name, int depth); void output_field(int val, const char* name, int depth); void output_field(long val, const char* name, int depth); void output_field(long long val, const char* name, int depth); void output_field(unsigned long long val, const char* name, int depth); void output_field(char val, const char* name, int depth); void output_field(float val, const char* name, int depth); void output_field(double val, const char* name, int depth); void output_field(long double val, const char* name, int depth); void output_field(Sg_File_Info* file_info, int depth); void output_field(const SgSymbolTable& st, const char* name, int depth); // XXX MEI, This is a dummy stub to make it link void output_field(SgType **val, const char* name, int depth); int max_depth() const {return p_max_depth;} void tabs(int tab); };

Class SgFile

Basic global information about a file.

Private Members

private: SgGlobal p_root;

Public Members

public: SgFile() {}; void unparsestdout(); void unparse(ostream&); SgGlobal & root() { return p_root;}

Class SgProject

Basic global information about the files that are part of the project.

Private Members

private: SgFile* p_file;

Public Members

public: SgProject(); int numberOfFiles() { return 1; } SgFile& file(int i) { assert(i==0); return *p_file; }

Class Sg_Options

Basic utilities.

Private Members

private: Sg_Options(); /* to stop anyone but sg_options() instantiating it */ ostream* p_default_output; ostream* p_debug_output; ostream* p_error_output; ostream* p_logging_output; int p_debug_level; int p_logging_level; friend Sg_Options& sg_options();

Public Members

public: inline ostream& default_output() { return *p_default_output;} inline void set_default_output(ostream& os){ p_default_output = &os;} inline ostream& debug_output() { return *p_debug_output;} inline void set_debug_output(ostream& os) { p_debug_output = &os;} inline ostream& error_output() { return *p_error_output;} inline void set_error_output(ostream& os) { p_error_output = &os;} inline ostream& logging_output() { return *p_logging_output;} inline void set_logging_output(ostream& os){ p_logging_output = &os;} inline int debug_level() {return p_debug_level;} inline void set_debug_level(int l) { p_debug_level = l; } inline int logging_level() {return p_logging_level;} inline void set_logging(ostream& log_file, int level) {p_logging_level = level; p_logging_output = &log_file;} };

Class Sg_Tree_Traverser

Deals with applying a function to all elements of a sage tree from a given root. To use, derive a class from Sg_Tree_Traverser, overriding the user_visit function to deal with the aspects of interest, and then call node->traverse_tree(traverser) for the root of the tree in question.
#define MAX_TREE_SIZE 1000

Private Members

private: int p_num_visited; SgNode* p_already_visited[MAX_TREE_SIZE];

Public Members

public: Sg_Tree_Traverser():p_num_visited(0){} virtual void visit(SgNode* node); /* * user_visit is the function that would be overridden * by the user for a particular traverser */ bool already_visited(SgNode* node); virtual void user_visit(SgNode* node) = 0; /* * these next functions deal with list types etc, where visiting * will probably not be overridden */ virtual void visit(SgDeclarationStatementPtrList& item); virtual void visit(SgStatementPtrList& item); virtual void visit(const SgStatementPtr &item); virtual void visit(const SgDeclarationStatementPtr &item); /* * the base class list is not visited by default */ virtual void visit(SgBaseClassList& item) {}; /* * none of the following have any default action */ virtual void visit(SgInitializedNameList& item) {}; virtual void visit(SgSymbolTable& symbol_table) {}; virtual void visit(SgUnaryOp::op_mode& item) {}; virtual void visit(SgCastExp::e_cast_type& item) {}; virtual void visit(SgName& item) {}; virtual void visit(SgTypePtrList& item) {}; virtual void visit(SgExpressionPtrList& item) {}; virtual void visit(SgInitializedName* item) {}; virtual void visit(SgInitializedName& item) {}; /* * the builtin types are basically ignored by default */ virtual void visit(unsigned int& item){} virtual void visit(char* item) {} virtual void visit(int& item) {} virtual void visit(unsigned long& item) {} virtual void visit(long& item) {} virtual void visit(long long& item) {} virtual void visit(unsigned long long& item) {} virtual void visit(unsigned short& item) {} virtual void visit(short& item) {} virtual void visit(char& item) {} virtual void visit(wchar_t& item) {} virtual void visit(unsigned char& item) {} virtual void visit(float& item) {} virtual void visit(double& item) {} virtual void visit(long double& item) {} };

Class SgGenericList

A genric class that implements methods to manage a list of objects, instances of the same class. The list classes are built upon classes defined in the Sage++2.0 hierarchy. (SgStatementPtr, SgBasicClass etc.)

class SgGenericList

{ protected: typedef allocator_void::pointer void_pointer; struct list_node; class allocator_list_node; friend list_node; friend allocator_list_node; friend inline SgGeneric * allocate(ptrdiff_t, SgGeneric *); friend inline void deallocate(SgGeneric *); friend inline list_node * allocate(ptrdiff_t, list_node *); friend inline void deallocate(list_node *); friend inline void swap(list_node *&, list_node *&); struct list_node { void_pointer next; void_pointer prev; SgGeneric data; };

class allocator

{ public: typedef SgGeneric value_type; typedef SgGeneric* pointer; typedef const SgGeneric* const_pointer; typedef SgGeneric& reference; typedef const SgGeneric& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; pointer allocate(size_type n) { return ::allocate((difference_type)n, (pointer)0); } void deallocate(pointer p) { ::deallocate(p); } pointer address(reference x) { return (pointer)&x; } const_pointer const_address(const_reference x) { return (const_pointer)&x; } size_type init_page_size() { return max(size_type(1), size_type(4096/sizeof(SgGeneric))); } size_type max_size() const { return max(size_type(1), size_type(UINT_MAX/sizeof(SgGeneric))); } };

class allocator_list_node

{ public: typedef list_node value_type; typedef list_node* pointer; typedef const list_node* const_pointer; typedef list_node& reference; typedef const list_node& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; pointer allocate(size_type n) { return ::allocate((difference_type)n, (pointer)0); } void deallocate(pointer p) { ::deallocate(p); } pointer address(reference x) { return (pointer)&x; } const_pointer const_address(const_reference x) { return (const_pointer)&x; } size_type init_page_size() { return max(size_type(1), size_type(4096/sizeof(list_node))); } size_type max_size() const { return max(size_type(1), size_type(UINT_MAX/sizeof(list_node))); } }; static allocator_list_node list_node_allocator; static allocator value_allocator; public: typedef SgGeneric value_type; typedef allocator value_allocator_type; typedef allocator::pointer pointer; typedef allocator::reference reference; typedef allocator::const_reference const_reference; typedef allocator_list_node list_node_allocator_type; typedef allocator_list_node::pointer link_type; typedef allocator_list_node::size_type size_type; typedef allocator_list_node::difference_type difference_type; protected: size_type buffer_size() { return list_node_allocator.init_page_size(); } struct list_node_buffer; friend list_node_buffer; friend inline list_node_buffer * allocate(ptrdiff_t, list_node_buffer *); friend inline void deallocate(list_node_buffer *); class allocator_list_node_buffer; friend allocator_list_node_buffer; struct list_node_buffer { void_pointer next_buffer; link_type buffer; };

class allocator_list_node_buffer

{ public: typedef list_node_buffer value_type; typedef list_node_buffer* pointer; typedef const list_node_buffer* const_pointer; typedef list_node_buffer& reference; typedef const list_node_buffer& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; pointer allocate(size_type n) { return ::allocate((difference_type)n, (pointer)0); } void deallocate(pointer p) { ::deallocate(p); } pointer address(reference x) { return (pointer)&x; } const_pointer const_address(const_reference x) { return (const_pointer)&x; } size_type init_page_size() { return max(size_type(1), size_type(4096/sizeof(list_node_buffer))); } size_type max_size() const { return max(size_type(1), size_type(UINT_MAX/sizeof(list_node_buffer))); } }; public: typedef allocator_list_node_buffer buffer_allocator_type; typedef allocator_list_node_buffer::pointer buffer_pointer; protected: static allocator_list_node_buffer buffer_allocator; static buffer_pointer buffer_list; static link_type free_list; static link_type next_avail; static link_type last; void add_new_buffer(); static size_type number_of_lists; void deallocate_buffers(); link_type get_node(); void put_node(link_type p); protected: link_type node; size_type length; public: class iterator; class const_iterator;

class iterator

: public bidirectional_iterator_SgGeneric { friend class SgGenericList; friend class const_iterator; protected: link_type node; iterator(link_type x) : node(x) {} public: iterator() {} BOOL operator==(const iterator& x) const { return node == x.node; } BOOL operator!=(const iterator& x) const { return !(node == x.node); } reference operator*() const { return (*node).data; } iterator& operator++(); iterator operator++(int); iterator& operator--(); iterator operator--(int); };

class const_iterator

: public bidirectional_iterator_SgGeneric { friend class SgGenericList; protected: link_type node; const_iterator(link_type x) : node(x) {} public: const_iterator() {} const_iterator(const iterator& x) : node(x.node) {} BOOL operator==(const const_iterator& x) const { return node == x.node; } BOOL operator!=(const const_iterator& x) const { return ! (node == x.node); } const_reference operator*() const { return (*node).data; } const_iterator& operator++(); const_iterator operator++(int); const_iterator& operator--(); const_iterator operator--(int); };

class reverse_bidirectional_const_iterator

: public bidirectional_iterator_SgGeneric { typedef reverse_bidirectional_const_iterator self; friend BOOL operator==(const self& x, const self& y); protected: SgGenericList::const_iterator current; public: reverse_bidirectional_const_iterator() {} reverse_bidirectional_const_iterator(SgGenericList:: const_iterator x) : current(x) {} SgGenericList::const_iterator base() { return current; } SgGenericList::const_reference operator*() const; self& operator++(); self operator++(int); self& operator--(); self operator--(int); };

class reverse_bidirectional_iterator

: public bidirectional_iterator_SgGeneric { typedef reverse_bidirectional_iterator self; friend BOOL operator==(const self& x, const self& y); protected: SgGenericList::iterator current; public: reverse_bidirectional_iterator() {} reverse_bidirectional_iterator(SgGenericList::iterator x) : current(x) {} SgGenericList::iterator base() { return current; } SgGenericList::reference operator*() const; self& operator++(); self operator++(int); self& operator--(); self operator--(int); }; typedef reverse_bidirectional_const_iterator const_reverse_iterator; typedef reverse_bidirectional_iterator reverse_iterator; SgGenericList() : length(0); iterator begin() { return (link_type)((*node).next); } const_iterator begin() const { return (link_type)((*node).next); } iterator end() { return node; } const_iterator end() const { return node; } reverse_iterator rbegin() { return reverse_iterator(end()); } const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } reverse_iterator rend() { return reverse_iterator(begin()); } const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } BOOL empty() const { return length == 0; } size_type size() const { return length; } size_type max_size() const { return list_node_allocator.max_size(); } reference front() { return *begin(); } const_reference front() const { return *begin(); } reference back() { return *(--end()); } const_reference back() const { return *(--end()); } void swap(SgGenericList& x) { ::swap(node, x.node); ::swap(length, x.length); } const SgGeneric& remove_front(); void copy(SgGenericList& dest, SgGenericList& source); iterator insert(iterator position, const SgGeneric& x); void insert(iterator position, const SgGeneric* a_first, const SgGeneric* last); void insert(iterator position, const_iterator a_first, const_iterator a_last); void insert(iterator position, size_type n, const SgGeneric& x); void push_front(const SgGeneric& x) { insert(begin(), x); } void push_back(const SgGeneric& x) { insert(end(), x); } void erase(iterator position); void erase(iterator a_first, iterator a_last); void pop_front() { erase(begin()); } void pop_back(); /* constructors */ SgGenericList(size_type n, const SgGeneric& value = SgGeneric()) : length(0); SgGenericList(const SgGeneric* a_first, const SgGeneric* a_last) : length(0); SgGenericList(const SgGenericList& x) : length(0); /* destructor */ ~SgGenericList(); /* operators */ SgGenericList& operator=(const SgGenericList& x); protected: void transfer(iterator position, iterator a_first, iterator a_last); public: friend inline void distance(iterator, iterator, difference_type &); void splice(iterator position, SgGenericList& x); void splice(iterator position, SgGenericList& x, iterator i); void splice(iterator position, SgGenericList& x, iterator a_first, iterator a_last); void remove(const SgGeneric& value); void unique(); void merge(SgGenericList& x); void reverse(); void sort(); };
[Extreme] Extreme! Computing Home Page
horea adrian abrudan
Last modified: Tue Jul 29 11:24:36 EST 1997