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

more refactoring of parser code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.