Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

declNode Class Reference

Declaration. More...

#include <ast.h>

Inheritance diagram for declNode::

defNode Node subdeclNode List of all members.

Public Types

enum  Decl_location {
  UNKNOWN, TOP, BLOCK, FORMAL,
  SU, ENUM, PROC
}
 Declaration location. More...

enum  Storage_class {
  NONE, AUTO, EXTERN, REGISTER,
  STATIC, TYPEDEF
}
 Storage class specifier. More...


Public Methods

 declNode (const char *name, Storage_class sc, typeNode *the_type, exprNode *init, exprNode *bitsize, const Coord coord=Coord::Unknown)
 Create a declaration. More...

virtual ~declNode ()
 Destroy a declNode. More...

typeNode * base_type (bool TdefIndir) const
 Return the base data type of a node. More...

typeNode * no_tdef_type ()
 Return the type. More...

virtual declNode * original ()
 SSA original declaration. More...

virtual void dataflow (FlowVal *v, FlowProblem &fp)
 Run the dataflow analyzer. More...

virtual Node * clone () const
 Clone the input node. More...

virtual void output (output_context &ct, Node *par)
 Generate C code. More...

Parser constructors
 declNode (idNode *id, Storage_class sc, typeNode *the_type, exprNode *init, exprNode *bitsize)
 Create a declaration from an identifier. More...

 declNode (idNode *name, exprNode *value)
 Create an enum declaration. More...

 declNode (typeNode *the_type, Storage_class sc)
 Create a type-only declaration. More...

Accessors
Methods to get and set fields in the class.

typeNode * type () const
 Return this declNode's base C data type. More...

typeNode * get_type ()
 Return this declNode's base C data type, and set the base C data type to be empty. More...

void type (typeNode *the_type)
 Set this declNode's base C data type. More...

string & name ()
 Return the name of the variable declared by this declNode. More...

void name (string name)
 Set the name of the variable declared by this declNode. More...

Decl_location decl_location () const
 Return a Decl_location indicating the syntactic context in which this declaration occured. More...

void decl_location (Decl_location loc)
 Set the syntactic context in which this declaration occured. More...

Storage_class storage_class () const
 Return the storage class of the variable declared by this declNode. More...

void storage_class (Storage_class sc)
 Set the storage class of the variable declared by this declNode. More...

bool is_redundant_extern () const
 Return true iff this declaration is a redundant extern declaration. More...

void set_redundant_extern (bool v)
 Set whether this declaration is a redundant extern declaration. More...

void inc_references ()
 Increment the number of identifier nodes that point to this declaration. More...

exprNode * init () const
 Return the AST used to initialize the variable declared by this declNode. More...

void init (exprNode *init)
 Define the AST node used to initialize the variable declared by this declNode. More...

exprNode * bitsize () const
 Return this Node's bitsize. More...

void bitsize (exprNode *bitsize)
 Define the bitsize for this declNode. More...

int references () const
 Return the number of idNodes that point to this declaration. More...

void references (int references)
 Set the number of idNodes that point to this declaration. More...

attrib_list & attribs ()
 Return a mutable reference to this declaration's attribute list. More...

const attrib_list & attribs () const
 Return an immutable reference to this declaration's attribute list. More...

void merge_attribs (attrib_list *attribs)
 Add each attribute in the given attribute list to this declNode's attribute list. More...

Parser methods
void set_type (typeNode *the_type, Storage_class sc, ScopeState redeclare)
declNode * set_type_and (typeNode *the_type, Storage_class sc, ScopeState redeclare)
declNode * set_type_and (declNode *the_decltype, Storage_class sc, ScopeState redeclare)
void inherit_type (decl_list *others, ScopeState redeclare)
declNode * inherit_type_and (decl_list *others, ScopeState redeclare)
void modify_type (typeNode *the_type)
declNode * modify_type_and (typeNode *the_type)
declNode * modify_type_and (declNode *the_type)
void set_init (exprNode *init)
declNode * set_init_and (exprNode *init)
void add_parameter_types (decl_list *types)
declNode * add_parameter_types_and (decl_list *types)
void finish (Storage_class sc)
declNode * finish_and (Storage_class sc)
AST Traversal
Methods to uniformly traverse the AST. See the documentation in the Node class.

virtual void visit (Visitor *the_visitor)
 Dispatch a Visitor. More...

virtual void walk (Walker &the_walker)
 Dispatch a Walker. More...

virtual Node * change (Changer &the_changer, bool redispatch=false)
 Dispatch a Changer. More...


Static Public Methods

Output methods.
These two methods are used when generating C code to convert the Storage_class and Decl_location values into strings.

string storage_class_name (Storage_class sc)
 Return a string value containing the C code for this Declaration's storage class. More...

string decl_location_name (Decl_location dl)
 Return a string value containing the C code for this Declaration's location. More...


Private Attributes

TREE typeNode * _type
 Type. More...

string _name
 Name. More...

Decl_location _decl_location
 Declaration location. More...

Storage_class _storage_class
 Storage class. More...

bool _is_redundant_extern
 Redundant extern. More...

TREE exprNode * _init
 Initializer expression. More...

TREE exprNode * _bitsize
 Bitsize expression. More...

int _references
 Reference count. More...

TREE attrib_list _attribs
 Attributes. More...


Detailed Description

Declaration.

This class represents all declarations. At its core, it is just a name and a data type, with the optional initializer and bitsize expressions. However, it also holds information about the syntactic location of the declaration and any associated storage class.

The NodeType is Decl.


Member Enumeration Documentation

enum declNode::Decl_location
 

Declaration location.

This type is used to record some syntactic context information about the declaration. This information is computed by the id_lookup_walker.

See also:
id_lookup_walker
Enumeration values:
UNKNOWN  No context provided
TOP  A top-level declaration (either a global variable or a function declaration).
BLOCK  A regular local variable declared inside a function body.
FORMAL  A formal argument declared in the function interface.
SU  A struct/union field declaration.
ENUM  An element of an enum declaration.
PROC  A function declaration that has the function definition.

enum declNode::Storage_class
 

Storage class specifier.

This type indicates any storage class information associated with the declaration. It is overloaded to also indicate when a declaration is a typedef.

Enumeration values:
NONE 
AUTO 
EXTERN 
REGISTER 
STATIC 
TYPEDEF 


Constructor & Destructor Documentation

declNode::declNode (  const char *    name,
Storage_class    sc,
typeNode *    the_type,
exprNode *    init,
exprNode *    bitsize,
const Coord    coord = Coord::Unknown
) 
 

Create a declaration.

Create a new declaration with the given parameters. This constructor allows most of the properties of the declaration to be specified explicitly. The exceptions are the declNode's location, which is set to UNKNOWN, and the boolean redundant_extern, which is set to false. User code should only need this constructor. The following example declaration is used to point out which features each parameter represents.

    static int x = 12;
Parameters:
name  a C string specifying the declaration name ("x" in the example). This value is copied.
sc  the storage class of the declaration ("static" in the example).
the_type  the type of the declaration ("int" in the example).
init  an initializer expression, or NULL for none ("12" in the example).
bitsize  a bitfield size expression, or NONE if the declaration does not declare a bitfield (the example does not declare a bitfield).
coord  the location of the construct in the source file.

declNode::declNode (  idNode *    id,
Storage_class    sc,
typeNode *    the_type,
exprNode *    init,
exprNode *    bitsize
) 
 

Create a declaration from an identifier.

declNode::declNode (  idNode *    idname,
exprNode *    value
) 
 

Create an enum declaration.

declNode::declNode (  typeNode *    the_type,
Storage_class    sc = NONE
) 
 

Create a type-only declaration.

declNode::~declNode (    )  [virtual]
 

Destroy a declNode.

Warning:
Do not use the destructors to delete AST nodes. Instead, rely on the node garbage collector.


Member Function Documentation

void declNode::add_parameter_types (  decl_list *    types ) 
 

declNode * declNode::add_parameter_types_and (  decl_list *    types ) 
 

const attrib_list& declNode::attribs (    )  const [inline]
 

Return an immutable reference to this declaration's attribute list.

attrib_list& declNode::attribs (    )  [inline]
 

Return a mutable reference to this declaration's attribute list.

typeNode * declNode::base_type (  bool    TdefIndir )  const [virtual]
 

Return the base data type of a node.

This method differs from the Node::type() method in two respects. First, it follows some of the simple type inferences. For example, calling it on an idNode will return the type of its declaration. Second, the boolean argument indicates whether or not to follow typedef links.

Parameters:
TdefIndir  pass true to follow typedefs to their definitions.

Reimplemented from Node.

void declNode::bitsize (  exprNode *    bitsize )  [inline]
 

Define the bitsize for this declNode.

To set the bitsize of this declNode to be empty, call this method with a value of NULL.

exprNode* declNode::bitsize (    )  const [inline]
 

Return this Node's bitsize.

Node * declNode::change (  Changer &    the_changer,
bool    redispatch = false
)  [virtual]
 

Dispatch a Changer.

This abstract method works much the walker, but allows the tree to be changed.

Parameters:
the_changer  the specific Changer object to use.
redispatch  pass true to revisit parts of the tree that have changed.

Reimplemented from Node.

Reimplemented in subdeclNode.

virtual Node* declNode::clone (    )  const [inline, virtual]
 

Clone the input node.

This is not a "deep" clone, so be careful. For a deep clone, use the clone_changer class.

Returns:
a shallow copy of the node (no subtrees are copied).

Reimplemented from Node.

Reimplemented in subdeclNode.

void declNode::dataflow (  FlowVal *    v,
FlowProblem &    fp
)  [virtual]
 

Run the dataflow analyzer.

Each subclass overrides this method to define it's semantics for dataflow analysis. It alters the input flow value to reflect the effect of the node within the given flow problem, calling dataflow() on it's subtrees as necessary. See the dataflow analysis documentation for more information.

Parameters:
v  the flow value to pass through the node.
fp  the flow problem (specifying the transfer functions).

Reimplemented from Node.

void declNode::decl_location (  Decl_location    loc )  [inline]
 

Set the syntactic context in which this declaration occured.

Decl_location declNode::decl_location (    )  const [inline]
 

Return a Decl_location indicating the syntactic context in which this declaration occured.

string declNode::decl_location_name (  Decl_location    dl )  [static]
 

Return a string value containing the C code for this Declaration's location.

void declNode::finish (  Storage_class    sc ) 
 

declNode * declNode::finish_and (  Storage_class    sc ) 
 

typeNode* declNode::get_type (    )  [inline]
 

Return this declNode's base C data type, and set the base C data type to be empty.

void declNode::inc_references (    )  [inline]
 

Increment the number of identifier nodes that point to this declaration.

void declNode::inherit_type (  decl_list *    others,
ScopeState    redeclare
) 
 

declNode * declNode::inherit_type_and (  decl_list *    others,
ScopeState    redeclare
) 
 

void declNode::init (  exprNode *    init )  [inline]
 

Define the AST node used to initialize the variable declared by this declNode.

To set the initializer of this declNode to be empty, call this method with a value of NULL.

exprNode* declNode::init (    )  const [inline]
 

Return the AST used to initialize the variable declared by this declNode.

bool declNode::is_redundant_extern (    )  const [inline]
 

Return true iff this declaration is a redundant extern declaration.

Redundant extern declarations are allowed in C.

void declNode::merge_attribs (  attrib_list *    attribs ) 
 

Add each attribute in the given attribute list to this declNode's attribute list.

void declNode::modify_type (  typeNode *    the_type ) 
 

declNode * declNode::modify_type_and (  declNode *    the_decl ) 
 

declNode * declNode::modify_type_and (  typeNode *    the_type ) 
 

void declNode::name (  string    name )  [inline]
 

Set the name of the variable declared by this declNode.

string& declNode::name (    )  [inline]
 

Return the name of the variable declared by this declNode.

typeNode * declNode::no_tdef_type (    ) 
 

Return the type.

Return the type after following any typedefs to the real type.

Returns:
the type

virtual declNode* declNode::original (    )  [inline, virtual]
 

SSA original declaration.

For use with subdeclNode when the code is in SSA form. This method returns the original declaration from which the sub-declaration was derived.

Returns:
the original declaration

Reimplemented in subdeclNode.

void declNode::output (  output_context &    ct,
Node *    parent
)  [virtual]
 

Generate C code.

Each subclass overrides this method to define how to produce the output C code. To use this method, pass an output_context and a null parent.

Parameters:
ct  the output context which describes the formatting.
par  the parent node (or null, if at the top of a subtree).

Reimplemented from Node.

Reimplemented in subdeclNode.

void declNode::references (  int    references )  [inline]
 

Set the number of idNodes that point to this declaration.

int declNode::references (    )  const [inline]
 

Return the number of idNodes that point to this declaration.

void declNode::set_init (  exprNode *    new_init ) 
 

declNode * declNode::set_init_and (  exprNode *    new_init ) 
 

void declNode::set_redundant_extern (  bool    v )  [inline]
 

Set whether this declaration is a redundant extern declaration.

void declNode::set_type (  typeNode *    the_type,
Storage_class    sc,
ScopeState    redeclare
) 
 

declNode * declNode::set_type_and (  declNode *    the_decltype,
Storage_class    sc,
ScopeState    redeclare
) 
 

declNode * declNode::set_type_and (  typeNode *    the_type,
Storage_class    sc,
ScopeState    redeclare
) 
 

void declNode::storage_class (  Storage_class    sc )  [inline]
 

Set the storage class of the variable declared by this declNode.

Storage_class declNode::storage_class (    )  const [inline]
 

Return the storage class of the variable declared by this declNode.

string declNode::storage_class_name (  Storage_class    sc )  [static]
 

Return a string value containing the C code for this Declaration's storage class.

void declNode::type (  typeNode *    the_type )  [inline]
 

Set this declNode's base C data type.

To set the data type to be empty, call this method with a value of NULL.

typeNode* declNode::type (    )  const [inline, virtual]
 

Return this declNode's base C data type.

Reimplemented from Node.

void declNode::visit (  Visitor *    the_visitor )  [virtual]
 

Dispatch a Visitor.

This abstract method is the entry point for the visitor design pattern. Each node subclass defines a visit() method that calls the appropriate at_ method in the visitor. For more information see the Visitor documentation.

Parameters:
the_visitor  the specific Visitor object to use.

Reimplemented from Node.

Reimplemented in subdeclNode.

void declNode::walk (  Walker &    the_walker )  [virtual]
 

Dispatch a Walker.

This abstract method works much like the visitor, but instead walks the entire underlying subtree calling the appropriate at_ method at each node. For more information see the Walker documentation.

Parameters:
the_walker  the specific Walker object to use.

Reimplemented from Node.

Reimplemented in subdeclNode.


Member Data Documentation

TREE attrib_list declNode::_attribs [private]
 

Attributes.

Currently unused.

TREE exprNode* declNode::_bitsize [private]
 

Bitsize expression.

This AST subtree specifies the bitsize expression for bitfields, or is null if the declaration is not a bitfield.

Decl_location declNode::_decl_location [private]
 

Declaration location.

The syntactic location of the declaration.

See also:
Decl_location

TREE exprNode* declNode::_init [private]
 

Initializer expression.

This AST subtree specifies the initializer expression, or is null if there isn't one.

bool declNode::_is_redundant_extern [private]
 

Redundant extern.

This boolean is true if the declaration is a redundant extern declaration (as allowed in C).

string declNode::_name [private]
 

Name.

The name of the declaration.

int declNode::_references [private]
 

Reference count.

Counts the number of identifier nodes that refer to this declaration.

See also:
idNode

Storage_class declNode::_storage_class [private]
 

Storage class.

Storage class specifier.

See also:
Storage_class

TREE typeNode* declNode::_type [private]
 

Type.

This AST subtree defines the type of the declaration.


The documentation for this class was generated from the following files:
Generated on Thu Jan 10 12:06:26 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001