Changeset ddcfb88


Ignore:
Timestamp:
Sep 12, 2016, 10:26:46 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
4ed70597
Parents:
46f1d20 (diff), b6424d9 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r46f1d20 rddcfb88  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 22:30:56 2016
    13 // Update Count     : 327
     12// Last Modified On : Sun Sep 11 09:24:11 2016
     13// Update Count     : 438
    1414//
    1515
     
    3131
    3232// These must remain in the same order as the corresponding DeclarationNode enumerations.
    33 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "" };
     33const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" };
    3434const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" };
    3535const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary",  };
     
    4343extern LinkageSpec::Spec linkage;                                               // defined in parser.yy
    4444
    45 DeclarationNode::DeclarationNode()
    46                 : type( 0 )
    47                 , storageClass( NoStorageClass )
    48                 , isInline( false )
    49                 , isNoreturn( false )
    50                 , bitfieldWidth( 0 )
    51                 , initializer( 0 )
    52                 , hasEllipsis( false )
    53                 , linkage( ::linkage )
    54                 , extension( false )
    55                 , error() {
     45DeclarationNode::DeclarationNode() :
     46                type( 0 ),
     47                storageClass( NoStorageClass ),
     48                isInline( false ),
     49                isNoreturn( false ),
     50                bitfieldWidth( 0 ),
     51                initializer( 0 ),
     52                hasEllipsis( false ),
     53                linkage( ::linkage ),
     54                extension( false ) {
     55        variable.tyClass = DeclarationNode::Type;
     56        variable.assertions = nullptr;
     57
    5658        attr.expr = nullptr;
    5759        attr.type = nullptr;
    58 
    59         variable.tyClass = DeclarationNode::Type;
    60         variable.assertions = nullptr;
    6160}
    6261
     
    390389
    391390void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) {
    392         TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers;
    393 
    394         if ( (qsrc & qdst).any() ) {                                            // common bits between qualifier masks ?
    395                 error = "duplicate qualifier ";
    396                 int j = 0;                                                                              // separator detector
    397                 for ( int i = 0; i < DeclarationNode::NoOfQualifier; i += 1 ) {
    398                         if ( qsrc[i] & qdst[i] ) {                                      // find specific qualifiers in common
    399                                 if ( j > 0 ) error += ", ";
    400                                 error += DeclarationNode::qualifierName[i];
    401                                 j += 1;
     391        TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
     392
     393        if ( (qsrc & qdst).any() ) {                                            // common qualifier ?
     394                for ( int i = 0; i < NoOfQualifier; i += 1 ) {  // find common qualifiers
     395                        if ( qsrc[i] & qdst[i] ) {
     396                                if ( ! error.empty() ) error += ", ";   // separator
     397                                error += string( "duplicate " ) + DeclarationNode::qualifierName[i];
    402398                        } // if
    403399                } // for
    404                 error += " in declaration of ";
    405400        } // if
    406401} // DeclarationNode::checkQualifiers
     402
     403void DeclarationNode::checkStorageClasses( DeclarationNode *q ) {
     404        if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) {
     405                if ( ! error.empty() ) error += ", ";                   // separator
     406                if ( storageClass == q->storageClass ) {                // duplicate qualifier
     407                        error += string( "duplicate " ) + storageName[ storageClass ];
     408                } else {                                                                                // only one storage class
     409                        error += string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ];
     410                        q->storageClass = storageClass;                         // FIX ERROR
     411                } // if
     412                if ( ! q->error.empty() ) error += ", " + q->error;     // separator
     413        } else {
     414                if ( ! error.empty() ) {
     415                        if ( ! q->error.empty() ) error += ", " + q->error; // separator
     416                } else if ( ! q->error.empty() ) error += q->error;
     417        } // if
     418} // DeclarationNode::copyStorageClasses
     419
     420DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
     421        isInline = isInline | q->isInline;
     422        isNoreturn = isNoreturn | q->isNoreturn;
     423        // do not overwrite an existing value with NoStorageClass
     424        if ( q->storageClass != NoStorageClass ) {
     425                assert( storageClass == NoStorageClass || storageClass == q->storageClass );
     426                storageClass = q->storageClass;
     427        } // if
     428        return this;
     429} // DeclarationNode::copyStorageClasses
    407430
    408431DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    409432        if ( q ) {
    410                 copyStorageClasses(q);
     433                checkStorageClasses( q );
     434                copyStorageClasses( q );
    411435                if ( q->type ) {
    412436                        if ( ! type ) {
     
    433457        } // if
    434458        delete q;
    435         return this;
    436 }
    437 
    438 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
    439         isInline = isInline || q->isInline;
    440         isNoreturn = isNoreturn || q->isNoreturn;
    441         if ( storageClass == NoStorageClass ) {
    442                 storageClass = q->storageClass;
    443         } else if ( q->storageClass != NoStorageClass ) {
    444                 q->error = "invalid combination of storage classes in declaration of ";
    445         } // if
    446         if ( error.empty() ) error = q->error;
    447459        return this;
    448460}
     
    504516DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) {
    505517        if ( o ) {
     518                checkStorageClasses( o );
    506519                copyStorageClasses( o );
    507520                if ( o->type ) {
     
    751764        } // if
    752765        newnode->type->forall = maybeClone( type->forall );
     766        assert( storageClass == NoStorageClass );
    753767        newnode->copyStorageClasses( this );
    754768        newnode->name = assign_strptr( newName );
     
    791805        DeclarationNode *newnode = new DeclarationNode;
    792806        newnode->type = maybeClone( type );
     807        assert( storageClass == NoStorageClass );
    793808        newnode->copyStorageClasses( this );
    794809        newnode->name = assign_strptr( newName );
     
    798813DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) {
    799814        if ( o ) {
     815                assert( storageClass == NoStorageClass );
    800816                o->copyStorageClasses( this );
    801817                if ( type ) {
     
    908924
    909925Declaration *DeclarationNode::build() const {
    910         if ( ! error.empty() ) throw SemanticError( error, this );
     926        if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this );
    911927        if ( type ) {
    912928                if ( type->kind == TypeData::Variable ) {
     
    922938                return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
    923939        } // if
    924         throw SemanticError( "invalid function specifier in declaration of ", this );
     940        throw SemanticError( "invalid function specifier ", this );
    925941}
    926942
     
    971987}
    972988
    973 // DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {
    974 //      DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;
    975 //      for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
    976 //        if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers
    977 //        if ( ret != DeclarationNode::NoStorageClass ) {       // already have a valid storage class ?
    978 //                      throw SemanticError( "invalid combination of storage classes in declaration of ", this );
    979 //              } // if
    980 //              ret = *i;
    981 //      } // for
    982 //      return ret;
    983 // }
    984 
    985 // bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {
    986 //      std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );
    987 //   if ( first == storageClasses.end() ) return false; // not found
    988 //      first = std::find( ++first, storageClasses.end(), key ); // found
    989 //   if ( first == storageClasses.end() ) return true;          // not found again
    990 //      throw SemanticError( "duplicate function specifier in declaration of ", this );
    991 // }
    992 
    993989// Local Variables: //
    994990// tab-width: 4 //
  • src/Parser/ParseNode.h

    r46f1d20 rddcfb88  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 21:45:43 2016
    13 // Update Count     : 583
     12// Last Modified On : Sat Sep 10 17:14:37 2016
     13// Update Count     : 589
    1414//
    1515
     
    4141  public:
    4242        ParseNode() {};
    43         ParseNode( const std::string *name ) : name( *name ) { assert( false ); delete name; }
     43        ParseNode( const std::string * name ) : name( * name ) { assert( false ); delete name; }
    4444        ParseNode( const std::string &name ) : name( name ) { assert( false ); }
    4545        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;
     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;
    5252                for ( current = this; current->get_next() != 0; current = current->get_next() );
    5353                return current;
    5454        }
    55         ParseNode *set_last( ParseNode *newlast ) {
     55        ParseNode * set_last( ParseNode * newlast ) {
    5656                if ( newlast != 0 ) get_last()->set_next( newlast );
    5757                return this;
     
    6666        static int indent_by;
    6767
    68         ParseNode *next = nullptr;
     68        ParseNode * next = nullptr;
    6969        std::string name;
    7070}; // ParseNode
     
    7474class InitializerNode : public ParseNode {
    7575  public:
    76         InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode *des = 0 );
    77         InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 );
     76        InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode * des = 0 );
     77        InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = 0 );
    7878        ~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; }
     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; }
    8787        bool get_maybeConstructed() const { return maybeConstructed; }
    8888
    89         InitializerNode *next_init() const { return kids; }
     89        InitializerNode * next_init() const { return kids; }
    9090
    9191        void print( std::ostream &os, int indent = 0 ) const;
    9292        void printOneLine( std::ostream & ) const;
    9393
    94         virtual Initializer *build() const;
     94        virtual Initializer * build() const;
    9595  private:
    96         ExpressionNode *expr;
     96        ExpressionNode * expr;
    9797        bool aggregate;
    98         ExpressionNode *designator;                                                     // may be list
    99         InitializerNode *kids;
     98        ExpressionNode * designator;                                            // may be list
     99        InitializerNode * kids;
    100100        bool maybeConstructed;
    101101}; // InitializerNode
     
    106106  public:
    107107        ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {}
    108         ExpressionNode( Expression * expr, const std::string *name ) : ParseNode( name ), expr( expr ) {}
     108        ExpressionNode( Expression * expr, const std::string * name ) : ParseNode( name ), expr( expr ) {}
    109109        ExpressionNode( const ExpressionNode &other );
    110110        virtual ~ExpressionNode() {}
    111         virtual ExpressionNode *clone() const { return expr ? new ExpressionNode( expr->clone() ) : nullptr; }
     111        virtual ExpressionNode * clone() const { return expr ? new ExpressionNode( expr->clone() ) : nullptr; }
    112112
    113113        bool get_extension() const { return extension; }
    114         ExpressionNode *set_extension( bool exten ) { extension = exten; return this; }
     114        ExpressionNode * set_extension( bool exten ) { extension = exten; return this; }
    115115
    116116        void print( std::ostream &os, int indent = 0 ) const {}
     
    122122        }
    123123
    124         Expression *build() const { return const_cast<ExpressionNode*>(this)->expr.release(); }
     124        Expression * build() const { return const_cast<ExpressionNode*>(this)->expr.release(); }
    125125  private:
    126126        bool extension = false;
     
    130130template< typename T >
    131131struct maybeBuild_t< Expression, T > {
    132         static inline Expression * doit( const T *orig ) {
     132        static inline Expression * doit( const T * orig ) {
    133133                if ( orig ) {
    134                         Expression *p = orig->build();
     134                        Expression * p = orig->build();
    135135                        p->set_extension( orig->get_extension() );
    136136                        return p;
     
    156156};
    157157
    158 Expression *build_constantInteger( const std::string &str );
    159 Expression *build_constantFloat( const std::string &str );
    160 Expression *build_constantChar( const std::string &str );
    161 ConstantExpr *build_constantStr( const std::string &str );
    162 
    163 NameExpr *build_varref( const std::string *name, bool labelp = false );
    164 Expression *build_typevalue( DeclarationNode *decl );
    165 
    166 Expression *build_cast( DeclarationNode * decl_node, ExpressionNode *expr_node );
    167 Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member );
    168 Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member );
    169 Expression *build_addressOf( ExpressionNode *expr_node );
    170 Expression *build_sizeOfexpr( ExpressionNode *expr_node );
    171 Expression *build_sizeOftype( DeclarationNode *decl_node );
    172 Expression *build_alignOfexpr( ExpressionNode *expr_node );
    173 Expression *build_alignOftype( DeclarationNode *decl_node );
    174 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member );
    175 Expression *build_and( ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
    176 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind );
    177 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node );
    178 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node );
    179 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
    180 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
    181 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 );
    182 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
    183 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node );
    184 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node );
    185 Expression *build_tuple( ExpressionNode * expr_node = 0 );
    186 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node );
    187 Expression *build_range( ExpressionNode * low, ExpressionNode *high );
    188 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand );
    189 Expression *build_valexpr( StatementNode *s );
    190 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids );
     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 );
     169Expression * build_addressOf( ExpressionNode * expr_node );
     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 );
     175Expression * build_and( ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
     176Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind );
     177Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node );
     178Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node );
     179Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
     180Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
     181Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 );
     182Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
     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 );
     187Expression * build_range( ExpressionNode * low, ExpressionNode * high );
     188Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand );
     189Expression * build_valexpr( StatementNode * s );
     190Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids );
    191191
    192192//##############################################################################
     
    204204        enum BuiltinType { Valist };
    205205
    206         static const char *qualifierName[];
    207         static const char *storageName[];
    208         static const char *basicTypeName[];
    209         static const char *modifierName[];
    210         static const char *aggregateName[];
    211         static const char *typeClassName[];
    212         static const char *builtinTypeName[];
    213 
    214         static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false );
    215         static DeclarationNode *newQualifier( Qualifier );
    216         static DeclarationNode *newForall( DeclarationNode *);
    217         static DeclarationNode *newStorageClass( StorageClass );
    218         static DeclarationNode *newBasicType( BasicType );
    219         static DeclarationNode *newModifier( Modifier );
    220         static DeclarationNode *newBuiltinType( BuiltinType );
    221         static DeclarationNode *newFromTypedef( std::string *);
    222         static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body );
    223         static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants );
    224         static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant );
    225         static DeclarationNode *newName( std::string *);
    226         static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params );
    227         static DeclarationNode *newTypeParam( TypeClass, std::string *);
    228         static DeclarationNode *newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts );
    229         static DeclarationNode *newTraitUse( std::string *name, ExpressionNode *params );
    230         static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams );
    231         static DeclarationNode *newPointer( DeclarationNode *qualifiers );
    232         static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic );
    233         static DeclarationNode *newVarArray( DeclarationNode *qualifiers );
    234         static DeclarationNode *newBitfield( ExpressionNode *size );
    235         static DeclarationNode *newTuple( DeclarationNode *members );
    236         static DeclarationNode *newTypeof( ExpressionNode *expr );
    237         static DeclarationNode *newAttr( std::string *, ExpressionNode *expr );
    238         static DeclarationNode *newAttr( std::string *, DeclarationNode *type );
     206        static const char * qualifierName[];
     207        static const char * storageName[];
     208        static const char * basicTypeName[];
     209        static const char * modifierName[];
     210        static const char * aggregateName[];
     211        static const char * typeClassName[];
     212        static const char * builtinTypeName[];
     213
     214        static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false );
     215        static DeclarationNode * newQualifier( Qualifier );
     216        static DeclarationNode * newForall( DeclarationNode *);
     217        static DeclarationNode * newStorageClass( StorageClass );
     218        static DeclarationNode * newBasicType( BasicType );
     219        static DeclarationNode * newModifier( Modifier );
     220        static DeclarationNode * newBuiltinType( BuiltinType );
     221        static DeclarationNode * newFromTypedef( std::string *);
     222        static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
     223        static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants );
     224        static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode * constant );
     225        static DeclarationNode * newName( std::string *);
     226        static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode * params );
     227        static DeclarationNode * newTypeParam( TypeClass, std::string *);
     228        static DeclarationNode * newTrait( std::string * name, DeclarationNode * params, DeclarationNode * asserts );
     229        static DeclarationNode * newTraitUse( std::string * name, ExpressionNode * params );
     230        static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode * typeParams );
     231        static DeclarationNode * newPointer( DeclarationNode * qualifiers );
     232        static DeclarationNode * newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic );
     233        static DeclarationNode * newVarArray( DeclarationNode * qualifiers );
     234        static DeclarationNode * newBitfield( ExpressionNode * size );
     235        static DeclarationNode * newTuple( DeclarationNode * members );
     236        static DeclarationNode * newTypeof( ExpressionNode * expr );
     237        static DeclarationNode * newAttr( std::string *, ExpressionNode * expr );
     238        static DeclarationNode * newAttr( std::string *, DeclarationNode * type );
    239239
    240240        DeclarationNode();
    241241        ~DeclarationNode();
    242         DeclarationNode *clone() const;
    243 
    244         DeclarationNode *addQualifiers( DeclarationNode *);
     242        DeclarationNode * clone() const;
     243
     244        DeclarationNode * addQualifiers( DeclarationNode *);
    245245        void checkQualifiers( const TypeData *, const TypeData * );
    246         DeclarationNode *copyStorageClasses( DeclarationNode *);
    247         DeclarationNode *addType( DeclarationNode *);
    248         DeclarationNode *addTypedef();
    249         DeclarationNode *addAssertions( DeclarationNode *);
    250         DeclarationNode *addName( std::string *);
    251         DeclarationNode *addBitfield( ExpressionNode *size );
    252         DeclarationNode *addVarArgs();
    253         DeclarationNode *addFunctionBody( StatementNode *body );
    254         DeclarationNode *addOldDeclList( DeclarationNode *list );
    255         DeclarationNode *addPointer( DeclarationNode *qualifiers );
    256         DeclarationNode *addArray( DeclarationNode *array );
    257         DeclarationNode *addNewPointer( DeclarationNode *pointer );
    258         DeclarationNode *addNewArray( DeclarationNode *array );
    259         DeclarationNode *addParamList( DeclarationNode *list );
    260         DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions
    261         DeclarationNode *addInitializer( InitializerNode *init );
    262 
    263         DeclarationNode *cloneType( std::string *newName );
    264         DeclarationNode *cloneType( DeclarationNode *existing );
    265         DeclarationNode *cloneType( int ) { return cloneType( ( std::string *)0 ); }
    266         DeclarationNode *cloneBaseType( std::string *newName );
    267         DeclarationNode *cloneBaseType( DeclarationNode *newdecl );
    268 
    269         DeclarationNode *appendList( DeclarationNode *node ) {
     246        void checkStorageClasses( DeclarationNode *q );
     247        DeclarationNode * copyStorageClasses( DeclarationNode *);
     248        DeclarationNode * addType( DeclarationNode *);
     249        DeclarationNode * addTypedef();
     250        DeclarationNode * addAssertions( DeclarationNode *);
     251        DeclarationNode * addName( std::string *);
     252        DeclarationNode * addBitfield( ExpressionNode * size );
     253        DeclarationNode * addVarArgs();
     254        DeclarationNode * addFunctionBody( StatementNode * body );
     255        DeclarationNode * addOldDeclList( DeclarationNode * list );
     256        DeclarationNode * addPointer( DeclarationNode * qualifiers );
     257        DeclarationNode * addArray( DeclarationNode * array );
     258        DeclarationNode * addNewPointer( DeclarationNode * pointer );
     259        DeclarationNode * addNewArray( DeclarationNode * array );
     260        DeclarationNode * addParamList( DeclarationNode * list );
     261        DeclarationNode * addIdList( DeclarationNode * list ); // old-style functions
     262        DeclarationNode * addInitializer( InitializerNode * init );
     263
     264        DeclarationNode * cloneType( std::string * newName );
     265        DeclarationNode * cloneType( DeclarationNode * existing );
     266        DeclarationNode * cloneType( int ) { return cloneType( ( std::string *)0 ); }
     267        DeclarationNode * cloneBaseType( std::string * newName );
     268        DeclarationNode * cloneBaseType( DeclarationNode * newdecl );
     269
     270        DeclarationNode * appendList( DeclarationNode * node ) {
    270271                return (DeclarationNode *)set_last( node );
    271272        }
     
    274275        void printList( std::ostream &os, int indent = 0 ) const;
    275276
    276         Declaration *build() const;
    277         ::Type *buildType() const;
     277        Declaration * build() const;
     278        ::Type * buildType() const;
    278279
    279280        bool get_hasEllipsis() const;
    280281        const std::string &get_name() const { return name; }
    281282        LinkageSpec::Spec get_linkage() const { return linkage; }
    282         DeclarationNode *extractAggregate() const;
     283        DeclarationNode * extractAggregate() const;
    283284        bool has_enumeratorValue() const { return (bool)enumeratorValue; }
    284         ExpressionNode *consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); }
     285        ExpressionNode * consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); }
    285286
    286287        bool get_extension() const { return extension; }
    287         DeclarationNode *set_extension( bool exten ) { extension = exten; return this; }
     288        DeclarationNode * set_extension( bool exten ) { extension = exten; return this; }
    288289  public:
    289290        // StorageClass buildStorageClass() const;
    290291        // bool buildFuncSpecifier( StorageClass key ) const;
    291 
    292         struct Enumeration_t {
    293                 std::string name;
    294                 DeclarationNode * constants;
    295         };
    296         Enumeration_t enumeration;
    297292
    298293        struct Variable_t {
     
    312307        BuiltinType builtin;
    313308
    314         TypeData *type;
     309        TypeData * type;
    315310        std::string name;
    316311        // std::list< StorageClass > storageClasses;
     
    318313        bool isInline, isNoreturn;
    319314        std::list< std::string > attributes;
    320         ExpressionNode *bitfieldWidth;
     315        ExpressionNode * bitfieldWidth;
    321316        std::unique_ptr<ExpressionNode> enumeratorValue;
    322         InitializerNode *initializer;
     317        InitializerNode * initializer;
    323318        bool hasEllipsis;
    324319        LinkageSpec::Spec linkage;
     
    329324}; // DeclarationNode
    330325
    331 Type *buildType( TypeData *type );
     326Type * buildType( TypeData * type );
    332327//Type::Qualifiers buildQualifiers( const TypeData::Qualifiers & qualifiers );
    333328
    334 static inline Type * maybeMoveBuildType( const DeclarationNode *orig ) {
     329static inline Type * maybeMoveBuildType( const DeclarationNode * orig ) {
    335330        Type* ret = orig ? orig->buildType() : nullptr;
    336331        delete orig;
     
    343338  public:
    344339        StatementNode() { stmt = nullptr; }
    345         StatementNode( Statement *stmt ) : stmt( stmt ) {}
    346         StatementNode( DeclarationNode *decl );
     340        StatementNode( Statement * stmt ) : stmt( stmt ) {}
     341        StatementNode( DeclarationNode * decl );
    347342        virtual ~StatementNode() {}
    348343
    349         virtual StatementNode *clone() const final { assert( false ); return nullptr; }
    350         Statement *build() const { return const_cast<StatementNode*>(this)->stmt.release(); }
    351 
    352         virtual StatementNode *add_label( const std::string * name ) {
    353                 stmt->get_labels().emplace_back( *name );
     344        virtual StatementNode * clone() const final { assert( false ); return nullptr; }
     345        Statement * build() const { return const_cast<StatementNode*>(this)->stmt.release(); }
     346
     347        virtual StatementNode * add_label( const std::string * name ) {
     348                stmt->get_labels().emplace_back( * name );
    354349                delete name;
    355350                return this;
    356351        }
    357352
    358         virtual StatementNode *append_last_case( StatementNode * );
     353        virtual StatementNode * append_last_case( StatementNode * );
    359354
    360355        virtual void print( std::ostream &os, int indent = 0 ) {}
     
    364359}; // StatementNode
    365360
    366 Statement *build_expr( ExpressionNode *ctl );
     361Statement * build_expr( ExpressionNode * ctl );
    367362
    368363struct ForCtl {
    369         ForCtl( ExpressionNode *expr, ExpressionNode *condition, ExpressionNode *change ) :
     364        ForCtl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :
    370365                init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {}
    371         ForCtl( DeclarationNode *decl, ExpressionNode *condition, ExpressionNode *change ) :
     366        ForCtl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :
    372367                init( new StatementNode( decl ) ), condition( condition ), change( change ) {}
    373368
    374         StatementNode *init;
    375         ExpressionNode *condition;
    376         ExpressionNode *change;
     369        StatementNode * init;
     370        ExpressionNode * condition;
     371        ExpressionNode * change;
    377372};
    378373
    379 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt );
    380 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt );
    381 Statement *build_case( ExpressionNode *ctl );
    382 Statement *build_default();
    383 Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind = false );
    384 Statement *build_for( ForCtl *forctl, StatementNode *stmt );
    385 Statement *build_branch( BranchStmt::Type kind );
    386 Statement *build_branch( std::string *identifier, BranchStmt::Type kind );
    387 Statement *build_computedgoto( ExpressionNode *ctl );
    388 Statement *build_return( ExpressionNode *ctl );
    389 Statement *build_throw( ExpressionNode *ctl );
    390 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt );
    391 Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny = false );
    392 Statement *build_finally( StatementNode *stmt );
    393 Statement *build_compound( StatementNode *first );
    394 Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ExpressionNode *clobber = 0, LabelNode *gotolabels = 0 );
     374Statement * build_if( ExpressionNode * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
     375Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt );
     376Statement * build_case( ExpressionNode * ctl );
     377Statement * build_default();
     378Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind = false );
     379Statement * build_for( ForCtl * forctl, StatementNode * stmt );
     380Statement * build_branch( BranchStmt::Type kind );
     381Statement * build_branch( std::string * identifier, BranchStmt::Type kind );
     382Statement * build_computedgoto( ExpressionNode * ctl );
     383Statement * build_return( ExpressionNode * ctl );
     384Statement * build_throw( ExpressionNode * ctl );
     385Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt );
     386Statement * build_catch( DeclarationNode * decl, StatementNode * stmt, bool catchAny = false );
     387Statement * build_finally( StatementNode * stmt );
     388Statement * build_compound( StatementNode * first );
     389Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = 0, ExpressionNode * input = 0, ExpressionNode * clobber = 0, LabelNode * gotolabels = 0 );
    395390
    396391//##############################################################################
    397392
    398393template< typename SynTreeType, typename NodeType >
    399 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
     394void buildList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {
    400395        SemanticError errors;
    401396        std::back_insert_iterator< std::list< SynTreeType * > > out( outputList );
    402         const NodeType *cur = firstNode;
     397        const NodeType * cur = firstNode;
    403398
    404399        while ( cur ) {
    405400                try {
    406 //                      SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) );
    407                         SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) );
     401//                      SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) );
     402                        SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) );
    408403                        if ( result ) {
    409                                 *out++ = result;
    410                         } else {
     404                                * out++ = result;
    411405                        } // if
    412406                } catch( SemanticError &e ) {
     
    421415
    422416// in DeclarationNode.cc
    423 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList );
    424 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList );
    425 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList );
     417void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList );
     418void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList );
     419void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList );
    426420
    427421template< typename SynTreeType, typename NodeType >
    428 void buildMoveList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
     422void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {
    429423        buildList(firstNode, outputList);
    430424        delete firstNode;
  • src/Parser/TypeData.h

    r46f1d20 rddcfb88  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 22:31:52 2016
    13 // Update Count     : 110
     12// Last Modified On : Sat Sep 10 09:42:54 2016
     13// Update Count     : 118
    1414//
    1515
     
    8989        typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers;
    9090        Qualifiers qualifiers;
     91        typedef std::bitset< DeclarationNode::NoStorageClass > StorageClasses;
     92        StorageClasses storageclasses;
    9193        DeclarationNode * forall;
    9294
     
    9698                Array_t array;
    9799                Enumeration_t enumeration;
     100                // Variable_t variable;
    98101                Function_t function;
    99102                Symbolic_t symbolic;
    100103                DeclarationNode * tuple;
    101104                ExpressionNode * typeexpr;
    102                 //Attr_t attr;
     105                // Attr_t attr;
    103106                // DeclarationNode::BuiltinType builtin;
    104107
  • src/tests/.expect/declarationErrors.txt

    r46f1d20 rddcfb88  
    11CFA Version 1.0.0 (debug)
    2 Error: invalid combination of storage classes in declaration of x9: static const volatile short int
     2Error: duplicate static in declaration of x1: static const volatile short int
    33
    4 Error: invalid combination of storage classes in declaration of x18: static const volatile instance of const volatile struct __anonymous0
     4Error: conflicting extern & static in declaration of x2: extern const volatile short int
     5
     6Error: conflicting extern & auto, conflicting extern & static, conflicting extern & static, duplicate extern in declaration of x3: extern const volatile short int
     7
     8Error: duplicate static in declaration of x4: static const volatile instance of const volatile struct __anonymous0
    59  with members
    610   with body
    711
    812
    9 Error: duplicate qualifier volatile in declaration of x19: static const volatile instance of const volatile struct __anonymous1
     13Error: duplicate const, duplicate static, duplicate volatile in declaration of x5: static const volatile instance of const volatile struct __anonymous1
    1014  with members
    1115   with body
    1216
    1317
    14 Error: invalid combination of storage classes in declaration of x28: static const volatile instance of type Int
     18Error: duplicate static in declaration of x6: static const volatile instance of type Int
    1519
    16 Error: duplicate qualifier const in declaration of f01: static inline function
     20Error: duplicate const in declaration of f01: static inline function
    1721  with no parameters
    1822  returning const volatile int
    1923
    2024
    21 Error: duplicate qualifier volatile in declaration of f02: static inline function
     25Error: duplicate volatile in declaration of f02: static inline function
    2226  with no parameters
    2327  returning const volatile int
    2428
    2529
    26 Error: duplicate qualifier const in declaration of f03: static inline function
     30Error: duplicate const in declaration of f03: static inline function
    2731  with no parameters
    2832  returning const volatile int
    2933
    3034
    31 Error: duplicate qualifier volatile in declaration of f04: static inline function
     35Error: duplicate volatile in declaration of f04: static inline function
    3236  with no parameters
    3337  returning const volatile int
    3438
    3539
    36 Error: duplicate qualifier const in declaration of f05: static inline function
     40Error: duplicate const in declaration of f05: static inline function
    3741  with no parameters
    3842  returning const volatile int
    3943
    4044
    41 Error: duplicate qualifier volatile in declaration of f06: static inline function
     45Error: duplicate volatile in declaration of f06: static inline function
    4246  with no parameters
    4347  returning const volatile int
    4448
    4549
    46 Error: duplicate qualifier const in declaration of f07: static inline function
     50Error: duplicate const in declaration of f07: static inline function
    4751  with no parameters
    4852  returning const volatile int
    4953
    5054
    51 Error: duplicate qualifier const, volatile in declaration of f08: static inline function
     55Error: duplicate const, duplicate volatile in declaration of f08: static inline function
    5256  with no parameters
    5357  returning const volatile int
    5458
    5559
    56 Error: duplicate qualifier const, volatile in declaration of f09: static inline function
     60Error: duplicate const, duplicate volatile in declaration of f09: static inline function
    5761  with no parameters
    5862  returning const volatile int
    5963
    6064
    61 Error: duplicate qualifier const, volatile in declaration of f09: static inline function
     65Error: duplicate const, duplicate _Atomic, duplicate _Atomic, duplicate const, duplicate restrict, duplicate volatile in declaration of f09: static inline function
    6266  with no parameters
    63   returning const volatile int
     67  returning const restrict volatile _Atomic int
    6468
    6569
  • src/tests/declarationErrors.c

    r46f1d20 rddcfb88  
    1010// Created On       : Wed Aug 17 08:23:43 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 25 18:16:40 2016
    13 // Update Count     : 5
     12// Last Modified On : Fri Sep  9 22:57:52 2016
     13// Update Count     : 31
    1414//
    1515
    16 static short int volatile static const x9;                              // duplicate static
    17 struct { int i; } const static volatile static x18;             // duplicate static
    18 struct { int i; } const static volatile static volatile x19; // duplicate static & volatile
     16static short int volatile static const x1;                              // duplicate static
     17extern short int static volatile const x2;                              // multiple extern & static
     18extern short int auto static volatile static extern const x3; // duplicate and multiple storage classes
     19struct { int i; } const static volatile static x4;              // duplicate static
     20struct { int i; } const static volatile const static volatile x5; // duplicate static & const & volatile
    1921typedef int Int;
    20 static Int volatile static const x28;                                   // duplicate static
     22static Int volatile static const x6;                                    // duplicate static
    2123
    2224const static inline const volatile int f01();                   // duplicate const
     
    2426const inline const volatile int static f03();                   // duplicate const
    2527volatile inline static const volatile int f04();                // duplicate volatile
    26 const static const inline volatile int f05();                   // duplicate const
    27 volatile static const volatile inline int f06();                // duplicate volatile
    28 const static const volatile int inline f07();                   // duplicate const
    29 volatile static const int inline const volatile f08();          // duplicate volatile
     28const static int const inline volatile f05();                   // duplicate const
     29volatile int static const volatile inline f06();                // duplicate volatile
     30const static const int volatile inline f07();                   // duplicate const
     31volatile static const int inline const volatile f08();  // duplicate volatile
    3032
    31 volatile static const int inline const volatile f09();          // duplicate volatile
    32 volatile static const int inline const volatile f09();          // duplicate volatile
     33volatile static const int inline const volatile f09();  // duplicate volatile
     34_Atomic _Atomic _Atomic volatile restrict static const const int inline restrict const volatile f09();  // duplicate volatile
    3335
    3436//Dummy main
Note: See TracChangeset for help on using the changeset viewer.