Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    rac71a86 r7bf7fb9  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 18 23:48:37 2016
    13 // Update Count     : 542
     12// Last Modified On : Sun Aug  7 09:37:16 2016
     13// Update Count     : 333
    1414//
    1515
     
    2222#include <memory>
    2323
     24#include "Common/utility.h"
    2425#include "Parser/LinkageSpec.h"
    2526#include "SynTree/Type.h"
    2627#include "SynTree/Expression.h"
    27 #include "SynTree/Statement.h"
     28//#include "SynTree/Declaration.h"
     29#include "Common/UniqueName.h"
    2830#include "SynTree/Label.h"
    29 #include "Common/utility.h"
    30 #include "Common/UniqueName.h"
    3131
    3232class StatementNode;
    3333class CompoundStmtNode;
    3434class DeclarationNode;
    35 class ExpressionNode;
    3635class InitializerNode;
    3736
    38 //##############################################################################
    39 
     37// Builder
    4038class ParseNode {
    4139  public:
    42         ParseNode() {};
    43         ParseNode( const std::string *name ) : name( *name ) { assert( false ); delete name; }
    44         ParseNode( const std::string &name ) : name( name ) { assert( false ); }
    45         virtual ~ParseNode() { delete next; };
    46         virtual ParseNode *clone() const = 0;
    47 
    48         ParseNode *get_next() const { return next; }
    49         ParseNode *set_next( ParseNode *newlink ) { next = newlink; return this; }
    50         ParseNode *get_last() {
    51                 ParseNode *current;
    52                 for ( current = this; current->get_next() != 0; current = current->get_next() );
    53                 return current;
    54         }
    55         ParseNode *set_last( ParseNode *newlast ) {
    56                 if ( newlast != 0 ) get_last()->set_next( newlast );
    57                 return this;
    58         }
     40        ParseNode();
     41        ParseNode( const std::string * );
     42        ParseNode( const std::string & );                                       // for copy constructing subclasses
     43        virtual ~ParseNode();
     44
     45        ParseNode *get_link() const { return next; }
     46        ParseNode *get_last();
     47        ParseNode *set_link( ParseNode * );
     48        void set_next( ParseNode *newlink ) { next = newlink; }
     49
     50        virtual ParseNode *clone() const { return 0; };
    5951
    6052        const std::string &get_name() const { return name; }
    6153        void set_name( const std::string &newValue ) { name = newValue; }
    6254
    63         virtual void print( std::ostream &os, int indent = 0 ) const {}
    64         virtual void printList( std::ostream &os, int indent = 0 ) const {}
    65   private:
     55        virtual void print( std::ostream &os, int indent = 0 ) const;
     56        virtual void printList( std::ostream &os, int indent = 0 ) const;
     57
     58        ParseNode &operator,( ParseNode &);
     59  protected:
     60        std::string name;
    6661        static int indent_by;
    67 
    68         ParseNode *next = nullptr;
    69         std::string name;
    70 }; // ParseNode
    71 
    72 //##############################################################################
    73 
    74 class InitializerNode : public ParseNode {
    75   public:
    76         InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode *des = 0 );
    77         InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 );
    78         ~InitializerNode();
    79         virtual InitializerNode *clone() const { assert( false ); return nullptr; }
    80 
    81         ExpressionNode *get_expression() const { return expr; }
    82 
    83         InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; }
    84         ExpressionNode *get_designators() const { return designator; }
    85 
    86         InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }
    87         bool get_maybeConstructed() const { return maybeConstructed; }
    88 
    89         InitializerNode *next_init() const { return kids; }
    90 
    91         void print( std::ostream &os, int indent = 0 ) const;
    92         void printOneLine( std::ostream & ) const;
    93 
    94         virtual Initializer *build() const;
    95   private:
    96         ExpressionNode *expr;
    97         bool aggregate;
    98         ExpressionNode *designator;                                                     // may be list
    99         InitializerNode *kids;
    100         bool maybeConstructed;
    101 };
    102 
    103 //##############################################################################
    104 
    105 class ExpressionNode final : public ParseNode {
    106   public:
    107         ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {}
    108         ExpressionNode( Expression * expr, const std::string *name ) : ParseNode( name ), expr( expr ) {}
     62        ParseNode *next;
     63};
     64
     65ParseNode *mkList( ParseNode & );
     66
     67//##############################################################################
     68
     69class ExpressionNode : public ParseNode {
     70  public:
     71        ExpressionNode();
     72        ExpressionNode( const std::string * );
    10973        ExpressionNode( const ExpressionNode &other );
    110         virtual ~ExpressionNode() {}
    111         virtual ExpressionNode *clone() const { assert( false ); return nullptr; }
    112 
     74        virtual ~ExpressionNode() { delete argName; }
     75
     76        virtual ExpressionNode *clone() const = 0;
     77
     78        ExpressionNode *get_argName() const { return argName; }
     79        ExpressionNode *set_argName( const std::string *aName );
     80        ExpressionNode *set_argName( ExpressionNode *aDesignator );
    11381        bool get_extension() const { return extension; }
    11482        ExpressionNode *set_extension( bool exten ) { extension = exten; return this; }
    11583
    116         void print( std::ostream &os, int indent = 0 ) const {}
    117         void printOneLine( std::ostream &os, int indent = 0 ) const {}
    118 
    119         template<typename T>
    120         bool isExpressionType() const {
    121                 return nullptr != dynamic_cast<T>(expr.get());
    122         }
    123 
    124         Expression *build() const { return const_cast<ExpressionNode*>(this)->expr.release(); }
    125   private:
     84        virtual void print( std::ostream &os, int indent = 0) const = 0;
     85        virtual void printOneLine( std::ostream &os, int indent = 0) const = 0;
     86
     87        virtual Expression *build() const = 0;
     88  protected:
     89        void printDesignation ( std::ostream &os, int indent = 0) const;
     90  private:
     91        ExpressionNode *argName = 0;
    12692        bool extension = false;
    127         std::unique_ptr<Expression> expr;
    12893};
    12994
    13095template< typename T >
    131 struct maybeBuild_t< Expression, T > {
     96struct maybeBuild_t<Expression, T> {
    13297        static inline Expression * doit( const T *orig ) {
    13398                if ( orig ) {
     
    136101                        return p;
    137102                } else {
    138                         return nullptr;
     103                        return 0;
    139104                } // if
    140105        }
     106};
     107
     108//##############################################################################
     109
     110// NullExprNode is used in tuples as a place-holder where a tuple component is omitted e.g., [ 2, , 3 ]
     111class NullExprNode : public ExpressionNode {
     112  public:
     113        NullExprNode();
     114
     115        virtual NullExprNode *clone() const;
     116
     117        virtual void print( std::ostream &os, int indent = 0) const;
     118        virtual void printOneLine( std::ostream &os, int indent = 0) const;
     119
     120        virtual Expression *build() const;
     121};
     122
     123//##############################################################################
     124
     125class ConstantNode : public ExpressionNode {
     126  public:
     127        ConstantNode( ConstantExpr *expr ) : expr( expr ) {}
     128        ConstantNode( const ConstantNode &other ) : expr( other.expr->clone() ) {}
     129        virtual ~ConstantNode() {}
     130
     131        virtual ConstantNode *clone() const { assert( false ); return new ConstantNode( *this ); }
     132
     133        ConstantExpr *get_expr() const { return expr; }
     134
     135        virtual void print( std::ostream &os, int indent = 0 ) const {}
     136        virtual void printOneLine( std::ostream &os, int indent = 0 ) const {}
     137
     138        Expression *build() const { return expr; }
     139  private:
     140        ConstantExpr *expr;
     141};
     142
     143ConstantNode *build_constantInteger( std::string &str );
     144ConstantNode *build_constantFloat( std::string &str );
     145ConstantNode *build_constantChar( std::string &str );
     146ConstantNode *build_constantStr( std::string &str );
     147
     148//##############################################################################
     149
     150class VarRefNode : public ExpressionNode {
     151  public:
     152        VarRefNode( const std::string *, bool isLabel = false );
     153        VarRefNode( const VarRefNode &other );
     154
     155        virtual Expression *build() const ;
     156
     157        virtual VarRefNode *clone() const { return new VarRefNode( *this ); }
     158
     159        virtual void print( std::ostream &os, int indent = 0 ) const;
     160        virtual void printOneLine( std::ostream &os, int indent = 0 ) const;
     161  private:
     162        bool isLabel;
     163};
     164
     165//##############################################################################
     166
     167class DesignatorNode : public ExpressionNode {
     168  public:
     169        DesignatorNode( ExpressionNode *expr, bool isArrayIndex = false );
     170        DesignatorNode( const DesignatorNode &other );
     171
     172        virtual Expression *build() const ;
     173        virtual DesignatorNode *clone() const { return new DesignatorNode( *this ); }
     174
     175        virtual void print( std::ostream &os, int indent = 0 ) const;
     176        virtual void printOneLine( std::ostream &os, int indent = 0 ) const;
     177  private:
     178        bool isArrayIndex;
     179};
     180
     181//##############################################################################
     182
     183class TypeValueNode : public ExpressionNode {
     184  public:
     185        TypeValueNode( DeclarationNode * );
     186        TypeValueNode( const TypeValueNode &other );
     187
     188        DeclarationNode *get_decl() const { return decl; }
     189
     190        virtual Expression *build() const ;
     191
     192        virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); }
     193
     194        virtual void print( std::ostream &os, int indent = 0) const;
     195        virtual void printOneLine( std::ostream &os, int indent = 0) const;
     196  private:
     197        DeclarationNode *decl;
     198};
     199
     200//##############################################################################
     201
     202class CompositeExprNode : public ExpressionNode {
     203  public:
     204        CompositeExprNode( Expression *expr ) : expr( expr ) {}
     205        CompositeExprNode( const CompositeExprNode &other ) : expr( other.expr->clone() ) {}
     206        virtual ~CompositeExprNode() {}
     207
     208        CompositeExprNode *clone() const { assert( false ); return new CompositeExprNode( *this ); }
     209
     210        Expression *build() const { return expr; }
     211
     212        void print( std::ostream &os, int indent = 0 ) const {}
     213        void printOneLine( std::ostream &os, int indent = 0 ) const {}
     214  private:
     215        Expression *expr;
    141216};
    142217
     
    152227};
    153228
    154 struct LabelNode {
    155         std::list< Label > labels;
    156 };
    157 
    158 Expression *build_constantInteger( const std::string &str );
    159 Expression *build_constantFloat( const std::string &str );
    160 Expression *build_constantChar( const std::string &str );
    161 ConstantExpr *build_constantStr( const std::string &str );
    162 
    163 NameExpr *build_varref( const std::string *name, bool labelp = false );
    164 Expression *build_typevalue( DeclarationNode *decl );
    165 
    166 Expression *build_cast( DeclarationNode * decl_node, ExpressionNode *expr_node );
    167 Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member );
    168 Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member );
     229Expression *build_cast( TypeValueNode * arg, ExpressionNode *expr_node );
     230Expression *build_fieldSel( ExpressionNode *expr_node, VarRefNode *member );
     231Expression *build_pfieldSel( ExpressionNode *expr_node, VarRefNode *member );
    169232Expression *build_addressOf( ExpressionNode *expr_node );
    170 Expression *build_sizeOfexpr( ExpressionNode *expr_node );
    171 Expression *build_sizeOftype( DeclarationNode *decl_node );
    172 Expression *build_alignOfexpr( ExpressionNode *expr_node );
    173 Expression *build_alignOftype( DeclarationNode *decl_node );
    174 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member );
     233Expression *build_sizeOf( ExpressionNode *expr_node );
     234Expression *build_alignOf( ExpressionNode *expr_node );
     235Expression *build_offsetOf( TypeValueNode * arg, VarRefNode *member );
    175236Expression *build_and( ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
    176237Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind );
     
    181242Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 );
    182243Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
    183 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node );
    184 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node );
    185 Expression *build_tuple( ExpressionNode * expr_node = 0 );
    186 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node );
     244Expression *build_attr( VarRefNode *var, ExpressionNode * expr = 0 );
     245Expression *build_tuple( ExpressionNode * expr = 0 );
     246Expression *build_func( ExpressionNode * function, ExpressionNode * expr );
    187247Expression *build_range( ExpressionNode * low, ExpressionNode *high );
    188 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand );
    189 Expression *build_valexpr( StatementNode *s );
    190 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids );
     248
     249//##############################################################################
     250
     251class AsmExprNode : public ExpressionNode {
     252  public:
     253        AsmExprNode();
     254        AsmExprNode( ExpressionNode *inout, ConstantNode *constraint, ExpressionNode *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
     255        virtual ~AsmExprNode() { delete inout; delete constraint; delete operand; }
     256
     257        virtual AsmExprNode *clone() const { return new AsmExprNode( *this ); }
     258        virtual Expression *build() const;
     259
     260        virtual void print( std::ostream &os, int indent = 0) const;
     261        virtual void printOneLine( std::ostream &os, int indent = 0) const;
     262
     263        ExpressionNode *get_inout() const { return inout; };
     264        void set_inout( ExpressionNode *newValue ) { inout = newValue; }
     265
     266        ConstantNode *get_constraint() const { return constraint; };
     267        void set_constraint( ConstantNode *newValue ) { constraint = newValue; }
     268
     269        ExpressionNode *get_operand() const { return operand; };
     270        void set_operand( ExpressionNode *newValue ) { operand = newValue; }
     271  private:
     272        ExpressionNode *inout;
     273        ConstantNode *constraint;
     274        ExpressionNode *operand;
     275};
     276
     277//##############################################################################
     278
     279class LabelNode : public ExpressionNode {
     280  public:
     281        virtual Expression *build() const { return NULL; }
     282        virtual LabelNode *clone() const { return new LabelNode( *this ); }
     283
     284        virtual void print( std::ostream &os, int indent = 0) const;
     285        virtual void printOneLine( std::ostream &os, int indent = 0) const;
     286
     287        const std::list< Label > &get_labels() const { return labels; };
     288        void append_label( std::string *label ) { labels.push_back( *label ); delete label; }
     289  private:
     290        std::list< Label > labels;
     291};
     292
     293//##############################################################################
     294
     295class ForCtlExprNode : public ExpressionNode {
     296  public:
     297        ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError );
     298        ForCtlExprNode( const ForCtlExprNode &other );
     299        ~ForCtlExprNode();
     300
     301        StatementNode *get_init() const { return init; }
     302        ExpressionNode *get_condition() const { return condition; }
     303        ExpressionNode *get_change() const { return change; }
     304
     305        virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); }
     306        virtual Expression *build() const;
     307
     308        virtual void print( std::ostream &os, int indent = 0 ) const;
     309        virtual void printOneLine( std::ostream &os, int indent = 0 ) const;
     310  private:
     311        StatementNode *init;
     312        ExpressionNode *condition;
     313        ExpressionNode *change;
     314};
     315
     316//##############################################################################
     317
     318class ValofExprNode : public ExpressionNode {
     319  public:
     320        ValofExprNode();
     321        ValofExprNode( StatementNode *s = 0 );
     322        ValofExprNode( const ValofExprNode &other );
     323        ~ValofExprNode();
     324
     325        virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); }
     326
     327        StatementNode *get_body() const { return body; }
     328        void print( std::ostream &os, int indent = 0 ) const;
     329        void printOneLine( std::ostream &os, int indent = 0 ) const;
     330        Expression *build() const;
     331
     332  private:
     333        StatementNode *body;
     334};
    191335
    192336//##############################################################################
     
    238382        static DeclarationNode *newBuiltinType( BuiltinType );
    239383
    240         DeclarationNode();
    241         ~DeclarationNode();
    242         DeclarationNode *clone() const;
    243 
    244384        DeclarationNode *addQualifiers( DeclarationNode *);
    245385        DeclarationNode *copyStorageClasses( DeclarationNode *);
     
    257397        DeclarationNode *addNewArray( DeclarationNode *array );
    258398        DeclarationNode *addParamList( DeclarationNode *list );
    259         DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions
     399        DeclarationNode *addIdList( DeclarationNode *list );       // old-style functions
    260400        DeclarationNode *addInitializer( InitializerNode *init );
    261401
     
    266406        DeclarationNode *cloneBaseType( DeclarationNode *newdecl );
    267407
    268         DeclarationNode *appendList( DeclarationNode *node ) {
    269                 return (DeclarationNode *)set_last( node );
    270         }
    271 
     408        DeclarationNode *appendList( DeclarationNode * );
     409
     410        DeclarationNode *clone() const;
    272411        void print( std::ostream &os, int indent = 0 ) const;
    273412        void printList( std::ostream &os, int indent = 0 ) const;
     
    278417        bool get_hasEllipsis() const;
    279418        const std::string &get_name() const { return name; }
    280         LinkageSpec::Spec get_linkage() const { return linkage; }
     419        LinkageSpec::Type get_linkage() const { return linkage; }
    281420        DeclarationNode *extractAggregate() const;
    282421        ExpressionNode *get_enumeratorValue() const { return enumeratorValue; }
     
    284423        bool get_extension() const { return extension; }
    285424        DeclarationNode *set_extension( bool exten ) { extension = exten; return this; }
    286   private:
    287         // StorageClass buildStorageClass() const;
    288         // bool buildFuncSpecifier( StorageClass key ) const;
     425
     426        DeclarationNode();
     427        ~DeclarationNode();
     428  private:
     429        StorageClass buildStorageClass() const;
     430        bool buildFuncSpecifier( StorageClass key ) const;
    289431
    290432        TypeData *type;
    291433        std::string name;
    292         // std::list< StorageClass > storageClasses;
    293         StorageClass storageClass;
    294         bool isInline, isNoreturn;
     434        std::list< StorageClass > storageClasses;
    295435        std::list< std::string > attributes;
    296436        ExpressionNode *bitfieldWidth;
     
    298438        InitializerNode *initializer;
    299439        bool hasEllipsis;
    300         LinkageSpec::Spec linkage;
     440        LinkageSpec::Type linkage;
    301441        bool extension = false;
    302         std::string error;
    303442
    304443        static UniqueName anonymous;
    305444}; // DeclarationNode
    306445
    307 Type *buildType( TypeData *type );
    308 
    309 //##############################################################################
    310 
    311 class StatementNode final : public ParseNode {
    312   public:
    313         StatementNode() { stmt = nullptr; }
    314         StatementNode( Statement *stmt ) : stmt( stmt ) {}
     446//##############################################################################
     447
     448class StatementNode : public ParseNode {
     449  public:
     450        enum Type { Exp,   If,        Switch,  Case,    Default,  Choose,   Fallthru,
     451                                While, Do,        For,
     452                                Goto,  Continue,  Break,   Return,  Throw,
     453                                Try,   Catch,     Finally, Asm,
     454                                Decl
     455        };
     456
     457        StatementNode();
     458        StatementNode( const std::string *name );
     459        StatementNode( Type t, ExpressionNode *control = 0, StatementNode *block = 0 );
     460        StatementNode( Type t, std::string *target );
    315461        StatementNode( DeclarationNode *decl );
    316         virtual ~StatementNode() {}
    317 
    318         virtual StatementNode *clone() const final { assert( false ); return nullptr; }
    319         Statement *build() const { return const_cast<StatementNode*>(this)->stmt.release(); }
    320 
    321         virtual StatementNode *add_label( const std::string * name ) {
    322                 stmt->get_labels().emplace_back( *name );
    323                 delete name;
    324                 return this;
    325         }
    326 
    327         virtual StatementNode *append_last_case( StatementNode * );
    328 
    329         virtual void print( std::ostream &os, int indent = 0 ) {}
    330         virtual void printList( std::ostream &os, int indent = 0 ) {}
    331   private:
    332         std::unique_ptr<Statement> stmt;
     462
     463        ~StatementNode();
     464
     465        static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
     466
     467        StatementNode *set_block( StatementNode *b ) {  block = b; return this; }
     468        StatementNode *get_block() const { return block; }
     469
     470        void set_control( ExpressionNode *c ) { control = c; }
     471        ExpressionNode *get_control() const { return control; }
     472
     473        StatementNode::Type get_type() const { return type; }
     474
     475        StatementNode *add_label( const std::string * );
     476        const std::list<std::string> &get_labels() const { return labels; }
     477
     478        void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; }
     479        void setCatchRest( bool newVal ) { isCatchRest = newVal; }
     480
     481        std::string get_target() const;
     482
     483        // StatementNode *add_controlexp( ExpressionNode * );
     484        StatementNode *append_block( StatementNode * );
     485        StatementNode *append_last_case( StatementNode * );
     486
     487        void print( std::ostream &os, int indent = 0) const;
     488        virtual StatementNode *clone() const;
     489        virtual Statement *build() const;
     490  private:
     491        static const char *StType[];
     492        Type type;
     493        ExpressionNode *control;
     494        StatementNode *block;
     495        std::list<std::string> labels;
     496        std::string *target;                            // target label for jump statements
     497        DeclarationNode *decl;
     498        bool isCatchRest;
    333499}; // StatementNode
    334500
    335 Statement *build_expr( ExpressionNode *ctl );
    336 
    337 struct ForCtl {
    338         ForCtl( ExpressionNode *expr, ExpressionNode *condition, ExpressionNode *change ) :
    339                 init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {}
    340         ForCtl( DeclarationNode *decl, ExpressionNode *condition, ExpressionNode *change ) :
    341                 init( new StatementNode( decl ) ), condition( condition ), change( change ) {}
    342 
    343         StatementNode *init;
    344         ExpressionNode *condition;
    345         ExpressionNode *change;
    346 };
    347 
    348 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt );
    349 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt );
    350 Statement *build_case( ExpressionNode *ctl );
    351 Statement *build_default();
    352 Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind = false );
    353 Statement *build_for( ForCtl *forctl, StatementNode *stmt );
    354 Statement *build_branch( std::string identifier, BranchStmt::Type kind );
    355 Statement *build_computedgoto( ExpressionNode *ctl );
    356 Statement *build_return( ExpressionNode *ctl );
    357 Statement *build_throw( ExpressionNode *ctl );
    358 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt );
    359 Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny = false );
    360 Statement *build_finally( StatementNode *stmt );
    361 Statement *build_compound( StatementNode *first );
    362 Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ExpressionNode *clobber = 0, LabelNode *gotolabels = 0 );
    363 
    364 //##############################################################################
     501//##############################################################################
     502
     503class CompoundStmtNode : public StatementNode {
     504  public:
     505        CompoundStmtNode();
     506        CompoundStmtNode( const std::string * );
     507        CompoundStmtNode( StatementNode * );
     508        ~CompoundStmtNode();
     509
     510        void add_statement( StatementNode * );
     511
     512        void print( std::ostream &os, int indent = 0 ) const;
     513        virtual Statement *build() const;
     514  private:
     515        StatementNode *first, *last;
     516};
     517
     518//##############################################################################
     519
     520class AsmStmtNode : public StatementNode {
     521  public:
     522        AsmStmtNode( Type, bool voltile, ConstantNode *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ConstantNode *clobber = 0, LabelNode *gotolabels = 0 );
     523        ~AsmStmtNode();
     524
     525        void print( std::ostream &os, int indent = 0 ) const;
     526        Statement *build() const;
     527  private:
     528        bool voltile;
     529        ConstantNode *instruction;
     530        ExpressionNode *output, *input;
     531        ConstantNode *clobber;
     532        std::list< Label > gotolabels;
     533};
     534
     535//##############################################################################
     536
     537class InitializerNode : public ParseNode {
     538  public:
     539        InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode *des = 0 );
     540        InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 );
     541        ~InitializerNode();
     542
     543        ExpressionNode *get_expression() const { return expr; }
     544
     545        InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; }
     546        ExpressionNode *get_designators() const { return designator; }
     547
     548        InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }
     549        bool get_maybeConstructed() const { return maybeConstructed; }
     550
     551        InitializerNode *next_init() const { return kids; }
     552
     553        void print( std::ostream &os, int indent = 0 ) const;
     554        void printOneLine( std::ostream & ) const;
     555
     556        virtual Initializer *build() const;
     557  private:
     558        ExpressionNode *expr;
     559        bool aggregate;
     560        ExpressionNode *designator; // may be list
     561        InitializerNode *kids;
     562        bool maybeConstructed;
     563};
     564
     565//##############################################################################
     566
     567class CompoundLiteralNode : public ExpressionNode {
     568  public:
     569        CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids );
     570        CompoundLiteralNode( const CompoundLiteralNode &type );
     571        ~CompoundLiteralNode();
     572
     573        virtual CompoundLiteralNode *clone() const;
     574
     575        DeclarationNode *get_type() const { return type; }
     576        CompoundLiteralNode *set_type( DeclarationNode *t ) { type = t; return this; }
     577
     578        InitializerNode *get_initializer() const { return kids; }
     579        CompoundLiteralNode *set_initializer( InitializerNode *k ) { kids = k; return this; }
     580
     581        void print( std::ostream &os, int indent = 0 ) const;
     582        void printOneLine( std::ostream &os, int indent = 0 ) const;
     583
     584        virtual Expression *build() const;
     585  private:
     586        DeclarationNode *type;
     587        InitializerNode *kids;
     588};
    365589
    366590template< typename SynTreeType, typename NodeType >
    367 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
     591void buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) {
    368592        SemanticError errors;
    369         std::back_insert_iterator< std::list< SynTreeType * > > out( outputList );
     593        std::back_insert_iterator< std::list< SynTreeType *> > out( outputList );
    370594        const NodeType *cur = firstNode;
    371595
    372596        while ( cur ) {
    373597                try {
    374 //                      SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) );
    375                         SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) );
     598//                      SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::result_of<decltype(&NodeType::build)(NodeType)>::type>( cur ) );
     599                        SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::pointer_traits<decltype(cur->build())>::element_type>( cur ) );
    376600                        if ( result ) {
    377601                                *out++ = result;
     
    381605                        errors.append( e );
    382606                } // try
    383                 cur = dynamic_cast< NodeType * >( cur->get_next() );
     607                cur = dynamic_cast< NodeType *>( cur->get_link() );
    384608        } // while
    385609        if ( ! errors.isEmpty() ) {
     
    390614// in DeclarationNode.cc
    391615void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList );
    392 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList );
     616void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList );
    393617void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList );
    394 
    395 template< typename SynTreeType, typename NodeType >
    396 void buildMoveList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
    397         buildList(firstNode, outputList);
    398         delete firstNode;
    399 }
    400 
    401618
    402619#endif // PARSENODE_H
Note: See TracChangeset for help on using the changeset viewer.