Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r25bca42 r033ff37  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun  6 16:17:18 2018
    13 // Update Count     : 843
     12// Last Modified On : Thu Jul 25 22:17:10 2019
     13// Update Count     : 876
    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 );
     
    103103        InitializerNode * next_init() const { return kids; }
    104104
    105         void print( std::ostream &os, int indent = 0 ) const;
     105        void print( std::ostream & os, int indent = 0 ) const;
    106106        void printOneLine( std::ostream & ) const;
    107107
     
    127127        ExpressionNode * set_extension( bool exten ) { extension = exten; return this; }
    128128
    129         virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {
    130                 os << expr.get() << std::endl;
    131         }
    132         void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {}
     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 {}
    133133
    134134        template<typename T>
     
    136136
    137137        Expression * build() const { return const_cast<ExpressionNode *>(this)->expr.release(); }
     138
     139        std::unique_ptr<Expression> expr;                                       // public because of lifetime implications
    138140  private:
    139141        bool extension = false;
    140         std::unique_ptr<Expression> expr;
    141142}; // ExpressionNode
    142143
     
    205206class DeclarationNode : public ParseNode {
    206207  public:
    207         // These enumerations must harmonize with their names.
    208         enum BasicType { Void, Bool, Char, Int, Float, Double, LongDouble, Int128, Float80, Float128, NoBasicType };
     208        // These enumerations must harmonize with their names in DeclarationNode.cc.
     209        enum BasicType { Void, Bool, Char, Int, Int128,
     210                                         Float, Double, LongDouble, uuFloat80, uuFloat128,
     211                                         uFloat16, uFloat32, uFloat32x, uFloat64, uFloat64x, uFloat128, uFloat128x, NoBasicType };
    209212        static const char * basicTypeNames[];
    210         enum ComplexType { Complex, Imaginary, NoComplexType };
     213        enum ComplexType { Complex, NoComplexType, Imaginary }; // Imaginary unsupported => parse, but make invisible and print error message
    211214        static const char * complexTypeNames[];
    212215        enum Signedness { Signed, Unsigned, NoSignedness };
     
    218221        enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass };
    219222        static const char * typeClassNames[];
    220         enum BuiltinType { Valist, Zero, One, NoBuiltinType };
     223        enum BuiltinType { Valist, AutoType, Zero, One, NoBuiltinType };
    221224        static const char * builtinTypeNames[];
    222225
     
    231234        static DeclarationNode * newForall( DeclarationNode * );
    232235        static DeclarationNode * newFromTypedef( const std::string * );
     236        static DeclarationNode * newFromGlobalScope();
     237        static DeclarationNode * newQualifiedType( DeclarationNode *, DeclarationNode * );
    233238        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
    234239        static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
     
    246251        static DeclarationNode * newBitfield( ExpressionNode * size );
    247252        static DeclarationNode * newTuple( DeclarationNode * members );
    248         static DeclarationNode * newTypeof( ExpressionNode * expr );
    249         static DeclarationNode * newAttr( const std::string *, ExpressionNode * expr ); // @ attributes
    250         static DeclarationNode * newAttr( const std::string *, DeclarationNode * type ); // @ attributes
     253        static DeclarationNode * newTypeof( ExpressionNode * expr, bool basetypeof = false );
    251254        static DeclarationNode * newAttribute( const std::string *, ExpressionNode * expr = nullptr ); // gcc attributes
    252255        static DeclarationNode * newAsmStmt( StatementNode * stmt ); // gcc external asm statement
     
    288291        }
    289292
    290         virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override;
    291         virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override;
     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;
    292295
    293296        Declaration * build() const;
     
    301304        bool get_extension() const { return extension; }
    302305        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; }
    303309  public:
    304310        DeclarationNode * get_last() { return (DeclarationNode *)ParseNode::get_last(); }
     
    325331        StaticAssert_t assert;
    326332
    327         BuiltinType builtin;
    328 
    329         TypeData * type;
    330 
     333        BuiltinType builtin = NoBuiltinType;
     334
     335        TypeData * type = nullptr;
     336
     337        bool inLine = false;
    331338        Type::FuncSpecifiers funcSpecs;
    332339        Type::StorageClasses storageClasses;
    333340
    334         ExpressionNode * bitfieldWidth;
     341        ExpressionNode * bitfieldWidth = nullptr;
    335342        std::unique_ptr<ExpressionNode> enumeratorValue;
    336         bool hasEllipsis;
     343        bool hasEllipsis = false;
    337344        LinkageSpec::Spec linkage;
    338         Expression * asmName;
     345        Expression * asmName = nullptr;
    339346        std::list< Attribute * > attributes;
    340         InitializerNode * initializer;
     347        InitializerNode * initializer = nullptr;
    341348        bool extension = false;
    342349        std::string error;
    343         StatementNode * asmStmt;
     350        StatementNode * asmStmt = nullptr;
    344351
    345352        static UniqueName anonymous;
     
    375382        virtual StatementNode * append_last_case( StatementNode * );
    376383
    377         virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {
     384        virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override {
    378385                os << stmt.get() << std::endl;
    379386        }
     
    384391Statement * build_expr( ExpressionNode * ctl );
    385392
    386 struct IfCtl {
    387         IfCtl( DeclarationNode * decl, ExpressionNode * condition ) :
     393struct IfCtrl {
     394        IfCtrl( DeclarationNode * decl, ExpressionNode * condition ) :
    388395                init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {}
    389396
     
    392399};
    393400
    394 struct ForCtl {
    395         ForCtl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :
     401struct ForCtrl {
     402        ForCtrl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :
    396403                init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {}
    397         ForCtl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :
     404        ForCtrl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :
    398405                init( new StatementNode( decl ) ), condition( condition ), change( change ) {}
    399406
     
    403410};
    404411
    405 Expression * build_if_control( IfCtl * ctl, std::list< Statement * > & init );
    406 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
     412Expression * build_if_control( IfCtrl * ctl, std::list< Statement * > & init );
     413Statement * build_if( IfCtrl * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
    407414Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt );
    408415Statement * build_case( ExpressionNode * ctl );
    409416Statement * build_default();
    410 Statement * build_while( IfCtl * ctl, StatementNode * stmt );
     417Statement * build_while( IfCtrl * ctl, StatementNode * stmt );
    411418Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt );
    412 Statement * build_for( ForCtl * forctl, StatementNode * stmt );
     419Statement * build_for( ForCtrl * forctl, StatementNode * stmt );
    413420Statement * build_branch( BranchStmt::Type kind );
    414421Statement * build_branch( std::string * identifier, BranchStmt::Type kind );
     
    428435WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when );
    429436WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when );
    430 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt );
     437Statement * build_with( ExpressionNode * exprs, StatementNode * stmt );
    431438
    432439//##############################################################################
    433440
    434441template< typename SynTreeType, typename NodeType, template< typename, typename...> class Container, typename... Args >
    435 void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > &outputList ) {
     442void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > & outputList ) {
    436443        SemanticErrorException errors;
    437444        std::back_insert_iterator< Container< SynTreeType *, Args... > > out( outputList );
     
    447454                                assertf(false, "buildList unknown type");
    448455                        } // if
    449                 } catch( SemanticErrorException &e ) {
     456                } catch( SemanticErrorException & e ) {
    450457                        errors.append( e );
    451458                } // try
     
    458465
    459466// in DeclarationNode.cc
    460 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList );
    461 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList );
    462 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList );
     467void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList );
     468void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList );
     469void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList );
    463470
    464471template< typename SynTreeType, typename NodeType >
    465 void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {
     472void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > & outputList ) {
    466473        buildList( firstNode, outputList );
    467474        delete firstNode;
Note: See TracChangeset for help on using the changeset viewer.