Changeset 7880579


Ignore:
Timestamp:
Aug 16, 2016, 8:59:49 AM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
0da3e2c, 13e3b50, 7527e63
Parents:
b1848a0
Message:

more refactoring of parser code

Location:
src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 15 14:30:25 2016
    13 // Update Count     : 172
     12// Last Modified On : Mon Aug 15 20:48:55 2016
     13// Update Count     : 178
    1414//
    1515
     
    4949        newnode->name = name;
    5050        newnode->storageClasses = storageClasses;
    51 //PAB   newnode->bitfieldWidth = maybeClone( bitfieldWidth );
    5251        newnode->bitfieldWidth = bitfieldWidth;
    5352        newnode->hasEllipsis = hasEllipsis;
    5453        newnode->initializer = initializer;
    55         newnode->next = maybeClone( next );
     54        newnode->set_next( maybeClone( get_next() ) );
    5655        newnode->linkage = linkage;
    5756        return newnode;
     
    284283        newnode->type->array->dimension = size;
    285284        newnode->type->array->isStatic = isStatic;
    286         if ( newnode->type->array->dimension == 0 || dynamic_cast<ConstantExpr *>( newnode->type->array->dimension->build() ) ) {
     285        if ( newnode->type->array->dimension == 0 || dynamic_cast< ConstantExpr * >( newnode->type->array->dimension->build() ) ) {
    287286                newnode->type->array->isVarLen = false;
    288287        } else {
     
    776775void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ) {
    777776        SemanticError errors;
    778         std::back_insert_iterator< std::list< Declaration *> > out( outputList );
     777        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
    779778        const DeclarationNode *cur = firstNode;
    780779        while ( cur ) {
     
    794793                        errors.append( e );
    795794                } // try
    796                 cur = dynamic_cast<DeclarationNode *>( cur->get_next() );
     795                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    797796        } // while
    798797        if ( ! errors.isEmpty() ) {
     
    801800}
    802801
    803 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList ) {
     802void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) {
    804803        SemanticError errors;
    805         std::back_insert_iterator< std::list< DeclarationWithType *> > out( outputList );
     804        std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
    806805        const DeclarationNode *cur = firstNode;
    807806        while ( cur ) {
     
    817816                        Declaration *decl = cur->build();
    818817                        if ( decl ) {
    819                                 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType *>( decl ) ) {
     818                                if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    820819                                        *out++ = dwt;
    821                                 } else if ( StructDecl *agg = dynamic_cast< StructDecl *>( decl ) ) {
     820                                } else if ( StructDecl *agg = dynamic_cast< StructDecl * >( decl ) ) {
    822821                                        StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
    823822                                        *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
    824823                                        delete agg;
    825                                 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl *>( decl ) ) {
     824                                } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * >( decl ) ) {
    826825                                        UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
    827826                                        *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
     
    831830                        errors.append( e );
    832831                } // try
    833                 cur = dynamic_cast< DeclarationNode *>( cur->get_next() );
     832                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    834833        } // while
    835834        if ( ! errors.isEmpty() ) {
     
    838837}
    839838
    840 void buildTypeList( const DeclarationNode *firstNode, std::list< Type *> &outputList ) {
     839void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) {
    841840        SemanticError errors;
    842         std::back_insert_iterator< std::list< Type *> > out( outputList );
     841        std::back_insert_iterator< std::list< Type * > > out( outputList );
    843842        const DeclarationNode *cur = firstNode;
    844843        while ( cur ) {
     
    848847                        errors.append( e );
    849848                } // try
    850                 cur = dynamic_cast< DeclarationNode *>( cur->get_next() );
     849                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    851850        } // while
    852851        if ( ! errors.isEmpty() ) {
  • src/Parser/ExpressionNode.cc

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 15 14:30:42 2016
    13 // Update Count     : 490
     12// Last Modified On : Tue Aug 16 00:09:20 2016
     13// Update Count     : 495
    1414//
    1515
     
    3232using namespace std;
    3333
    34 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.name ), extension( other.extension ) {}
     34ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.get_name() ), extension( other.extension ) {}
    3535
    3636//##############################################################################
     
    166166} // build_constantStr
    167167
    168 //##############################################################################
    169 
    170168NameExpr * build_varref( const string *name, bool labelp ) {
    171169        return new NameExpr( *name, nullptr );
    172170}
    173 
    174 //##############################################################################
    175171
    176172static const char *OperName[] = {
     
    184180};
    185181
    186 //##############################################################################
    187 
    188182Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) {
    189183        Type *targetType = decl_node->buildType();
    190184        if ( dynamic_cast< VoidType * >( targetType ) ) {
    191185                delete targetType;
    192                 return new CastExpr( maybeBuild<Expression>(expr_node) );
     186                return new CastExpr( maybeBuild< Expression >(expr_node) );
    193187        } else {
    194                 return new CastExpr( maybeBuild<Expression>(expr_node), targetType );
     188                return new CastExpr( maybeBuild< Expression >(expr_node), targetType );
    195189        } // if
    196190}
    197191
    198192Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member ) {
    199         UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeBuild<Expression>(expr_node) );
     193        UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeBuild< Expression >(expr_node) );
    200194        delete member;
    201195        return ret;
     
    204198Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member ) {
    205199        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    206         deref->get_args().push_back( maybeBuild<Expression>(expr_node) );
     200        deref->get_args().push_back( maybeBuild< Expression >(expr_node) );
    207201        UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref );
    208202        delete member;
     
    211205
    212206Expression *build_addressOf( ExpressionNode *expr_node ) {
    213                 return new AddressExpr( maybeBuild<Expression>(expr_node) );
     207                return new AddressExpr( maybeBuild< Expression >(expr_node) );
    214208}
    215209Expression *build_sizeOfexpr( ExpressionNode *expr_node ) {
    216         return new SizeofExpr( maybeBuild<Expression>(expr_node) );
     210        return new SizeofExpr( maybeBuild< Expression >(expr_node) );
    217211}
    218212Expression *build_sizeOftype( DeclarationNode *decl_node ) {
     
    220214}
    221215Expression *build_alignOfexpr( ExpressionNode *expr_node ) {
    222         return new AlignofExpr( maybeBuild<Expression>(expr_node) );
     216        return new AlignofExpr( maybeBuild< Expression >(expr_node) );
    223217}
    224218Expression *build_alignOftype( DeclarationNode *decl_node ) {
     
    230224
    231225Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) {
    232         return new LogicalExpr( notZeroExpr( maybeBuild<Expression>(expr_node1) ), notZeroExpr( maybeBuild<Expression>(expr_node2) ), kind );
     226        return new LogicalExpr( notZeroExpr( maybeBuild< Expression >(expr_node1) ), notZeroExpr( maybeBuild< Expression >(expr_node2) ), kind );
    233227}
    234228
    235229Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) {
    236         std::list<Expression *> args;
    237         args.push_back( maybeBuild<Expression>(expr_node) );
     230        std::list< Expression * > args;
     231        args.push_back( maybeBuild< Expression >(expr_node) );
    238232        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    239233}
    240234Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) {
    241         std::list<Expression *> args;
    242         args.push_back( new AddressExpr( maybeBuild<Expression>(expr_node) ) );
     235        std::list< Expression * > args;
     236        args.push_back( new AddressExpr( maybeBuild< Expression >(expr_node) ) );
    243237        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    244238}
    245239Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
    246         std::list<Expression *> args;
    247         args.push_back( maybeBuild<Expression>(expr_node1) );
    248         args.push_back( maybeBuild<Expression>(expr_node2) );
     240        std::list< Expression * > args;
     241        args.push_back( maybeBuild< Expression >(expr_node1) );
     242        args.push_back( maybeBuild< Expression >(expr_node2) );
    249243        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    250244}
    251245Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
    252         std::list<Expression *> args;
    253         args.push_back( new AddressExpr( maybeBuild<Expression>(expr_node1) ) );
    254         args.push_back( maybeBuild<Expression>(expr_node2) );
     246        std::list< Expression * > args;
     247        args.push_back( new AddressExpr( maybeBuild< Expression >(expr_node1) ) );
     248        args.push_back( maybeBuild< Expression >(expr_node2) );
    255249        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    256250}
    257251
    258252Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) {
    259         return new ConditionalExpr( notZeroExpr( maybeBuild<Expression>(expr_node1) ), maybeBuild<Expression>(expr_node2), maybeBuild<Expression>(expr_node3) );
     253        return new ConditionalExpr( notZeroExpr( maybeBuild< Expression >(expr_node1) ), maybeBuild< Expression >(expr_node2), maybeBuild< Expression >(expr_node3) );
    260254}
    261255
    262256Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
    263         return new CommaExpr( maybeBuild<Expression>(expr_node1), maybeBuild<Expression>(expr_node2) );
     257        return new CommaExpr( maybeBuild< Expression >(expr_node1), maybeBuild< Expression >(expr_node2) );
    264258}
    265259
    266260Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) {
    267         return new AttrExpr( var, maybeBuild<Expression>(expr_node) );
     261        return new AttrExpr( var, maybeBuild< Expression >(expr_node) );
    268262}
    269263Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) {
     
    278272
    279273Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
    280         std::list<Expression *> args;
     274        std::list< Expression * > args;
    281275
    282276        buildList( expr_node, args );
    283         return new UntypedExpr( maybeBuild<Expression>(function), args, nullptr );
     277        return new UntypedExpr( maybeBuild< Expression >(function), args, nullptr );
    284278}
    285279
    286280Expression *build_range( ExpressionNode * low, ExpressionNode *high ) {
    287         Expression *low_cexpr = maybeBuild<Expression>( low );
    288         Expression *high_cexpr = maybeBuild<Expression>( high );
     281        Expression *low_cexpr = maybeBuild< Expression >( low );
     282        Expression *high_cexpr = maybeBuild< Expression >( high );
    289283        return new RangeExpr( low_cexpr, high_cexpr );
    290284}
    291285
    292 //##############################################################################
    293 
    294286Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) {
    295         return new AsmExpr( maybeBuild< Expression >( inout ), constraint, maybeBuild<Expression>(operand) );
    296 }
    297 
    298 //##############################################################################
    299 
    300 //void LabelNode::print( std::ostream &os, int indent ) const {}
    301 
    302 //void LabelNode::printOneLine( std::ostream &os, int indent ) const {}
    303 
    304 //##############################################################################
     287        return new AsmExpr( maybeBuild< Expression >( inout ), constraint, maybeBuild< Expression >(operand) );
     288}
    305289
    306290Expression *build_valexpr( StatementNode *s ) {
    307         return new UntypedValofExpr( maybeBuild<Statement>(s), nullptr );
    308 }
    309 
    310 //##############################################################################
    311 
     291        return new UntypedValofExpr( maybeBuild< Statement >(s), nullptr );
     292}
    312293Expression *build_typevalue( DeclarationNode *decl ) {
    313294        return new TypeExpr( decl->buildType() );
    314295}
    315296
    316 //##############################################################################
    317 
    318297Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) {
    319         Declaration * newDecl = maybeBuild<Declaration>(decl_node); // compound literal type
     298        Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type
    320299        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
    321                 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild<Initializer>(kids) );
     300                return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild< Initializer >(kids) );
    322301        // these types do not have associated type information
    323302        } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl )  ) {
    324                 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild<Initializer>(kids) );
     303                return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild< Initializer >(kids) );
    325304        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl )  ) {
    326                 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild<Initializer>(kids) );
     305                return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild< Initializer >(kids) );
    327306        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl )  ) {
    328                 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild<Initializer>(kids) );
     307                return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild< Initializer >(kids) );
    329308        } else {
    330309                assert( false );
  • src/Parser/InitializerNode.cc

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 13:20:24 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 13 18:55:11 2016
    13 // Update Count     : 18
     12// Last Modified On : Mon Aug 15 18:27:02 2016
     13// Update Count     : 20
    1414//
    1515
     
    2525        : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) {
    2626        if ( aggrp )
    27                 kids = dynamic_cast< InitializerNode *>( get_next() );
     27                kids = dynamic_cast< InitializerNode * >( get_next() );
    2828
    2929        if ( kids != 0 )
     
    3737
    3838        if ( aggrp )
    39                 kids = dynamic_cast< InitializerNode *>( get_next() );
     39                kids = dynamic_cast< InitializerNode * >( get_next() );
    4040
    4141        if ( kids != 0 )
     
    8282                //assert( next_init() != 0 );
    8383
    84                 std::list< Initializer *> initlist;
    85                 buildList<Initializer, InitializerNode>( next_init(), initlist );
     84                std::list< Initializer * > initlist;
     85                buildList< Initializer, InitializerNode >( next_init(), initlist );
    8686
    87                 std::list< Expression *> designlist;
     87                std::list< Expression * > designlist;
    8888
    8989                if ( designator != 0 ) {
    90                         buildList<Expression, ExpressionNode>( designator, designlist );
     90                        buildList< Expression, ExpressionNode >( designator, designlist );
    9191                } // if
    9292
    9393                return new ListInit( initlist, designlist, maybeConstructed );
    9494        } else {
    95                 std::list< Expression *> designators;
     95                std::list< Expression * > designators;
    9696
    9797                if ( designator != 0 )
    98                         buildList<Expression, ExpressionNode>( designator, designators );
     98                        buildList< Expression, ExpressionNode >( designator, designators );
    9999
    100100                if ( get_expression() != 0)
    101                         return new SingleInit( maybeBuild<Expression>( get_expression() ), designators, maybeConstructed );
     101                        return new SingleInit( maybeBuild< Expression >( get_expression() ), designators, maybeConstructed );
    102102        } // if
    103103
  • src/Parser/ParseNode.cc

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 13:26:29 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 15 14:49:06 2016
    13 // Update Count     : 99
     12// Last Modified On : Tue Aug 16 08:42:29 2016
     13// Update Count     : 107
    1414//
    1515
     
    1717using namespace std;
    1818
    19 // Builder
    2019int ParseNode::indent_by = 4;
    2120
    22 ParseNode::ParseNode() : next( 0 ) {};
    23 ParseNode::ParseNode( const string *name ) : name( *name ), next( 0 ) { delete name; }
    24 ParseNode::ParseNode( const string &name ) : name( name ), next( 0 ) { }
     21ParseNode::ParseNode() : next( nullptr ) {};
     22ParseNode::ParseNode( const string *name ) : name( *name ), next( nullptr ) { delete name; }
     23ParseNode::ParseNode( const string &name ) : name( name ), next( nullptr ) { }
    2524
    2625ParseNode::~ParseNode() {
     
    4140}
    4241
    43 void ParseNode::print( std::ostream &os, int indent ) const {}
    44 
    45 
    4642void ParseNode::printList( std::ostream &os, int indent ) const {
    4743        print( os, indent );
  • src/Parser/ParseNode.h

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 15 14:52:12 2016
    13 // Update Count     : 512
     12// Last Modified On : Tue Aug 16 08:37:47 2016
     13// Update Count     : 527
    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"
    2827#include "SynTree/Statement.h"
    29 //#include "SynTree/Declaration.h"
     28#include "SynTree/Label.h"
     29#include "Common/utility.h"
    3030#include "Common/UniqueName.h"
    31 #include "SynTree/Label.h"
    3231
    3332class StatementNode;
     
    3736class InitializerNode;
    3837
    39 // Builder
     38//##############################################################################
     39
    4040class ParseNode {
    4141  public:
     
    4444        ParseNode( const std::string & );                                       // for copy constructing subclasses
    4545        virtual ~ParseNode();
     46        virtual ParseNode *clone() const { assert( false ); return nullptr; };
    4647
    4748        ParseNode *get_next() const { return next; }
     
    5051        ParseNode *set_last( ParseNode * );
    5152
    52         virtual ParseNode *clone() const { return 0; };
    53 
    5453        const std::string &get_name() const { return name; }
    5554        void set_name( const std::string &newValue ) { name = newValue; }
    5655
    57         virtual void print( std::ostream &os, int indent = 0 ) const;
     56        virtual void print( std::ostream &os, int indent = 0 ) const {}
    5857        virtual void printList( std::ostream &os, int indent = 0 ) const;
    59 
    60         ParseNode &operator,( ParseNode & );
    61   protected:
     58  private:
     59        static int indent_by;
     60
     61        ParseNode *next;
    6262        std::string name;
    63         static int indent_by;
    64         ParseNode *next;
    65 };
     63}; // ParseNode
    6664
    6765//##############################################################################
     
    104102        virtual ~ExpressionNode() {}
    105103
    106         virtual ExpressionNode *clone() const { return 0; }
     104        virtual ExpressionNode *clone() const { assert( false ); return nullptr; }
    107105
    108106        bool get_extension() const { return extension; }
     
    119117
    120118template< typename T >
    121 struct maybeBuild_t<Expression, T> {
     119struct maybeBuild_t< Expression, T > {
    122120        static inline Expression * doit( const T *orig ) {
    123121                if ( orig ) {
     
    126124                        return p;
    127125                } else {
    128                         return 0;
     126                        return nullptr;
    129127                } // if
    130128        }
     
    228226        static DeclarationNode *newBuiltinType( BuiltinType );
    229227
     228        DeclarationNode();
     229        ~DeclarationNode();
     230        DeclarationNode *clone() const;
     231
    230232        DeclarationNode *addQualifiers( DeclarationNode *);
    231233        DeclarationNode *copyStorageClasses( DeclarationNode *);
     
    254256        DeclarationNode *appendList( DeclarationNode * );
    255257
    256         DeclarationNode *clone() const;
    257258        void print( std::ostream &os, int indent = 0 ) const;
    258259        void printList( std::ostream &os, int indent = 0 ) const;
     
    269270        bool get_extension() const { return extension; }
    270271        DeclarationNode *set_extension( bool exten ) { extension = exten; return this; }
    271 
    272         DeclarationNode();
    273         ~DeclarationNode();
    274272  private:
    275273        StorageClass buildStorageClass() const;
     
    351349void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
    352350        SemanticError errors;
    353         std::back_insert_iterator< std::list< SynTreeType *> > out( outputList );
     351        std::back_insert_iterator< std::list< SynTreeType * > > out( outputList );
    354352        const NodeType *cur = firstNode;
    355353
    356354        while ( cur ) {
    357355                try {
    358 //                      SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::result_of<decltype(&NodeType::build)(NodeType)>::type>( cur ) );
    359                         SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::pointer_traits<decltype(cur->build())>::element_type>( cur ) );
     356//                      SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) );
     357                        SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) );
    360358                        if ( result ) {
    361359                                *out++ = result;
     
    365363                        errors.append( e );
    366364                } // try
    367                 cur = dynamic_cast< NodeType *>( cur->get_next() );
     365                cur = dynamic_cast< NodeType * >( cur->get_next() );
    368366        } // while
    369367        if ( ! errors.isEmpty() ) {
     
    374372// in DeclarationNode.cc
    375373void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList );
    376 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList );
     374void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList );
    377375void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList );
    378376
  • src/Parser/Parser.cc

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 14:54:28 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar 21 18:04:47 2016
    13 // Update Count     : 5
     12// Last Modified On : Mon Aug 15 17:44:22 2016
     13// Update Count     : 7
    1414//
    1515
  • src/Parser/Parser.h

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 14:56:50 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 14:58:56 2015
    13 // Update Count     : 2
     12// Last Modified On : Mon Aug 15 16:33:22 2016
     13// Update Count     : 3
    1414//
    1515
  • src/Parser/StatementNode.cc

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 15 14:40:05 2016
    13 // Update Count     : 317
     12// Last Modified On : Mon Aug 15 20:47:11 2016
     13// Update Count     : 322
    1414//
    1515
     
    3232                if ( agg ) {
    3333                        StatementNode *nextStmt = new StatementNode( new DeclStmt( noLabels, maybeBuild< Declaration >( decl ) ) );
    34                         next = nextStmt;
     34                        set_next( nextStmt );
    3535                        if ( decl->get_next() ) {
    36                                 next->set_next( new StatementNode( dynamic_cast<DeclarationNode *>(decl->get_next()) ) );
     36                                get_next()->set_next( new StatementNode( dynamic_cast< DeclarationNode * >(decl->get_next()) ) );
    3737                                decl->set_next( 0 );
    3838                        } // if
    3939                } else {
    4040                        if ( decl->get_next() ) {
    41                                 next = new StatementNode( dynamic_cast<DeclarationNode *>( decl->get_next() ) );
     41                                set_next(new StatementNode( dynamic_cast< DeclarationNode * >( decl->get_next() ) ) );
    4242                                decl->set_next( 0 );
    4343                        } // if
    4444                        agg = decl;
    4545                } // if
    46                 stmt = new DeclStmt( noLabels, maybeBuild<Declaration>(agg) );
     46                stmt = new DeclStmt( noLabels, maybeBuild< Declaration >(agg) );
    4747        } else {
    4848                assert( false );
     
    5454        // find end of list and maintain previous pointer
    5555        for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) {
    56                 StatementNode *node = dynamic_cast<StatementNode *>(curr);
     56                StatementNode *node = dynamic_cast< StatementNode * >(curr);
    5757                assert( node );
    58                 assert( dynamic_cast<CaseStmt *>(node->stmt) );
     58                assert( dynamic_cast< CaseStmt * >(node->stmt) );
    5959                prev = curr;
    6060        } // for
    6161        // convert from StatementNode list to Statement list
    62         StatementNode *node = dynamic_cast<StatementNode *>(prev);
    63         std::list<Statement *> stmts;
     62        StatementNode *node = dynamic_cast< StatementNode * >(prev);
     63        std::list< Statement * > stmts;
    6464        buildList( stmt, stmts );
    6565        // splice any new Statements to end of current Statements
    66         CaseStmt * caseStmt = dynamic_cast<CaseStmt *>(node->stmt);
     66        CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt);
    6767        caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts );
    6868        return this;
     
    8080Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {
    8181        Statement *thenb, *elseb = 0;
    82         std::list<Statement *> branches;
    83         buildList<Statement, StatementNode>( then_stmt, branches );
     82        std::list< Statement * > branches;
     83        buildList< Statement, StatementNode >( then_stmt, branches );
    8484        assert( branches.size() == 1 );
    8585        thenb = branches.front();
    8686
    8787        if ( else_stmt ) {
    88                 std::list<Statement *> branches;
    89                 buildList<Statement, StatementNode>( else_stmt, branches );
     88                std::list< Statement * > branches;
     89                buildList< Statement, StatementNode >( else_stmt, branches );
    9090                assert( branches.size() == 1 );
    9191                elseb = branches.front();
    9292        } // if
    93         return new IfStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), thenb, elseb );
     93        return new IfStmt( noLabels, notZeroExpr( maybeBuild< Expression >(ctl) ), thenb, elseb );
    9494}
    9595
    9696Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) {
    97         std::list<Statement *> branches;
    98         buildList<Statement, StatementNode>( stmt, branches );
     97        std::list< Statement * > branches;
     98        buildList< Statement, StatementNode >( stmt, branches );
    9999        assert( branches.size() >= 0 );                                         // size == 0 for switch (...) {}, i.e., no declaration or statements
    100         return new SwitchStmt( noLabels, maybeBuild<Expression>(ctl), branches );
     100        return new SwitchStmt( noLabels, maybeBuild< Expression >(ctl), branches );
    101101}
    102102Statement *build_case( ExpressionNode *ctl ) {
    103         std::list<Statement *> branches;
    104         return new CaseStmt( noLabels, maybeBuild<Expression>(ctl), branches );
     103        std::list< Statement * > branches;
     104        return new CaseStmt( noLabels, maybeBuild< Expression >(ctl), branches );
    105105}
    106106Statement *build_default() {
    107         std::list<Statement *> branches;
     107        std::list< Statement * > branches;
    108108        return new CaseStmt( noLabels, nullptr, branches, true );
    109109}
    110110
    111111Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) {
    112         std::list<Statement *> branches;
    113         buildList<Statement, StatementNode>( stmt, branches );
     112        std::list< Statement * > branches;
     113        buildList< Statement, StatementNode >( stmt, branches );
    114114        assert( branches.size() == 1 );
    115         return new WhileStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), branches.front(), kind );
     115        return new WhileStmt( noLabels, notZeroExpr( maybeBuild< Expression >(ctl) ), branches.front(), kind );
    116116}
    117117
    118118Statement *build_for( ForCtl *forctl, StatementNode *stmt ) {
    119         std::list<Statement *> branches;
    120         buildList<Statement, StatementNode>( stmt, branches );
     119        std::list< Statement * > branches;
     120        buildList< Statement, StatementNode >( stmt, branches );
    121121        assert( branches.size() == 1 );
    122122
    123         std::list<Statement *> init;
     123        std::list< Statement * > init;
    124124        if ( forctl->init != 0 ) {
    125125                buildList( forctl->init, init );
     
    128128        Expression *cond = 0;
    129129        if ( forctl->condition != 0 )
    130                 cond = notZeroExpr( maybeBuild<Expression>(forctl->condition) );
     130                cond = notZeroExpr( maybeBuild< Expression >(forctl->condition) );
    131131
    132132        Expression *incr = 0;
    133133        if ( forctl->change != 0 )
    134                 incr = maybeBuild<Expression>(forctl->change);
     134                incr = maybeBuild< Expression >(forctl->change);
    135135
    136136        delete forctl;
     
    142142}
    143143Statement *build_computedgoto( ExpressionNode *ctl ) {
    144         return new BranchStmt( noLabels, maybeBuild<Expression>(ctl), BranchStmt::Goto );
     144        return new BranchStmt( noLabels, maybeBuild< Expression >(ctl), BranchStmt::Goto );
    145145}
    146146
    147147Statement *build_return( ExpressionNode *ctl ) {
    148         std::list<Expression *> exps;
     148        std::list< Expression * > exps;
    149149        buildList( ctl, exps );
    150150        return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr );
    151151}
    152152Statement *build_throw( ExpressionNode *ctl ) {
    153         std::list<Expression *> exps;
     153        std::list< Expression * > exps;
    154154        buildList( ctl, exps );
    155155        return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr, true );
     
    157157
    158158Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) {
    159         std::list<Statement *> branches;
    160         buildList<Statement, StatementNode>( catch_stmt, branches );
    161         CompoundStmt *tryBlock = dynamic_cast<CompoundStmt *>(maybeBuild<Statement>(try_stmt));
     159        std::list< Statement * > branches;
     160        buildList< Statement, StatementNode >( catch_stmt, branches );
     161        CompoundStmt *tryBlock = dynamic_cast< CompoundStmt * >(maybeBuild< Statement >(try_stmt));
    162162        assert( tryBlock );
    163         FinallyStmt *finallyBlock = dynamic_cast<FinallyStmt *>(maybeBuild<Statement>(finally_stmt) );
     163        FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeBuild< Statement >(finally_stmt) );
    164164        return new TryStmt( noLabels, tryBlock, branches, finallyBlock );
    165165}
    166166Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny ) {
    167         std::list<Statement *> branches;
    168         buildList<Statement, StatementNode>( stmt, branches );
     167        std::list< Statement * > branches;
     168        buildList< Statement, StatementNode >( stmt, branches );
    169169        assert( branches.size() == 1 );
    170         return new CatchStmt( noLabels, maybeBuild<Declaration>(decl), branches.front(), catchAny );
     170        return new CatchStmt( noLabels, maybeBuild< Declaration >(decl), branches.front(), catchAny );
    171171}
    172172Statement *build_finally( StatementNode *stmt ) {
    173         std::list<Statement *> branches;
    174         buildList<Statement, StatementNode>( stmt, branches );
     173        std::list< Statement * > branches;
     174        buildList< Statement, StatementNode >( stmt, branches );
    175175        assert( branches.size() == 1 );
    176         return new FinallyStmt( noLabels, dynamic_cast<CompoundStmt *>( branches.front() ) );
     176        return new FinallyStmt( noLabels, dynamic_cast< CompoundStmt * >( branches.front() ) );
    177177}
    178178
  • src/Parser/TypeData.cc

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 13 18:38:41 2016
    13 // Update Count     : 59
     12// Last Modified On : Mon Aug 15 20:48:52 2016
     13// Update Count     : 62
    1414//
    1515
     
    182182                break;
    183183          case Array:
    184 //PAB           newtype->array->dimension = maybeClone( array->dimension );
    185184                newtype->array->dimension = array->dimension;
    186185                newtype->array->isVarLen = array->isVarLen;
     
    489488                                decl = new FunctionDecl( name, sc, linkage, buildFunction(), body, isInline, isNoreturn );
    490489                        } else {
    491                                 // std::list<Label> ls;
    492                                 decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list<Label>() ), isInline, isNoreturn );
     490                                // std::list< Label > ls;
     491                                decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list< Label >() ), isInline, isNoreturn );
    493492                        } // if
    494493                } else {
     
    909908        buildList( enumeration->constants, ret->get_members() );
    910909        std::list< Declaration * >::iterator members = ret->get_members().begin();
    911         for ( const DeclarationNode *cur = enumeration->constants; cur != NULL; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ), ++members ) {
     910        for ( const DeclarationNode *cur = enumeration->constants; cur != NULL; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    912911                if ( cur->get_enumeratorValue() != NULL ) {
    913                         ObjectDecl *member = dynamic_cast<ObjectDecl *>(*members);
     912                        ObjectDecl *member = dynamic_cast< ObjectDecl * >(*members);
    914913                        member->set_init( new SingleInit( maybeBuild< Expression >( cur->get_enumeratorValue() ), std::list< Expression * >() ) );
    915914                } // if
  • src/Parser/TypedefTable.cc

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 13 16:57:30 2016
    13 // Update Count     : 24
     12// Last Modified On : Mon Aug 15 18:24:42 2016
     13// Update Count     : 25
    1414//
    1515
     
    6464                tableType::iterator curPos = table.find( identifier );
    6565                if ( curPos == table.end()) {
    66                         list<Entry> newList;
     66                        list< Entry > newList;
    6767                        newList.push_front( newEntry );
    6868                        table[identifier] = newList;
    6969                } else {
    70                         list<Entry>::iterator listPos = (*curPos ).second.begin();
     70                        list< Entry >::iterator listPos = (*curPos ).second.begin();
    7171                        while ( listPos != (*curPos ).second.end() && listPos->scope > scope ) {
    7272                                listPos++;
     
    127127        debugPrint( "Leaving scope " << currentScope << endl );
    128128        for ( tableType::iterator i = table.begin(); i != table.end(); ) {
    129                 list<Entry> &declList = (*i).second;
     129                list< Entry > &declList = (*i).second;
    130130                while ( ! declList.empty() && declList.front().scope == currentScope ) {
    131131                        declList.pop_front();
     
    157157        for ( tableType::const_iterator i = table.begin(); i != table.end(); i++) {
    158158                debugPrint( (*i ).first << ": " );
    159                 list<Entry> declList = (*i).second;
    160                 for ( list<Entry>::const_iterator j = declList.begin(); j != declList.end(); j++ ) {
     159                list< Entry > declList = (*i).second;
     160                for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) {
    161161                        debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " );
    162162                }
  • src/Parser/TypedefTable.h

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 13 16:59:56 2016
    13 // Update Count     : 27
     12// Last Modified On : Mon Aug 15 18:25:04 2016
     13// Update Count     : 28
    1414//
    1515
     
    3939        };
    4040
    41         typedef std::map<std::string, std::list<Entry> > tableType;
     41        typedef std::map< std::string, std::list< Entry > > tableType;
    4242        tableType table;
    4343
  • src/main.cc

    rb1848a0 r7880579  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug  6 16:17:41 2016
    13 // Update Count     : 210
     12// Last Modified On : Mon Aug 15 17:58:57 2016
     13// Update Count     : 220
    1414//
    1515
    1616#include <iostream>
    1717#include <fstream>
    18 #include <cstdlib>
    19 #include <cstdio>
    2018#include <getopt.h>
    2119#include "Parser/Parser.h"
    22 #include "Parser/ParseNode.h"
    23 #include "Parser/LinkageSpec.h"
    2420#include "SynTree/Declaration.h"
    2521#include "SynTree/Visitor.h"
     
    4339#include "InitTweak/GenInit.h"
    4440#include "InitTweak/FixInit.h"
    45 //#include "Explain/GenProlog.h"
    46 //#include "Try/Visit.h"
    4741
    4842#include "Common/SemanticError.h"
     
    384378        std::list< Declaration * > decls;
    385379        if ( noprotop ) {
    386                 filter( translationUnit.begin(), translationUnit.end(),
    387                                 std::back_inserter( decls ), notPrelude );
     380                filter( translationUnit.begin(), translationUnit.end(), std::back_inserter( decls ), notPrelude );
    388381        } else {
    389382                decls = translationUnit;
Note: See TracChangeset for help on using the changeset viewer.