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

typeNode Class Reference

Type node. More...

#include <ast.h>

Inheritance diagram for typeNode::

Node arrayNode funcNode primNode ptrNode sueNode suespecNode tdefNode enumNode structNode unionNode List of all members.

Public Types

enum  Type_qualifiers {
  NONE = 0x0, CONST = 0x1, VOLATILE = 0x2, INLINE = 0x4,
  COMPATIBLE = 0x3
}
 Type qualifiers. More...


Public Methods

 typeNode (NodeType typ, Type_qualifiers tq, typeNode *subtype, const Coord coord)
 Create a new type. More...

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

virtual bool qualified_equal_to (typeNode *other, bool strict_toplevel, bool strict_recursive)
 Virtual type comparison routine. More...

typeNode * unwind_tdefs (Type_qualifiers &the_tq)
 Unwind typedefs. More...

typeNode * no_tdef_type ()
typeNode * follow_tdefs ()
 Follow typedefs. More...

virtual typeNode * usual_unary_conversion_type ()
 Usual unary conversion type. More...

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

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

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

virtual void output_type (output_context &ct, Node *par, Assoc context, Type_qualifiers q)=0
 Output a type. More...

Accessors
Methods to get and set fields in the class.

typeNode * type () const
 Return this typeNode's subtype. More...

typeNode * get_type ()
 Return this typeNode's subtype, and set it to be empty. More...

void type (typeNode *the_type)
 Set this typeNode's subtype. More...

Type_qualifiers type_qualifiers () const
 Return this typeNode's type qualifiers. More...

void type_qualifiers (Type_qualifiers the_tq)
 Set this typeNode's type qualifiers. More...

string type_qualifiers_name ()
 Return a string representation of this typeNode's type qualifiers. More...

void add_type_qualifiers (Type_qualifiers the_tq)
 Add a new type qualifier to this typeNode. More...

typeNode * add_type_qualifiers_and (Type_qualifiers the_tq)
 Add a new type qualifier to this typeNode, and return the typeNode. More...

void remove_type_qualifiers (Type_qualifiers the_tq)
 Remove a type qualifier from this typeNode. More...

Parser methods
void finish ()
typeNode * finish_and ()
void set_base_type (typeNode *base)
typeNode * set_base_type_and (typeNode *base)
void verify_sue_complete ()
Type comparison operators
These operators are used to compare types. They recursively descend the compound types and verify the structure. There are several different variations, depending on the level of strictness. In all cases, typedefs are followed so they don't interfere with the comparison. All operators use the static equal_to() method.

See also:
equal_to()


bool operator== (typeNode &second)
 Strict type comparison. More...

bool operator<= (typeNode &second)
 Weaker type comparison. More...

bool operator!= (typeNode &second)
 Strict type inequality. More...

Type predicates
These methods support a variety of useful type predicates, most of which are self-explanatory. Each typeNode subclass overrides the methods for which it returns true.

virtual bool is_int () const
virtual bool is_char () const
virtual bool is_float () const
virtual bool is_void () const
virtual bool is_ellipsis () const
virtual bool is_integer () const
virtual bool is_arithmetic () const
virtual bool is_scalar () const
virtual bool is_aggregate () const
virtual bool is_derived () const
virtual bool is_pointer () const

Static Public Methods

string type_qualifiers_name (Type_qualifiers tq)
 Convert type qualifiers to string. More...

typeNode * integral_promotions (typeNode *old_type)
 Integral promotions. More...

pair< typeNode *, typeNode *> usual_arithmetic_conversions (typeNode *left, typeNode *right)
 Usual arithmetic conversions. More...

bool equal_to (typeNode *first, typeNode *second, bool strict_toplevel, bool strict_recursive)
 Type comparison. More...


Private Attributes

TREE typeNode * _type
 The sub-type. More...

Type_qualifiers _type_qualifiers
 Type qualifiers. More...


Detailed Description

Type node.

This class provides a base class for all nodes that represent C data types. Types are represented in the tree with the outer-most type specifier at the top and the primitive base type at the bottom. For example, "int * a[3]" is translated into a structure like this: arrayNode --> ptrNode -->primNode (int).

The NodeType is determined by the subclass.


Member Enumeration Documentation

enum typeNode::Type_qualifiers
 

Type qualifiers.

This enum holds the possible type qualifiers. The special COMPATIBLE value indicates which type qualifiers are relevant when comparing two types for compatibility: const and volatile.

Enumeration values:
NONE  No type qualifier
CONST  Type is const
VOLATILE  Type is volatile
INLINE  Type is inline
COMPATIBLE  Mask the qualifiers that are relevant to type compatibility


Constructor & Destructor Documentation

typeNode::typeNode NodeType    typ,
Type_qualifiers    tq,
typeNode *    subtype,
const Coord    coord
 

Create a new type.

Create a type node of the appropriate node type. This constructor is only used by the subclasses, which represent specific types.

Parameters:
typ  the kind of node (passed to the superclass constructor)
tq  the type qualifiers
subtype  the subtype, or 0 if there is none
coord  the location of the construct in the source file.

typeNode::~typeNode   [virtual]
 

Destroy a typeNode.

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


Member Function Documentation

void typeNode::add_type_qualifiers Type_qualifiers    the_tq [inline]
 

Add a new type qualifier to this typeNode.

typeNode* typeNode::add_type_qualifiers_and Type_qualifiers    the_tq [inline]
 

Add a new type qualifier to this typeNode, and return the typeNode.

virtual typeNode* typeNode::base_type bool    TdefIndir const [inline, 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.

Reimplemented in tdefNode.

virtual void typeNode::dataflow FlowVal   v,
FlowProblem   fp
[inline, 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.

typeNode * typeNode::deep_base_type  
 

bool typeNode::equal_to typeNode *    node1,
typeNode *    node2,
bool    strict_toplevel,
bool    strict_recursive
[static]
 

Type comparison.

This static method compares two types, descending into the subtypes and following typedefs as necessary. The two boolean arguments control how strict the algorithm is with respect to type qualifiers. Passing true requires all type qualifiers to be the same. Passing false only requires those type qualifiers that affect compatibility to be the same. (Was TypeEqualQualified in type.c)

This routine relies on the qualified_equal_to() methods on each kind of typeNode to perform the appropriate comparison and dispatch to the sub-type when necessary.

See also:
qualified_equal_to()
Parameters:
first  the first type
second  the second type
strict_toplevel  pass true to require strict comparison of top-level types
strict_recursive  pass true to require strict comparson of sub-types
Returns:
true, if the types pass the equality test

void typeNode::finish  
 

Reimplemented in primNode.

typeNode * typeNode::finish_and  
 

Reimplemented in primNode.

typeNode * typeNode::follow_tdefs  
 

Follow typedefs.

Follow the chain of typedefs from this type, returning the underlying (non-typedef) type.

Returns:
the type at the end of the typedef chain

typeNode* typeNode::get_type   [inline]
 

Return this typeNode's subtype, and set it to be empty.

typeNode * typeNode::integral_promotions typeNode *    old_type [static]
 

Integral promotions.

This method is used during parsing to convert smaller types (char, short, bit-fields and enums) into integers according to the rules in ANSI 6.2.1.1. In addition, our version converts float into double.

See also:
exprNode::integral_promotions()
Parameters:
old_type  the original small type to be promoted
Returns:
the resulting integral type

virtual bool typeNode::is_aggregate   const [inline, virtual]
 

Reimplemented in arrayNode, and structNode.

virtual bool typeNode::is_arithmetic   const [inline, virtual]
 

Reimplemented in primNode, and enumNode.

virtual bool typeNode::is_char   const [inline, virtual]
 

Reimplemented in primNode.

virtual bool typeNode::is_derived   const [inline, virtual]
 

Reimplemented in ptrNode, arrayNode, and funcNode.

virtual bool typeNode::is_ellipsis   const [inline, virtual]
 

Reimplemented in primNode.

virtual bool typeNode::is_float   const [inline, virtual]
 

Reimplemented in primNode.

virtual bool typeNode::is_int   const [inline, virtual]
 

Reimplemented in primNode, and enumNode.

virtual bool typeNode::is_integer   const [inline, virtual]
 

Reimplemented in primNode, and enumNode.

virtual bool typeNode::is_pointer   const [inline, virtual]
 

Reimplemented in ptrNode, arrayNode, and funcNode.

virtual bool typeNode::is_scalar   const [inline, virtual]
 

Reimplemented in primNode, ptrNode, arrayNode, and enumNode.

virtual bool typeNode::is_void   const [inline, virtual]
 

Reimplemented in primNode.

typeNode * typeNode::no_tdef_type  
 

bool typeNode::operator!= typeNode &    second [inline]
 

Strict type inequality.

This is just a negation of the operator==

Parameters:
second  the right type in the comparison
Returns:
true if the types are the same

bool typeNode::operator<= typeNode &    second [inline]
 

Weaker type comparison.

Compare this type to the given type, masking off type qualifiers that don't affect compatibility of types.

See also:
Type_qualifiers
Parameters:
second  the right type in the comparison
Returns:
true if the types are the same

bool typeNode::operator== typeNode &    second [inline]
 

Strict type comparison.

Compare this type to the given type, requiring all type qualifiers to be the same.

Parameters:
second  the right type in the comparison
Returns:
true if the types are the same

void typeNode::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.

virtual void typeNode::output_type output_context   ct,
Node   parent,
Assoc    context,
Type_qualifiers    q
[pure virtual]
 

Output a type.

Reimplemented in primNode, tdefNode, ptrNode, arrayNode, funcNode, sueNode, and suespecNode.

bool typeNode::qualified_equal_to typeNode *    node2,
bool    strict_toplevel,
bool    strict_recursive
[virtual]
 

Virtual type comparison routine.

Each typeNode subclass overrides this routine to provide its specific type comparison. This is used by the static equal_to() method to perform general deep type comparison.

See also:
equal_to()
Parameters:
other  the type to compare against
strict_toplevel  pass true to require strict comparison of top-level types
strict_recursive  pass true to require strict comparson of sub-types
Returns:
true, if the types pass the equality test

Reimplemented in primNode, ptrNode, arrayNode, funcNode, and sueNode.

void typeNode::remove_type_qualifiers Type_qualifiers    the_tq [inline]
 

Remove a type qualifier from this typeNode.

void typeNode::set_base_type typeNode *    base
 

typeNode * typeNode::set_base_type_and typeNode *    base
 

void typeNode::type typeNode *    the_type [inline]
 

Set this typeNode's subtype.

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

typeNode* typeNode::type   const [inline, virtual]
 

Return this typeNode's subtype.

Reimplemented from Node.

void typeNode::type_qualifiers Type_qualifiers    the_tq [inline]
 

Set this typeNode's type qualifiers.

Type_qualifiers typeNode::type_qualifiers   const [inline]
 

Return this typeNode's type qualifiers.

string typeNode::type_qualifiers_name   [inline]
 

Return a string representation of this typeNode's type qualifiers.

string typeNode::type_qualifiers_name Type_qualifiers    the_tq [static]
 

Convert type qualifiers to string.

This method is used when generating C code to convert the type qualifiers into string form.

Parameters:
tq  the type qualifiers to convert
Returns:
the string form of the type qualifiers

typeNode * typeNode::unwind_tdefs Type_qualifiers   the_tq
 

Unwind typedefs.

pair< typeNode *, typeNode *> typeNode::usual_arithmetic_conversions typeNode *    left,
typeNode *    right
[static]
 

Usual arithmetic conversions.

From ANSI 6.2.1.5: Many binary operators that expect operands of arithmetic type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result.

This method takes the types of the left and right operands and returns a pair of types indicating the conversions of the two operands, respectively. When necessary, these conversion include the integral promotions.

See also:
integral_promotions() , exprNode::usual_arithmetic_conversions()
Parameters:
left  the type of the left operand
right  the type of the right operand
Returns:
a pair of converted types for the left and right, respectively

virtual typeNode* typeNode::usual_unary_conversion_type   [inline, virtual]
 

Usual unary conversion type.

The purpose of this method escapes me. The constNode class seems to use it, but all it does is return itself. No other typeNode overrides it.

void typeNode::verify_sue_complete  
 


Member Data Documentation

TREE typeNode* typeNode::_type [private]
 

The sub-type.

This field holds the sub-type for compound types such as array, pointer, and function declaration.

Type_qualifiers typeNode::_type_qualifiers [private]
 

Type qualifiers.

The type qualifiers for this type


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