Ignore:
Timestamp:
Aug 19, 2016, 2:42:04 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
e85a8631
Parents:
03da511 (diff), ac71a86 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ctor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r03da511 r04cdd9b  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  7 09:37:16 2016
    13 // Update Count     : 333
     12// Last Modified On : Thu Aug 18 23:48:37 2016
     13// Update Count     : 542
    1414//
    1515
     
    2222#include <memory>
    2323
    24 #include "Common/utility.h"
    2524#include "Parser/LinkageSpec.h"
    2625#include "SynTree/Type.h"
    2726#include "SynTree/Expression.h"
    28 //#include "SynTree/Declaration.h"
     27#include "SynTree/Statement.h"
     28#include "SynTree/Label.h"
     29#include "Common/utility.h"
    2930#include "Common/UniqueName.h"
    30 #include "SynTree/Label.h"
    3131
    3232class StatementNode;
    3333class CompoundStmtNode;
    3434class DeclarationNode;
     35class ExpressionNode;
    3536class InitializerNode;
    3637
    37 // Builder
     38//##############################################################################
     39
    3840class ParseNode {
    3941  public:
    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; };
     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        }
    5159
    5260        const std::string &get_name() const { return name; }
    5361        void set_name( const std::string &newValue ) { name = newValue; }
    5462
    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:
     63        virtual void print( std::ostream &os, int indent = 0 ) const {}
     64        virtual void printList( std::ostream &os, int indent = 0 ) const {}
     65  private:
     66        static int indent_by;
     67
     68        ParseNode *next = nullptr;
    6069        std::string name;
    61         static int indent_by;
    62         ParseNode *next;
    63 };
    64 
    65 ParseNode *mkList( ParseNode & );
    66 
    67 //##############################################################################
    68 
    69 class ExpressionNode : public ParseNode {
     70}; // ParseNode
     71
     72//##############################################################################
     73
     74class InitializerNode : public ParseNode {
    7075  public:
    71         ExpressionNode();
    72         ExpressionNode( const std::string * );
     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
     105class 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 ) {}
    73109        ExpressionNode( const ExpressionNode &other );
    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 );
     110        virtual ~ExpressionNode() {}
     111        virtual ExpressionNode *clone() const { assert( false ); return nullptr; }
     112
    81113        bool get_extension() const { return extension; }
    82114        ExpressionNode *set_extension( bool exten ) { extension = exten; return this; }
    83115
    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;
     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(); }
    90125  private:
    91         ExpressionNode *argName = 0;
    92126        bool extension = false;
     127        std::unique_ptr<Expression> expr;
    93128};
    94129
    95130template< typename T >
    96 struct maybeBuild_t<Expression, T> {
     131struct maybeBuild_t< Expression, T > {
    97132        static inline Expression * doit( const T *orig ) {
    98133                if ( orig ) {
     
    101136                        return p;
    102137                } else {
    103                         return 0;
     138                        return nullptr;
    104139                } // if
    105140        }
    106 };
    107 
    108 //##############################################################################
    109 
    110 // NullExprNode is used in tuples as a place-holder where a tuple component is omitted e.g., [ 2, , 3 ]
    111 class 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 
    125 class 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 
    143 ConstantNode *build_constantInteger( std::string &str );
    144 ConstantNode *build_constantFloat( std::string &str );
    145 ConstantNode *build_constantChar( std::string &str );
    146 ConstantNode *build_constantStr( std::string &str );
    147 
    148 //##############################################################################
    149 
    150 class 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 
    167 class 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 
    183 class 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 
    202 class 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;
    216141};
    217142
     
    227152};
    228153
    229 Expression *build_cast( TypeValueNode * arg, ExpressionNode *expr_node );
    230 Expression *build_fieldSel( ExpressionNode *expr_node, VarRefNode *member );
    231 Expression *build_pfieldSel( ExpressionNode *expr_node, VarRefNode *member );
     154struct LabelNode {
     155        std::list< Label > labels;
     156};
     157
     158Expression *build_constantInteger( const std::string &str );
     159Expression *build_constantFloat( const std::string &str );
     160Expression *build_constantChar( const std::string &str );
     161ConstantExpr *build_constantStr( const std::string &str );
     162
     163NameExpr *build_varref( const std::string *name, bool labelp = false );
     164Expression *build_typevalue( DeclarationNode *decl );
     165
     166Expression *build_cast( DeclarationNode * decl_node, ExpressionNode *expr_node );
     167Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member );
     168Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member );
    232169Expression *build_addressOf( ExpressionNode *expr_node );
    233 Expression *build_sizeOf( ExpressionNode *expr_node );
    234 Expression *build_alignOf( ExpressionNode *expr_node );
    235 Expression *build_offsetOf( TypeValueNode * arg, VarRefNode *member );
     170Expression *build_sizeOfexpr( ExpressionNode *expr_node );
     171Expression *build_sizeOftype( DeclarationNode *decl_node );
     172Expression *build_alignOfexpr( ExpressionNode *expr_node );
     173Expression *build_alignOftype( DeclarationNode *decl_node );
     174Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member );
    236175Expression *build_and( ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
    237176Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind );
     
    242181Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 );
    243182Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
    244 Expression *build_attr( VarRefNode *var, ExpressionNode * expr = 0 );
    245 Expression *build_tuple( ExpressionNode * expr = 0 );
    246 Expression *build_func( ExpressionNode * function, ExpressionNode * expr );
     183Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node );
     184Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node );
     185Expression *build_tuple( ExpressionNode * expr_node = 0 );
     186Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node );
    247187Expression *build_range( ExpressionNode * low, ExpressionNode *high );
    248 
    249 //##############################################################################
    250 
    251 class 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 
    279 class 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 
    295 class 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 
    318 class 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 };
     188Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand );
     189Expression *build_valexpr( StatementNode *s );
     190Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids );
    335191
    336192//##############################################################################
     
    382238        static DeclarationNode *newBuiltinType( BuiltinType );
    383239
     240        DeclarationNode();
     241        ~DeclarationNode();
     242        DeclarationNode *clone() const;
     243
    384244        DeclarationNode *addQualifiers( DeclarationNode *);
    385245        DeclarationNode *copyStorageClasses( DeclarationNode *);
     
    397257        DeclarationNode *addNewArray( DeclarationNode *array );
    398258        DeclarationNode *addParamList( DeclarationNode *list );
    399         DeclarationNode *addIdList( DeclarationNode *list );       // old-style functions
     259        DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions
    400260        DeclarationNode *addInitializer( InitializerNode *init );
    401261
     
    406266        DeclarationNode *cloneBaseType( DeclarationNode *newdecl );
    407267
    408         DeclarationNode *appendList( DeclarationNode * );
    409 
    410         DeclarationNode *clone() const;
     268        DeclarationNode *appendList( DeclarationNode *node ) {
     269                return (DeclarationNode *)set_last( node );
     270        }
     271
    411272        void print( std::ostream &os, int indent = 0 ) const;
    412273        void printList( std::ostream &os, int indent = 0 ) const;
     
    417278        bool get_hasEllipsis() const;
    418279        const std::string &get_name() const { return name; }
    419         LinkageSpec::Type get_linkage() const { return linkage; }
     280        LinkageSpec::Spec get_linkage() const { return linkage; }
    420281        DeclarationNode *extractAggregate() const;
    421282        ExpressionNode *get_enumeratorValue() const { return enumeratorValue; }
     
    423284        bool get_extension() const { return extension; }
    424285        DeclarationNode *set_extension( bool exten ) { extension = exten; return this; }
    425 
    426         DeclarationNode();
    427         ~DeclarationNode();
    428286  private:
    429         StorageClass buildStorageClass() const;
    430         bool buildFuncSpecifier( StorageClass key ) const;
     287        // StorageClass buildStorageClass() const;
     288        // bool buildFuncSpecifier( StorageClass key ) const;
    431289
    432290        TypeData *type;
    433291        std::string name;
    434         std::list< StorageClass > storageClasses;
     292        // std::list< StorageClass > storageClasses;
     293        StorageClass storageClass;
     294        bool isInline, isNoreturn;
    435295        std::list< std::string > attributes;
    436296        ExpressionNode *bitfieldWidth;
     
    438298        InitializerNode *initializer;
    439299        bool hasEllipsis;
    440         LinkageSpec::Type linkage;
     300        LinkageSpec::Spec linkage;
    441301        bool extension = false;
     302        std::string error;
    442303
    443304        static UniqueName anonymous;
    444305}; // DeclarationNode
    445306
    446 //##############################################################################
    447 
    448 class StatementNode : public ParseNode {
     307Type *buildType( TypeData *type );
     308
     309//##############################################################################
     310
     311class StatementNode final : public ParseNode {
    449312  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 );
     313        StatementNode() { stmt = nullptr; }
     314        StatementNode( Statement *stmt ) : stmt( stmt ) {}
    461315        StatementNode( DeclarationNode *decl );
    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;
     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 ) {}
    490331  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;
     332        std::unique_ptr<Statement> stmt;
    499333}; // StatementNode
    500334
    501 //##############################################################################
    502 
    503 class 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 
    520 class 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 
    537 class 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 
    567 class 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 };
     335Statement *build_expr( ExpressionNode *ctl );
     336
     337struct 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
     348Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt );
     349Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt );
     350Statement *build_case( ExpressionNode *ctl );
     351Statement *build_default();
     352Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind = false );
     353Statement *build_for( ForCtl *forctl, StatementNode *stmt );
     354Statement *build_branch( std::string identifier, BranchStmt::Type kind );
     355Statement *build_computedgoto( ExpressionNode *ctl );
     356Statement *build_return( ExpressionNode *ctl );
     357Statement *build_throw( ExpressionNode *ctl );
     358Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt );
     359Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny = false );
     360Statement *build_finally( StatementNode *stmt );
     361Statement *build_compound( StatementNode *first );
     362Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ExpressionNode *clobber = 0, LabelNode *gotolabels = 0 );
     363
     364//##############################################################################
    589365
    590366template< typename SynTreeType, typename NodeType >
    591 void buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) {
     367void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
    592368        SemanticError errors;
    593         std::back_insert_iterator< std::list< SynTreeType *> > out( outputList );
     369        std::back_insert_iterator< std::list< SynTreeType * > > out( outputList );
    594370        const NodeType *cur = firstNode;
    595371
    596372        while ( cur ) {
    597373                try {
    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 ) );
     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 ) );
    600376                        if ( result ) {
    601377                                *out++ = result;
     
    605381                        errors.append( e );
    606382                } // try
    607                 cur = dynamic_cast< NodeType *>( cur->get_link() );
     383                cur = dynamic_cast< NodeType * >( cur->get_next() );
    608384        } // while
    609385        if ( ! errors.isEmpty() ) {
     
    614390// in DeclarationNode.cc
    615391void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList );
    616 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList );
     392void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList );
    617393void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList );
     394
     395template< typename SynTreeType, typename NodeType >
     396void buildMoveList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
     397        buildList(firstNode, outputList);
     398        delete firstNode;
     399}
     400
    618401
    619402#endif // PARSENODE_H
Note: See TracChangeset for help on using the changeset viewer.