Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    rf271bdd r5fcba14  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug  4 09:39:40 2018
    13 // Update Count     : 853
     12// Last Modified On : Mon Nov 27 17:33:35 2017
     13// Update Count     : 824
    1414//
    1515
     
    6868        }
    6969
    70         virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {}
    71         virtual void printList( std::ostream & os, int indent = 0 ) const {
     70        virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {}
     71        virtual void printList( std::ostream &os, int indent = 0 ) const {
    7272                print( os, indent );
    7373                if ( next ) next->print( os, indent );
     
    7777
    7878        ParseNode * next = nullptr;
    79         const std::string * name = nullptr;
     79        std::string * name = nullptr;
    8080        CodeLocation location = yylloc;
    8181}; // ParseNode
     
    8787        InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode * des = nullptr );
    8888        InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr );
    89         InitializerNode( bool isDelete );
    9089        ~InitializerNode();
    9190        virtual InitializerNode * clone() const { assert( false ); return nullptr; }
     
    9998        bool get_maybeConstructed() const { return maybeConstructed; }
    10099
    101         bool get_isDelete() const { return isDelete; }
    102 
    103100        InitializerNode * next_init() const { return kids; }
    104101
    105         void print( std::ostream & os, int indent = 0 ) const;
     102        void print( std::ostream &os, int indent = 0 ) const;
    106103        void printOneLine( std::ostream & ) const;
    107104
     
    113110        InitializerNode * kids;
    114111        bool maybeConstructed;
    115         bool isDelete;
    116112}; // InitializerNode
    117113
     
    127123        ExpressionNode * set_extension( bool exten ) { extension = exten; return this; }
    128124
    129         virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override {
    130                 os << expr.get();
    131         }
    132         void printOneLine( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {}
    133 
    134         Expression *get_expr() const { return expr.get(); }
     125        virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {
     126                os << expr.get() << std::endl;
     127        }
     128        void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {}
     129
    135130        template<typename T>
    136131        bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr.get()); }
     
    172167};
    173168
    174 Expression * build_constantInteger( std::string & str ); // these 4 routines modify the string
    175 Expression * build_constantFloat( std::string & str );
    176 Expression * build_constantChar( std::string & str );
    177 Expression * build_constantStr( std::string & str );
     169Expression * build_constantInteger( std::string &str );
     170Expression * build_constantFloat( std::string &str );
     171Expression * build_constantChar( std::string &str );
     172Expression * build_constantStr( std::string &str );
    178173Expression * build_field_name_FLOATING_FRACTIONconstant( const std::string & str );
    179174Expression * build_field_name_FLOATING_DECIMALconstant( const std::string & str );
     
    184179
    185180Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
    186 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node );
    187181Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
    188182Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member );
     
    215209        enum Length { Short, Long, LongLong, NoLength };
    216210        static const char * lengthNames[];
    217         enum Aggregate { Struct, Union, Exception, Trait, Coroutine, Monitor, Thread, NoAggregate };
     211        enum Aggregate { Struct, Union, Trait, Coroutine, Monitor, Thread, NoAggregate };
    218212        static const char * aggregateNames[];
    219213        enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass };
     
    231225        static DeclarationNode * newBuiltinType( BuiltinType );
    232226        static DeclarationNode * newForall( DeclarationNode * );
    233         static DeclarationNode * newFromTypedef( const std::string * );
    234         static DeclarationNode * newFromGlobalScope();
    235         static DeclarationNode * newQualifiedType( DeclarationNode *, DeclarationNode * );
    236         static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
     227        static DeclarationNode * newFromTypedef( std::string * );
     228        static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false );
    237229        static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    238         static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body );
    239         static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    240         static DeclarationNode * newName( const std::string * );
    241         static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params );
    242         static DeclarationNode * newTypeParam( TypeClass, const std::string * );
     230        static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants, bool body );
     231        static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode * constant );
     232        static DeclarationNode * newName( std::string * );
     233        static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode * params );
     234        static DeclarationNode * newTypeParam( TypeClass, std::string * );
    243235        static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts );
    244236        static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params );
    245         static DeclarationNode * newTypeDecl( const std::string * name, DeclarationNode * typeParams );
     237        static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode * typeParams );
    246238        static DeclarationNode * newPointer( DeclarationNode * qualifiers, OperKinds kind );
    247239        static DeclarationNode * newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic );
     
    250242        static DeclarationNode * newTuple( DeclarationNode * members );
    251243        static DeclarationNode * newTypeof( ExpressionNode * expr );
    252         static DeclarationNode * newAttr( const std::string *, ExpressionNode * expr ); // @ attributes
    253         static DeclarationNode * newAttr( const std::string *, DeclarationNode * type ); // @ attributes
    254         static DeclarationNode * newAttribute( const std::string *, ExpressionNode * expr = nullptr ); // gcc attributes
     244        static DeclarationNode * newAttr( std::string *, ExpressionNode * expr ); // @ attributes
     245        static DeclarationNode * newAttr( std::string *, DeclarationNode * type ); // @ attributes
     246        static DeclarationNode * newAttribute( std::string *, ExpressionNode * expr = nullptr ); // gcc attributes
    255247        static DeclarationNode * newAsmStmt( StatementNode * stmt ); // gcc external asm statement
    256         static DeclarationNode * newStaticAssert( ExpressionNode * condition, Expression * message );
    257248
    258249        DeclarationNode();
     
    271262        DeclarationNode * addBitfield( ExpressionNode * size );
    272263        DeclarationNode * addVarArgs();
    273         DeclarationNode * addFunctionBody( StatementNode * body, ExpressionNode * with = nullptr );
     264        DeclarationNode * addFunctionBody( StatementNode * body, StatementNode * with = nullptr );
    274265        DeclarationNode * addOldDeclList( DeclarationNode * list );
    275266        DeclarationNode * setBase( TypeData * newType );
     
    291282        }
    292283
    293         virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override;
    294         virtual void printList( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override;
     284        virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override;
     285        virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override;
    295286
    296287        Declaration * build() const;
    297288        Type * buildType() const;
    298289
     290        bool get_hasEllipsis() const;
    299291        LinkageSpec::Spec get_linkage() const { return linkage; }
    300292        DeclarationNode * extractAggregate() const;
     
    304296        bool get_extension() const { return extension; }
    305297        DeclarationNode * set_extension( bool exten ) { extension = exten; return this; }
    306 
    307         bool get_inLine() const { return inLine; }
    308         DeclarationNode * set_inLine( bool inL ) { inLine = inL; return this; }
    309298  public:
    310299        DeclarationNode * get_last() { return (DeclarationNode *)ParseNode::get_last(); }
     
    325314        Attr_t attr;
    326315
    327         struct StaticAssert_t {
    328                 ExpressionNode * condition;
    329                 Expression * message;
    330         };
    331         StaticAssert_t assert;
    332 
    333         BuiltinType builtin = NoBuiltinType;
    334 
    335         TypeData * type = nullptr;
    336 
    337         bool inLine = false;
     316        BuiltinType builtin;
     317
     318        TypeData * type;
     319
    338320        Type::FuncSpecifiers funcSpecs;
    339321        Type::StorageClasses storageClasses;
    340322
    341         ExpressionNode * bitfieldWidth = nullptr;
     323        ExpressionNode * bitfieldWidth;
    342324        std::unique_ptr<ExpressionNode> enumeratorValue;
    343         bool hasEllipsis = false;
     325        bool hasEllipsis;
    344326        LinkageSpec::Spec linkage;
    345         Expression * asmName = nullptr;
     327        Expression *asmName;
    346328        std::list< Attribute * > attributes;
    347         InitializerNode * initializer = nullptr;
     329        InitializerNode * initializer;
    348330        bool extension = false;
    349331        std::string error;
    350         StatementNode * asmStmt = nullptr;
     332        StatementNode * asmStmt;
    351333
    352334        static UniqueName anonymous;
     
    382364        virtual StatementNode * append_last_case( StatementNode * );
    383365
    384         virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override {
     366        virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {
    385367                os << stmt.get() << std::endl;
    386368        }
     
    391373Statement * build_expr( ExpressionNode * ctl );
    392374
    393 struct IfCtrl {
    394         IfCtrl( DeclarationNode * decl, ExpressionNode * condition ) :
     375struct IfCtl {
     376        IfCtl( DeclarationNode * decl, ExpressionNode * condition ) :
    395377                init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {}
    396378
     
    399381};
    400382
    401 struct ForCtrl {
    402         ForCtrl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :
     383struct ForCtl {
     384        ForCtl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :
    403385                init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {}
    404         ForCtrl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :
     386        ForCtl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :
    405387                init( new StatementNode( decl ) ), condition( condition ), change( change ) {}
    406388
     
    410392};
    411393
    412 Expression * build_if_control( IfCtrl * ctl, std::list< Statement * > & init );
    413 Statement * build_if( IfCtrl * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
    414 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt );
     394Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
     395Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt );
    415396Statement * build_case( ExpressionNode * ctl );
    416397Statement * build_default();
    417 Statement * build_while( IfCtrl * ctl, StatementNode * stmt );
    418 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt );
    419 Statement * build_for( ForCtrl * forctl, StatementNode * stmt );
     398Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind = false );
     399Statement * build_for( ForCtl * forctl, StatementNode * stmt );
    420400Statement * build_branch( BranchStmt::Type kind );
    421401Statement * build_branch( std::string * identifier, BranchStmt::Type kind );
     
    429409Statement * build_finally( StatementNode * stmt );
    430410Statement * build_compound( StatementNode * first );
    431 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
    432 Statement * build_directive( std::string * directive );
     411Statement * build_asmstmt( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
    433412WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when );
    434413WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing );
     
    440419
    441420template< typename SynTreeType, typename NodeType, template< typename, typename...> class Container, typename... Args >
    442 void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > & outputList ) {
    443         SemanticErrorException errors;
     421void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > &outputList ) {
     422        SemanticError errors;
    444423        std::back_insert_iterator< Container< SynTreeType *, Args... > > out( outputList );
    445424        const NodeType * cur = firstNode;
     
    454433                                assertf(false, "buildList unknown type");
    455434                        } // if
    456                 } catch( SemanticErrorException & e ) {
     435                } catch( SemanticError &e ) {
     436                        e.set_location( cur->location );
    457437                        errors.append( e );
    458438                } // try
     
    465445
    466446// in DeclarationNode.cc
    467 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList );
    468 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList );
    469 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList );
     447void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList );
     448void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList );
     449void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList );
    470450
    471451template< typename SynTreeType, typename NodeType >
    472 void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > & outputList ) {
     452void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {
    473453        buildList( firstNode, outputList );
    474454        delete firstNode;
Note: See TracChangeset for help on using the changeset viewer.