Base abstract class for all statements.
For base class see SgLocatedNode
class SgStatement : public SgLocatedNode {
public:
/* constructors and destructors */
SgStatement() : p_parent(0) { set_pragma(); }
~SgStatement() {}
SgStatement(Sg_File_Info* info) : SgLocatedNode(info),
p_parent(0) { set_pragma(); }
SgStatement* get_parent() const {return p_parent; }
SgAttributePtrList& get_uattributes() { return p_uattributes; }
void set_parent(SgStatement* cp);
void set_parent(SgExpression*) {}
void set_parent(SgType *) {}
void set_parent(SgSymbol *) {}
void output_pragma(ostream& os);
void set_pragma();
SgScopeStatement *get_scope();
virtual void setExtern() {}
virtual void setStatic() {}
/* the iterator associated with the class SgStatement */
class iterator {
public:
enum type { decllist=0, stmtlist, other };
iterator(SgStatement *);
int operator==(const iterator &) const;
int operator!=(const iterator &) const;
SgStatement * operator *() const;
void skip_to_next(SgStatement *);
iterator& operator ++(int);
void print(ostream &);
void printall(ostream &);
void mapall_prefix(SgApplyFunction *);
void mapall_postfix(SgApplyFunction *);
void mapall_exception(SgApplyFunction *,
SgStatement *,int);
private:
SgStatement *top_stmt;
SgStatement *p_stmt;
// current statement if s_type=other
enum type s_type;
int p_cnt; // keep track of which child is retrieved
short islast; // keep track if it is the last
SgDeclarationStatementPtrList::iterator diter;
SgDeclarationStatementPtrList diter_list;
SgStatementPtrList::iterator siter;
SgStatementPtrList siter_list;
}; /* end class iterator */
virtual SgStatement *get_first() const;
virtual SgStatement *get_next(int&) const { return 0; }
virtual SgStatement *get_end() const { return 0; }
virtual int replace_statement(SgStatement *,SgStatement *)
{ return 0; }
SgStatement::iterator begin() { return get_first(); }
SgStatement::iterator end() { return get_end(); }
virtual void insert_statement(SgStatement*, SgStatement*, int)
{ return 0; }
public:
void add_pragma(int cnt, SgPragma** plist);
SgPragma* add_pragma(char *nm);
SgPragma* get_pragma(char *nm) const;
int remove_pragma(char *nm);
// manage attributes
SgAttribute* get_user_attribute(char *nm) const;
SgAttribute* add_user_attribute(char *nm,SgAttribute *attr);
int remove_user_attribute(char *nm);
protected:
SgStatement* p_parent;
SgAttributePtrList p_uattributes;
};
SgExpression
Abstract base class for all expressions.
For base class see SgLocatedNode
class SgExpression : public SgLocatedNode {
public:
SgExpression() : p_parent(0L) { set_pragma(); }
SgExpression(Sg_File_Info* info) : p_parent(0L), SgLocatedNode(info)
{ set_pragma(); }
SgExpression * get_parent() const { return p_parent; }
SgAttributePtrList& get_uattributes() { return p_uattributes; }
void set_parent(SgExpression * a_parent) { p_parent = a_parent; }
void set_parent(SgStatement *) {}
void set_parent(SgType *) {}
void set_parent(SgSymbol *) {}
void output_pragma(ostream& os);
void set_pragma();
virtual SgType * get_type() const;
virtual void set_type();
virtual int precedence() const { return 0; }
virtual int length() const { return 0; }
virtual bool empty() const { return 1; }
/* iterate through the children */
class iterator {
public:
enum type {unary=0, binary, list, value, mixed};
iterator(SgExpression *);
int operator==(const iterator &) const;
int operator!=(const iterator &) const;
SgExpression * operator *() const ;
iterator& operator ++(int);
void skip_to_next(SgExpression *);
iterator& insert_link_after(const SgExpression *);
void print(ostream &);
void printall(ostream &);
void mapall_prefix(SgApplyFunction *);
void mapall_postfix(SgApplyFunction *);
private:
SgExpression *top_expr;
SgExpression *p_expr; // current expression if s_type!=list
int p_cnt; // keep track of which child is being called
enum type e_type;
short islast; // keep track if it is the last yet
SgExpressionPtrList::iterator eiter;
SgExpressionPtrList eiter_list;
};/* end class iterator */
virtual SgExpression *get_first() const { int p=0;
return get_next(p); }
virtual SgExpression *get_next(int&) const { return 0; }
virtual SgExpression *get_end() const { return 0; }
virtual int replace_expression(SgExpression *,SgExpression *)
{ return 0; }
virtual void insert_next(int,SgExpression *) {};
SgExpression::iterator begin() { return get_first(); }
SgExpression::iterator end() { return get_end(); }
enum attribute_enum {
e_lvalue = 0x80000000 /* whether the expr is an lvalue */
};
public:
void set_lvalue();
void unset_lvalue();
int get_is_lvalue() const;
void add_pragma(int cnt, SgPragma** plist);
SgPragma* add_pragma(char *nm);
SgPragma* get_pragma(char *nm) const;
int remove_pragma(char *nm);
// get attribute,
SgAttribute* get_user_attribute(char *nm) const;
SgAttribute* add_user_attribute(char *nm, SgAttribute* attr);
int remove_user_attribute(char *nm);
protected:
SgExpression* p_parent;
SgAttributePtrList p_uattributes;
/* useful functions imported on mass from sage1 */
friend SgExpression &operator + ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator - ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator * ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator / ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator % ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator ^ ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator <<( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator >>( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator < ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator > ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator <= ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator >= ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator & ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator | ( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator &&( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator ||( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator +=( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator &=( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator *=( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator /=( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator %=( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator ^=( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator <<=( SgExpression &lhs, SgExpression &rhs);
friend SgExpression &operator >>=( SgExpression &lhs, SgExpression &rhs);
};
SgNode
Base abstract class for all Sage classes. This is the top of the
Sage++ class hierarchy. All sage nodes that define statements,
symbols, types and expressions are derived from it.
class SgNode {
public:
/*
* print is the controlling functions called by the user. It would
* not usually be overridden for each class
* _print is the function that is overriden for each class, and is
* called by print: would not usually be called directly by the user
*/
virtual void print(ostream* os = 0, /* 0 uses the default */
int maxdepth = -1); /* controlling function*/
/* this _print just prints out class name */
virtual bool _print(int depth) const; /* the one overidden
for each class*/
/*
* the traverse_tree function calls traverser->visit()
* on each member
* of the tree rooted at that point
*/
virtual void traverse_tree(Sg_Tree_Traverser* traverser) = 0;
/*
* this next is a hook function to allow the addition of extra paths
* to be traversed that the generator is not aware of
* does not need to be virtual as it is always called
* from a _traverse_tree
* function with an exact type. JP
*/
void user_defined_traversal(Sg_Tree_Traverser* traverser) {}
virtual void unparse(Unparse_Info& info=NO_UNPARSE_INFO,
ostream& os = cout); /* control fn */
virtual void unparse_helper(Unparse_Info& info=NO_UNPARSE_INFO,
ostream& os = cout);
virtual void logical_unparse(Unparse_Info& info=NO_UNPARSE_INFO,
ostream& os = cout);
virtual void output_pragma(ostream& os=cout);
/* logical unparse is the one overridden for each class*/
virtual int variant() const = 0;
virtual void directives(ostream& os);
/* sage_class_name() returns the printable
name of the _sage_ class */
virtual const char* sage_class_name() const = 0;
/*
* _copy_tree() is the function overridden for
* each type of node, and
* generated for the classes in the spec files.
*/
virtual SgNode* _copy_tree(Sg_Copy_Info* copy_info) const = 0;
/*
* user_defined copy can be overridden for particular classes to
* handle cases that the generator is not aware of.
* it should always call super::user_defined_copy(source) before
* doing anything local.
*
* note it doesn't need to be virtual as it is
* called only in constructors
*/
void user_defined_copy(const SgNode* source)
{/* default is to do nothing */ }
Sg_Attribute* get_attribute();
void set_attribute(Sg_Attribute*);
virtual ~SgNode();
protected:
SgNode();
/*
* this next function is called at the end of generated constructors
* to allow the specification writer to add special initialization
* functions or tests. Default is to do nothing.
* Otherwise it should
* be overridden in the spec file, in NewHeaderCode/NewOutlinedCode.
*/
virtual void post_construction_initialization();
void inline initialize_attribute(Sg_Attribute* attr);
Sg_Attribute* user_attribute;
private:
SgNode(SgNode &); /* private so it can't be used. */
};
SgLocatedNode
Base abstract class for all expressions and statements.
For base class see SgNode
class SgLocatedNode : public SgNode {
public:
void setlineNumber(unsigned long new_line);
Sg_File_Info* get_file_info() const;
void set_file_info(Sg_File_Info* f_i);
virtual bool _print(int depth) const; /* prints file info */
/*
* copy_tree returns a copy of the tree rooted
* at the node it is called
* on. The tree and statements and enclosed expressions is copied
* it is only defined for Located Nodes
* (i.e. Statements and Expressions)
*
* if and when the compiler supports contravariance in return types
* then copy tree should return the type of the enclosing class
*/
virtual SgLocatedNode* copy_tree();
protected:
/* constructors */
SgLocatedNode();
SgLocatedNode(Sg_File_Info* info):p_file_info(info) {}
void delete_file_info() ;
void directives(ostream& os);
private:
Sg_File_Info* p_file_info;
SgLocatedNode(SgLocatedNode&); /* until we know what to do with it*/
};
SgSymbol
Base abstract class for sage symbol nodes.
For base class see SgNode
class SgSymbol : public SgNode {
public:
SgSymbol() {}
virtual SgType * get_type() const =0;
virtual SgName get_name() const = 0;
SgSymbol * get_parent() const { return 0; }
void set_parent(SgStatement *) {}
void set_parent(SgExpression *) {}
void set_parent(SgType *) {}
void set_parent(SgSymbol *) {}
protected:
};
SgType
Base abstract class for sage type nodes.
For base class see SgNode
class SgType : public SgNode {
friend class SgPointerType;
friend class SgReferenceType;
friend class SgTypedefType;
/* constructor, destructor */
SgType() : ref_to(0L), ptr_to(0L), modifiers(0L) {}
~SgType() { delete modifiers; }
public:
inline SgType();
inline ~SgType();
virtual SgName get_mangled(Unparse_Info& = NO_UNPARSE_INFO)
{ return ""; }
SgType * get_parent() const { return 0; }
void set_parent(SgExpression *) {}
void set_parent(SgStatement *) {}
void set_parent(SgType *) {}
void set_parent(SgSymbol *) {}
virtual bool isConst() const { return false; }
virtual bool isExtern() const { return false; }
virtual bool isTypedef() const { return false; }
virtual bool isVirtual() const { return false; }
virtual bool isProtected() const {return false;}
virtual bool isPrivate() const { return false; }
virtual bool isPublic() const {return false;}
virtual bool isGlobal() const {return false;}
virtual bool isAuto() const {return false;}
virtual bool isSync() const {return false;}
virtual bool isVolatile() const {return false;}
SgType* findBaseType() const;
bool isLong() const;
bool isShort() const;
bool isUnsignedType() const;
bool isIntegerType() const;
bool isFloatType() const;
SgType * dereference();
const SgType * dereference() const
{ return ((SgType *) this)-$gtdereference(); }
inline SgModifierType* matchModifiers(unsigned int f)
{
if (modifiers) {
return modifiers->match(this, f);
} else {
return (modifiers = new SgModifierNodes())->match(this, f);
}
}
void printName(Unparse_Info& ui, ostream& os);
enum basic_type_enum { t_Char, t_SignedChar, t_UnsignedChar,
t_Short, t_SignedShort, t_UnsignedShort, t_Int, t_SignedInt,
t_UnsignedInt, t_Long, t_SignedLong, t_UnsignedLong, t_Void,
t_Wchar, t_Float, t_Double, t_LongLong, t_LongDouble, t_Bool,
t_Default };
enum basic_modifier_enum {
e_const = 0x00000001,
e_sync = 0x00000002,
e_global= 0x00000004
};
static SgType * arithmetic_conversions(SgType *, SgType *);
static SgType * integer_promotion(SgType *, SgType *);
static SgType * float_promotion(SgType *, SgType *);
static SgType * rmModifier(SgType *, int);
static SgType * addModifier(SgType *, int);
protected:
SgReferenceType* ref_to;
SgPointerType* ptr_to;
SgModifierNodes* modifiers;
SgTypePtrList typedefs;
};