Changeset b1e63ac5 for src/Parser


Ignore:
Timestamp:
Jul 4, 2017, 9:40:16 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
208e5be
Parents:
9c951e3 (diff), f7cb0bc (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' into references

Location:
src/Parser
Files:
13 edited
3 moved

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r9c951e3 rb1e63ac5  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 12:34:05 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 15:46:33 2017
    13 // Update Count     : 1018
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jun 28 15:27:00 2017
     13// Update Count     : 1019
    1414//
    1515
     
    5757        variable.tyClass = NoTypeClass;
    5858        variable.assertions = nullptr;
     59        variable.initializer = nullptr;
    5960
    6061//      attr.name = nullptr;
     
    7071//      delete variable.name;
    7172        delete variable.assertions;
     73        delete variable.initializer;
    7274
    7375        delete type;
     
    101103        newnode->variable.tyClass = variable.tyClass;
    102104        newnode->variable.assertions = maybeClone( variable.assertions );
     105        newnode->variable.initializer = maybeClone( variable.initializer );
    103106
    104107//      newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;
     
    857860}
    858861
     862DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) {
     863        assertf( variable.tyClass != NoTypeClass, "Called addTypeInitializer on something that isn't a type variable." );
     864        variable.initializer = init;
     865        return this;
     866}
     867
    859868DeclarationNode * DeclarationNode::cloneType( string * newName ) {
    860869        DeclarationNode * newnode = new DeclarationNode;
     
    10141023                assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." );
    10151024                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    1016                 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );
     1025                TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.initializer ? variable.initializer->buildType() : nullptr );
    10171026                buildList( variable.assertions, ret->get_assertions() );
    10181027                return ret;
     
    10541063          case TypeData::Enum:
    10551064          case TypeData::Aggregate: {
    1056                   ReferenceToType * ret = buildComAggInst( type, attributes );
     1065                  ReferenceToType * ret = buildComAggInst( type, attributes, linkage );
    10571066                  buildList( type->aggregate.actuals, ret->get_parameters() );
    10581067                  return ret;
  • src/Parser/ExpressionNode.cc

    r9c951e3 rb1e63ac5  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 30 17:02:46 2017
    13 // Update Count     : 515
     12// Last Modified On : Wed Jun 28 21:08:15 2017
     13// Update Count     : 542
    1414//
    1515
     
    2727#include "SynTree/Declaration.h"
    2828#include "Common/UnimplementedError.h"
    29 #include "parseutility.h"
     29#include "parserutility.h"
    3030#include "Common/utility.h"
    3131
     
    6262        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
    6363        int size;                                                                                       // 0 => int, 1 => long, 2 => long long
    64         unsigned long long v;                                                           // converted integral value
     64        unsigned long long int v;                                                               // converted integral value
    6565        size_t last = str.length() - 1;                                         // last character of constant
    6666
     
    118118        } // if
    119119
    120         Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str ) );
     120        Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str, v ) );
    121121        delete &str;                                                                            // created by lex
    122122        return ret;
     
    133133        // floating-point constant has minimum of 2 characters: 1. or .1
    134134        size_t last = str.length() - 1;
     135        double v;
     136
     137        sscanf( str.c_str(), "%lg", &v );
    135138
    136139        if ( checkI( str[last] ) ) {                                            // imaginary ?
     
    150153        } // if
    151154
    152         Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str ) );
     155        Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str, v ) );
    153156        delete &str;                                                                            // created by lex
    154157        return ret;
     
    156159
    157160Expression *build_constantChar( const std::string & str ) {
    158         Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str ) );
     161        Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
    159162        delete &str;                                                                            // created by lex
    160163        return ret;
     
    164167        // string should probably be a primitive type
    165168        ArrayType *at = new ArrayType( emptyQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
    166                                 new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::UnsignedInt ),
    167                                                                                         toString( str.size()+1-2 ) ) ),  // +1 for '\0' and -2 for '"'
     169                                                                   new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ),  // +1 for '\0' and -2 for '"'
    168170                                                                   false, false );
    169         ConstantExpr * ret = new ConstantExpr( Constant( at, str ) );
     171        // constant 0 is ignored for pure string value
     172        ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) );
    170173        delete &str;                                                                            // created by lex
    171174        return ret;
     
    173176
    174177Expression *build_constantZeroOne( const std::string & str ) {
    175         Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( emptyQualifiers ) : (Type*)new OneType( emptyQualifiers ), str ) );
     178        Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( emptyQualifiers ) : (Type*)new OneType( emptyQualifiers ), str,
     179                                                                                                   str == "0" ? (unsigned long long int)0 : (unsigned long long int)1 ) );
    176180        delete &str;                                                                            // created by lex
    177181        return ret;
     
    184188        std::stringstream ss( str );
    185189        ss >> a >> dot >> b;
    186         UntypedMemberExpr * ret = new UntypedMemberExpr(
    187                 new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::SignedInt ), toString( b ) ) ),
    188                 new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::SignedInt ), toString( a ) ) ) );
     190        UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) );
    189191        delete &str;
    190192        return ret;
     
    207209} // build_field_name_fraction_constants
    208210
     211
     212
    209213Expression * build_field_name_REALFRACTIONconstant( const std::string & str ) {
    210         assert( str[0] == '.' );
     214        if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str );
    211215        Expression * ret = build_constantInteger( *new std::string( str.substr(1) ) );
    212216        delete &str;
     
    215219
    216220Expression * build_field_name_REALDECIMALconstant( const std::string & str ) {
    217         assert( str[str.size()-1] == '.' );
     221        if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str );
    218222        Expression * ret = build_constantInteger( *new std::string( str.substr( 0, str.size()-1 ) ) );
    219223        delete &str;
     
    221225} // build_field_name_REALDECIMALconstant
    222226
    223 NameExpr * build_varref( const string *name, bool labelp ) {
     227NameExpr * build_varref( const string *name ) {
    224228        NameExpr *expr = new NameExpr( *name, nullptr );
    225229        delete name;
     
    344348
    345349Expression *build_valexpr( StatementNode *s ) {
    346         return new UntypedValofExpr( maybeMoveBuild< Statement >(s), nullptr );
     350        return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) );
    347351}
    348352Expression *build_typevalue( DeclarationNode *decl ) {
  • src/Parser/InitializerNode.cc

    r9c951e3 rb1e63ac5  
    7474
    7575        InitializerNode *moreInit;
    76         if  ( get_next() != 0 && ((moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) != 0) )
     76        if ( (moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) ) {
    7777                moreInit->printOneLine( os );
     78        }
    7879}
    7980
    8081Initializer *InitializerNode::build() const {
    8182        if ( aggregate ) {
     83                // steal designators from children
     84                std::list< Designation * > designlist;
     85                InitializerNode * child = next_init();
     86                for ( ; child != nullptr; child = dynamic_cast< InitializerNode * >( child->get_next() ) ) {
     87                        std::list< Expression * > desList;
     88                        buildList< Expression, ExpressionNode >( child->designator, desList );
     89                        designlist.push_back( new Designation( desList ) );
     90                } // for
    8291                std::list< Initializer * > initlist;
    8392                buildList< Initializer, InitializerNode >( next_init(), initlist );
    84 
    85                 std::list< Expression * > designlist;
    86 
    87                 if ( designator != 0 ) {
    88                         buildList< Expression, ExpressionNode >( designator, designlist );
    89                 } // if
    90 
    9193                return new ListInit( initlist, designlist, maybeConstructed );
    9294        } else {
    93                 std::list< Expression * > designators;
    94 
    95                 if ( designator != 0 )
    96                         buildList< Expression, ExpressionNode >( designator, designators );
    97 
    98                 if ( get_expression() != 0)
    99                         return new SingleInit( maybeBuild< Expression >( get_expression() ), designators, maybeConstructed );
     95                if ( get_expression() != 0) {
     96                        return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed );
     97                }
    10098        } // if
    101 
    10299        return 0;
    103100}
  • src/Parser/LinkageSpec.cc

    r9c951e3 rb1e63ac5  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:22:09 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Oct  2 23:16:21 2016
    13 // Update Count     : 23
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jun 28 11:51:00 2017
     13// Update Count     : 24
    1414//
    1515
     
    2828        } else if ( *spec == "\"C\"" ) {
    2929                return C;
     30        } else if ( *spec == "\"BuiltinC\"" ) {
     31                return BuiltinC;
    3032        } else {
    3133                throw SemanticError( "Invalid linkage specifier " + *spec );
     
    3638        assert( 0 <= linkage && linkage < LinkageSpec::NoOfSpecs );
    3739        static const char *linkageKinds[LinkageSpec::NoOfSpecs] = {
    38                 "intrinsic", "Cforall", "C", "automatically generated", "compiler built-in",
     40                "intrinsic", "Cforall", "C", "automatically generated", "compiler built-in", "cfa built-in", "c built-in",
    3941        };
    4042        return linkageKinds[linkage];
    4143}
    4244
    43 bool LinkageSpec::isDecoratable( Spec spec ) {
     45bool LinkageSpec::isMangled( Spec spec ) {
    4446        assert( 0 <= spec && spec < LinkageSpec::NoOfSpecs );
    4547        static bool decoratable[LinkageSpec::NoOfSpecs] = {
    46                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler
     48                //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler,
    4749                        true,           true,           false,  true,           false,
     50                //      Builtin,        BuiltinC,
     51                        true,           false,
    4852        };
    4953        return decoratable[spec];
     
    5357        assert( 0 <= spec && spec < LinkageSpec::NoOfSpecs );
    5458        static bool generatable[LinkageSpec::NoOfSpecs] = {
    55                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler
     59                //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler,
    5660                        true,           true,           true,   true,           false,
     61                //      Builtin,        BuiltinC,
     62                        true,           true,
    5763        };
    5864        return generatable[spec];
     
    6268        assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs );
    6369        static bool overridable[LinkageSpec::NoOfSpecs] = {
    64                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler
     70                //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler,
    6571                        true,           false,          false,  true,           false,
     72                //      Builtin,        BuiltinC,
     73                        false,          false,
    6674        };
    6775        return overridable[spec];
     
    7179        assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs );
    7280        static bool builtin[LinkageSpec::NoOfSpecs] = {
    73                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler
     81                //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler,
    7482                        true,           false,          false,  false,          true,
     83                //      Builtin,        BuiltinC,
     84                        true,           true,
    7585        };
    7686        return builtin[spec];
  • src/Parser/LinkageSpec.h

    r9c951e3 rb1e63ac5  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:24:28 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Oct  1 23:03:17 2016
    13 // Update Count     : 11
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jun 28 11:50:00 2017
     13// Update Count     : 12
    1414//
    1515
     
    2626                AutoGen,                                                                                // built by translator (struct assignment)
    2727                Compiler,                                                                               // gcc internal
     28                Builtin,                                                                                // mangled builtins
     29                BuiltinC,                                                                               // non-mangled builtins
    2830                NoOfSpecs
    2931        };
     
    3234        static std::string linkageName( Spec );
    3335 
    34         static bool isDecoratable( Spec );
     36        static bool isMangled( Spec );
    3537        static bool isGeneratable( Spec );
    3638        static bool isOverridable( Spec );
  • src/Parser/ParseNode.h

    r9c951e3 rb1e63ac5  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:28:16 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 15:42:18 2017
    13 // Update Count     : 777
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jun 12 13:00:00 2017
     13// Update Count     : 779
    1414//
    1515
     
    6161        }
    6262
    63         virtual void print( std::ostream &os, int indent = 0 ) const {}
    64         virtual void printList( std::ostream &os, int indent = 0 ) const {}
     63        virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {}
     64        virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {}
    6565
    6666        static int indent_by;
     
    113113        ExpressionNode * set_extension( bool exten ) { extension = exten; return this; }
    114114
    115         virtual void print( std::ostream &os, int indent = 0 ) const override {}
    116         void printOneLine( std::ostream &os, int indent = 0 ) const {}
     115        virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {}
     116        void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {}
    117117
    118118        template<typename T>
     
    166166Expression * build_field_name_REALDECIMALconstant( const std::string & str );
    167167
    168 NameExpr * build_varref( const std::string * name, bool labelp = false );
     168NameExpr * build_varref( const std::string * name );
    169169Expression * build_typevalue( DeclarationNode * decl );
    170170
     
    274274        DeclarationNode * addIdList( DeclarationNode * list ); // old-style functions
    275275        DeclarationNode * addInitializer( InitializerNode * init );
     276        DeclarationNode * addTypeInitializer( DeclarationNode * init );
    276277
    277278        DeclarationNode * cloneType( std::string * newName );
     
    282283        }
    283284
    284         virtual void print( std::ostream &os, int indent = 0 ) const override;
    285         virtual void printList( std::ostream &os, int indent = 0 ) const override;
     285        virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override;
     286        virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override;
    286287
    287288        Declaration * build() const;
     
    301302                DeclarationNode::TypeClass tyClass;
    302303                DeclarationNode * assertions;
     304                DeclarationNode * initializer;
    303305        };
    304306        Variable_t variable;
     
    361363        virtual StatementNode * append_last_case( StatementNode * );
    362364
    363         virtual void print( std::ostream &os, int indent = 0 ) const override {}
    364         virtual void printList( std::ostream &os, int indent = 0 ) const override {}
     365        virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {}
     366        virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {}
    365367  private:
    366368        std::unique_ptr<Statement> stmt;
     
    391393Statement * build_return( ExpressionNode * ctl );
    392394Statement * build_throw( ExpressionNode * ctl );
     395Statement * build_resume( ExpressionNode * ctl );
     396Statement * build_resume_at( ExpressionNode * ctl , ExpressionNode * target );
    393397Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt );
    394 Statement * build_catch( DeclarationNode * decl, StatementNode * stmt, bool catchAny = false );
     398Statement * build_catch( CatchStmt::Kind kind, DeclarationNode *decl, ExpressionNode *cond, StatementNode *body );
    395399Statement * build_finally( StatementNode * stmt );
    396400Statement * build_compound( StatementNode * first );
     
    411415                                result->location = cur->location;
    412416                                * out++ = result;
     417                        } else {
     418                                assertf(false, "buildList unknown type");
    413419                        } // if
    414420                } catch( SemanticError &e ) {
  • src/Parser/StatementNode.cc

    r9c951e3 rb1e63ac5  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  2 22:16:40 2017
    13 // Update Count     : 327
     12// Last Modified On : Wed Jun 28 21:08:37 2017
     13// Update Count     : 330
    1414//
    1515
     
    2121#include "SynTree/Statement.h"
    2222#include "SynTree/Expression.h"
    23 #include "parseutility.h"
     23#include "parserutility.h"
    2424#include "Common/utility.h"
    2525
     
    152152        return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr );
    153153}
     154
    154155Statement *build_throw( ExpressionNode *ctl ) {
    155156        std::list< Expression * > exps;
    156157        buildMoveList( ctl, exps );
    157158        assertf( exps.size() < 2, "This means we are leaking memory");
    158         return new ReturnStmt( noLabels, !exps.empty() ? exps.back() : nullptr, true );
     159        return new ThrowStmt( noLabels, ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr );
     160}
     161
     162Statement *build_resume( ExpressionNode *ctl ) {
     163        std::list< Expression * > exps;
     164        buildMoveList( ctl, exps );
     165        assertf( exps.size() < 2, "This means we are leaking memory");
     166        return new ThrowStmt( noLabels, ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr );
     167}
     168
     169Statement *build_resume_at( ExpressionNode *ctl, ExpressionNode *target ) {
     170        (void)ctl;
     171        (void)target;
     172        assertf( false, "resume at (non-local throw) is not yet supported," );
    159173}
    160174
    161175Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) {
    162         std::list< Statement * > branches;
    163         buildMoveList< Statement, StatementNode >( catch_stmt, branches );
     176        std::list< CatchStmt * > branches;
     177        buildMoveList< CatchStmt, StatementNode >( catch_stmt, branches );
    164178        CompoundStmt *tryBlock = safe_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));
    165179        FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
    166180        return new TryStmt( noLabels, tryBlock, branches, finallyBlock );
    167181}
    168 Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny ) {
    169         std::list< Statement * > branches;
    170         buildMoveList< Statement, StatementNode >( stmt, branches );
    171         assert( branches.size() == 1 );
    172         return new CatchStmt( noLabels, maybeMoveBuild< Declaration >(decl), branches.front(), catchAny );
     182Statement *build_catch( CatchStmt::Kind kind, DeclarationNode *decl, ExpressionNode *cond, StatementNode *body ) {
     183        std::list< Statement * > branches;
     184        buildMoveList< Statement, StatementNode >( body, branches );
     185        assert( branches.size() == 1 );
     186        return new CatchStmt( noLabels, kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );
    173187}
    174188Statement *build_finally( StatementNode *stmt ) {
  • src/Parser/TypeData.cc

    r9c951e3 rb1e63ac5  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:12:51 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 15:52:43 2017
    13 // Update Count     : 563
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jun 28 15:28:00 2017
     13// Update Count     : 564
    1414//
    1515
     
    630630} // buildReference
    631631
    632 AggregateDecl * buildAggregate( const TypeData * td, std::list< Attribute * > attributes ) {
     632AggregateDecl * buildAggregate( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
    633633        assert( td->kind == TypeData::Aggregate );
    634634        AggregateDecl * at;
     
    638638          case DeclarationNode::Monitor:
    639639          case DeclarationNode::Thread:
    640                 at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes );
     640                at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes, linkage );
    641641                buildForall( td->aggregate.params, at->get_parameters() );
    642642                break;
     
    659659} // buildAggregate
    660660
    661 ReferenceToType * buildComAggInst( const TypeData * type, std::list< Attribute * > attributes ) {
     661ReferenceToType * buildComAggInst( const TypeData * type, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
    662662        switch ( type->kind ) {
    663663          case TypeData::Enum: {
     
    672672                  ReferenceToType * ret;
    673673                  if ( type->aggregate.body ) {
    674                           AggregateDecl * typedecl = buildAggregate( type, attributes );
     674                          AggregateDecl * typedecl = buildAggregate( type, attributes, linkage );
    675675                          switch ( type->aggregate.kind ) {
    676676                                case DeclarationNode::Struct:
     
    776776                if ( cur->has_enumeratorValue() ) {
    777777                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
    778                         member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), list< Expression * >() ) );
     778                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) );
    779779                } // if
    780780        } // for
     
    793793TupleType * buildTuple( const TypeData * td ) {
    794794        assert( td->kind == TypeData::Tuple );
    795         TupleType * ret = new TupleType( buildQualifiers( td ) );
    796         buildTypeList( td->tuple, ret->get_types() );
     795        std::list< Type * > types;
     796        buildTypeList( td->tuple, types );
     797        TupleType * ret = new TupleType( buildQualifiers( td ), types );
    797798        buildForall( td->forall, ret->get_forall() );
    798799        return ret;
     
    818819                return decl->set_asmName( asmName );
    819820        } else if ( td->kind == TypeData::Aggregate ) {
    820                 return buildAggregate( td, attributes );
     821                return buildAggregate( td, attributes, linkage );
    821822        } else if ( td->kind == TypeData::Enum ) {
    822823                return buildEnum( td, attributes );
  • src/Parser/TypeData.h

    r9c951e3 rb1e63ac5  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:18:36 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:32:39 2017
    13 // Update Count     : 185
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jun 28 15:29:00 2017
     13// Update Count     : 186
    1414//
    1515
     
    103103ReferenceType * buildReference( const TypeData * );
    104104AggregateDecl * buildAggregate( const TypeData *, std::list< Attribute * > );
    105 ReferenceToType * buildComAggInst( const TypeData *, std::list< Attribute * > attributes );
     105ReferenceToType * buildComAggInst( const TypeData *, std::list< Attribute * > attributes, LinkageSpec::Spec linkage );
    106106ReferenceToType * buildAggInst( const TypeData * );
    107107TypeDecl * buildVariable( const TypeData * );
  • src/Parser/TypedefTable.h

    r9c951e3 rb1e63ac5  
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 15 18:25:04 2016
    13 // Update Count     : 28
     12// Last Modified On : Wed Jun 28 21:56:34 2017
     13// Update Count     : 33
    1414//
    1515
     
    2222#include <stack>
    2323
    24 #include "lex.h"
     24#include "parser.hh"
    2525#include "parser.h"
    2626
  • src/Parser/lex.ll

    r9c951e3 rb1e63ac5  
    55 * file "LICENCE" distributed with Cforall.
    66 *
    7  * lex.l --
     7 * lex.ll --
    88 *
    99 * Author           : Peter A. Buhr
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Mon Mar 13 08:36:17 2017
    13  * Update Count     : 506
     12 * Last Modified On : Wed Jun 28 21:03:45 2017
     13 * Update Count     : 529
    1414 */
    1515
     
    2727#include <cstdio>                                                                               // FILENAME_MAX
    2828
    29 #include "lex.h"
    30 #include "parser.h"                                                                             // YACC generated definitions based on C++ grammar
    3129#include "ParseNode.h"
    3230#include "TypedefTable.h"
     
    7775                                // numeric constants, CFA: '_' in constant
    7876hex_quad {hex}("_"?{hex}){3}
    79 integer_suffix "_"?(([uU][lL]?)|([uU]("ll"|"LL")?)|([lL][uU]?)|("ll"|"LL")[uU]?)
     77integer_suffix "_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?)))
    8078
    8179octal_digits ({octal})|({octal}({octal}|"_")*{octal})
     
    9189
    9290decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal})
    93 real_decimal {decimal_digits}"."
    94 real_fraction "."{decimal_digits}
    95 real_constant {decimal_digits}?{real_fraction}
     91real_decimal {decimal_digits}"."{exponent}?{floating_suffix}?
     92real_fraction "."{decimal_digits}{exponent}?{floating_suffix}?
     93real_constant {decimal_digits}{real_fraction}
    9694exponent "_"?[eE]"_"?[+-]?{decimal_digits}
    97                                 // GCC: D (double), DL (long double) and iI (imaginary) suffixes
    98 floating_suffix "_"?([fFdDlL][iI]?|"DL"|[iI][lLfFdD]?)
    99                                 //floating_suffix "_"?([fFdD]|[lL]|[D][L])|([iI][lLfFdD])|([lLfFdD][iI]))
     95                                // GCC: D (double) and iI (imaginary) suffixes, and DL (long double)
     96floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL")
    10097floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}?
    10198
     
    236233long                    { KEYWORD_RETURN(LONG); }
    237234lvalue                  { KEYWORD_RETURN(LVALUE); }                             // CFA
    238 monitor         { KEYWORD_RETURN(MONITOR); }                    // CFA
     235monitor                 { KEYWORD_RETURN(MONITOR); }                    // CFA
    239236mutex                   { KEYWORD_RETURN(MUTEX); }                              // CFA
    240237_Noreturn               { KEYWORD_RETURN(NORETURN); }                   // C11
     
    378375"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
    379376        /*
    380           This rule handles ambiguous cases with operator identifiers, e.g., "int *?*?()", where the string "*?*?"
    381           can be lexed as "*"/"?*?" or "*?"/"*?". Since it is common practise to put a unary operator juxtaposed
    382           to an identifier, e.g., "*i", users will be annoyed if they cannot do this with respect to operator
    383           identifiers. Even with this special hack, there are 5 general cases that cannot be handled. The first
    384           case is for the function-call identifier "?()":
    385 
    386           int * ?()();  // declaration: space required after '*'
    387           * ?()();      // expression: space required after '*'
    388 
    389           Without the space, the string "*?()" is ambiguous without N character look ahead; it requires scanning
    390           ahead to determine if there is a '(', which is the start of an argument/parameter list.
    391 
    392           The 4 remaining cases occur in expressions:
    393 
    394           i++?i:0;              // space required before '?'
    395           i--?i:0;              // space required before '?'
    396           i?++i:0;              // space required after '?'
    397           i?--i:0;              // space required after '?'
    398 
    399           In the first two cases, the string "i++?" is ambiguous, where this string can be lexed as "i"/"++?" or
    400           "i++"/"?"; it requires scanning ahead to determine if there is a '(', which is the start of an argument
    401           list.  In the second two cases, the string "?++x" is ambiguous, where this string can be lexed as
    402           "?++"/"x" or "?"/"++x"; it requires scanning ahead to determine if there is a '(', which is the start of
    403           an argument list.
     377          This rule handles ambiguous cases with operator identifiers, e.g., "int *?*?()", where the string "*?*?"  can be
     378          lexed as "*?"/"*?" or "*"/"?*?". Since it is common practise to put a unary operator juxtaposed to an identifier,
     379          e.g., "*i", users will be annoyed if they cannot do this with respect to operator identifiers. Therefore, there is
     380          a lexical look-ahead for the second case, with backtracking to return the leading unary operator and then
     381          reparsing the trailing operator identifier.  Otherwise a space is needed between the unary operator and operator
     382          identifier to disambiguate this common case.
     383
     384          A similar issue occurs with the dereference, *?(...), and routine-call, ?()(...) identifiers.  The ambiguity
     385          occurs when the deference operator has no parameters, *?() and *?()(...), requiring arbitrary whitespace
     386          look-ahead for the routine-call parameter-list to disambiguate.  However, the dereference operator must have a
     387          parameter/argument to dereference *?(...).  Hence, always interpreting the string *?() as * ?() does not preclude
     388          any meaningful program.
     389
     390          The remaining cases are with the increment/decrement operators and conditional expression:
     391
     392          i++? ...(...);
     393          i?++ ...(...);
     394
     395          requiring arbitrary whitespace look-ahead for the operator parameter-list, even though that interpretation is an
     396      incorrect expression (juxtaposed identifiers).  Therefore, it is necessary to disambiguate these cases with a
     397      space:
     398
     399          i++ ? i : 0;
     400          i? ++i : 0;
    404401        */
    405 {op_unary}"?"({op_unary_pre_post}|"[?]"|{op_binary_over}"?") {
     402{op_unary}"?"({op_unary_pre_post}|"()"|"[?]"|{op_binary_over}"?") {
    406403        // 1 or 2 character unary operator ?
    407404        int i = yytext[1] == '?' ? 1 : 2;
  • src/Parser/module.mk

    r9c951e3 rb1e63ac5  
    1111## Created On       : Sat May 16 15:29:09 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Tue Aug 16 17:28:34 2016
    14 ## Update Count     : 101
     13## Last Modified On : Wed Jun 28 21:58:29 2017
     14## Update Count     : 104
    1515###############################################################################
    1616
     
    2929       Parser/TypeData.cc \
    3030       Parser/LinkageSpec.cc \
    31        Parser/parseutility.cc
     31       Parser/parserutility.cc
    3232
    3333MAINTAINERCLEANFILES += Parser/parser.output
  • src/Parser/parser.hh

    r9c951e3 rb1e63ac5  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // lex.h --
     7// parser.hh --
    88//
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep 22 08:58:10 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 21 11:28:47 2016
    13 // Update Count     : 347
     12// Last Modified On : Wed Jun 28 22:10:17 2017
     13// Update Count     : 349
    1414//
    1515
    16 #ifndef PARSER_LEX_H
    17 #define PARSER_LEX_H
     16#ifndef PARSER_HH
     17#define PARSER_HH
    1818
    1919int yylex();
     
    4242}; // Token
    4343
    44 #endif // PARSER_LEX_H
     44#endif // PARSER_HH
    4545
    4646// Local Variables: //
  • src/Parser/parser.yy

    r9c951e3 rb1e63ac5  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // cfa.y --
     7// parser.yy --
    88//
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 30 15:42:32 2017
    13 // Update Count     : 2318
     12// Last Modified On : Wed Jun 28 22:11:22 2017
     13// Update Count     : 2414
    1414//
    1515
     
    4848#include <cstdio>
    4949#include <stack>
    50 #include "lex.h"
    51 #include "parser.h"
    5250#include "ParseNode.h"
    5351#include "TypedefTable.h"
     
    8583        } // for
    8684} // distExt
     85
     86bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
    8787%}
     88
     89// Types declaration
     90%union
     91{
     92        Token tok;
     93        ParseNode * pn;
     94        ExpressionNode * en;
     95        DeclarationNode * decl;
     96        DeclarationNode::Aggregate aggKey;
     97        DeclarationNode::TypeClass tclass;
     98        StatementNode * sn;
     99        ConstantExpr * constant;
     100        ForCtl * fctl;
     101        LabelNode * label;
     102        InitializerNode * in;
     103        OperKinds op;
     104        std::string * str;
     105        bool flag;
     106}
    88107
    89108//************************* TERMINAL TOKENS ********************************
     
    138157%token ATassign                                                                                 // @=
    139158
    140 // Types declaration
    141 %union
    142 {
    143         Token tok;
    144         ParseNode * pn;
    145         ExpressionNode * en;
    146         DeclarationNode * decl;
    147         DeclarationNode::Aggregate aggKey;
    148         DeclarationNode::TypeClass tclass;
    149         StatementNode * sn;
    150         ConstantExpr * constant;
    151         ForCtl * fctl;
    152         LabelNode * label;
    153         InitializerNode * in;
    154         OperKinds op;
    155         std::string * str;
    156         bool flag;
    157 }
    158 
    159 %type<tok> identifier  no_01_identifier  no_attr_identifier zero_one
    160 %type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  no_01_identifier_or_type_name  attr_name
     159%type<tok> identifier  no_attr_identifier  zero_one
     160%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  attr_name
    161161%type<constant> string_literal
    162162%type<str> string_literal_list
     
    191191%type<sn> case_value_list                               case_label                                      case_label_list
    192192%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    193 %type<sn> handler_list                                  handler_clause                          finally_clause
     193%type<sn> /* handler_list */                    handler_clause                          finally_clause
    194194
    195195// declarations
     
    205205%type<en>   bit_subrange_size_opt bit_subrange_size
    206206
    207 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type_name indirect_type_name
     207%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
    208208
    209209%type<decl> trait_declaration trait_declaration_list trait_declaring_list trait_specifier
     
    259259%type<decl> type_declarator type_declarator_name type_declaring_list
    260260
    261 %type<decl> typedef typedef_type_specifier typedef_declaration typedef_declaration_specifier typedef_expression
     261%type<decl> type_declaration_specifier type_type_specifier type_name typegen_name
     262%type<decl> typedef typedef_declaration typedef_expression
    262263
    263264%type<decl> variable_type_redeclarator type_ptr type_array type_function
    264265
    265266%type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function
    266 %type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name
    267 
    268 %type<decl> type_name type_name_no_function
    269 %type<decl> type_parameter type_parameter_list
    270 
    271 %type<en> type_name_list
     267
     268%type<decl> type type_no_function
     269%type<decl> type_parameter type_parameter_list type_initializer_opt
     270
     271%type<en> type_list
    272272
    273273%type<decl> type_qualifier type_qualifier_name type_qualifier_list_opt type_qualifier_list
     
    349349        IDENTIFIER
    350350        | ATTR_IDENTIFIER                                                                       // CFA
    351         | zero_one                                                                                      // CFA
    352         ;
    353 
    354 no_01_identifier:
    355         IDENTIFIER
    356         | ATTR_IDENTIFIER                                                                       // CFA
    357351        ;
    358352
    359353no_attr_identifier:
    360354        IDENTIFIER
    361         | zero_one                                                                                      // CFA
    362355        ;
    363356
     
    365358        ZERO
    366359        | ONE
    367         ;
     360        ;
    368361
    369362string_literal:
     
    393386        | '(' compound_statement ')'                                            // GCC, lambda expression
    394387                { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
    395         | primary_expression '{' argument_expression_list '}' // CFA
     388        | primary_expression '{' argument_expression_list '}' // CFA, constructor call
    396389                {
    397390                        Token fn;
     
    399392                        $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
    400393                }
     394        | type_name '.' no_attr_identifier                                      // CFA, nested type
     395                { $$ = nullptr; }                                                               // FIX ME
     396        | type_name '.' '[' push field_list pop ']'                     // CFA, nested type / tuple field selector
     397                { $$ = nullptr; }                                                               // FIX ME
    401398        ;
    402399
     
    429426        | postfix_expression DECR
    430427                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
    431         | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
     428        | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
    432429                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
    433430        | '^' primary_expression '{' argument_expression_list '}' // CFA
     
    481478        | no_attr_identifier fraction_constants
    482479                {
    483                         if( (*$1) == "0" || (*$1) == "1" ) {
    484                                 $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantZeroOne( *$1 ), $2 ) );
    485                         } else {
    486                                 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
    487                         }
     480                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
     481                }
     482        | zero_one fraction_constants
     483                {
     484                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantZeroOne( *$1 ), $2 ) );
    488485                }
    489486        ;
     
    533530        | SIZEOF unary_expression
    534531                { $$ = new ExpressionNode( build_sizeOfexpr( $2 ) ); }
    535         | SIZEOF '(' type_name_no_function ')'
     532        | SIZEOF '(' type_no_function ')'
    536533                { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); }
    537534        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    538535                { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); }
    539         | ALIGNOF '(' type_name_no_function ')'                         // GCC, type alignment
     536        | ALIGNOF '(' type_no_function ')'                              // GCC, type alignment
    540537                { $$ = new ExpressionNode( build_alignOftype( $3 ) ); }
    541         | OFFSETOF '(' type_name_no_function ',' no_attr_identifier ')'
     538        | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
    542539                { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); }
    543540        | ATTR_IDENTIFIER
     
    545542        | ATTR_IDENTIFIER '(' argument_expression ')'
    546543                { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); }
    547         | ATTR_IDENTIFIER '(' type_name ')'
     544        | ATTR_IDENTIFIER '(' type ')'
    548545                { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); }
    549546//      | ANDAND IDENTIFIER                                                                     // GCC, address of label
    550 //              { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2, true ) ); }
     547//              { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2 ) ); }
    551548        ;
    552549
     
    567564cast_expression:
    568565        unary_expression
    569         | '(' type_name_no_function ')' cast_expression
     566        | '(' type_no_function ')' cast_expression
    570567                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    571 //      | '(' type_name_no_function ')' tuple
     568//      | '(' type_no_function ')' tuple
    572569//              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    573570        ;
     
    656653        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    657654                { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); }
    658 //      | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression
    659 //              { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }
    660655        ;
    661656
     
    669664        | unary_expression assignment_operator assignment_expression
    670665                { $$ = new ExpressionNode( build_binary_ptr( $2, $1, $3 ) ); }
    671 //      | tuple assignment_opt                                                          // CFA, tuple expression
    672 //              { $$ = ( $2 == 0 ) ? $1 : new ExpressionNode( build_binary_ptr( OperKinds::Assign, $1, $2 ) ); }
    673666        ;
    674667
     
    936929                { $$ = new StatementNode( build_throw( $2 ) ); }
    937930        | THROWRESUME assignment_expression_opt ';'                     // handles reresume
    938                 { $$ = new StatementNode( build_throw( $2 ) ); }
     931                { $$ = new StatementNode( build_resume( $2 ) ); }
    939932        | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume
    940                 { $$ = new StatementNode( build_throw( $2 ) ); }
     933                { $$ = new StatementNode( build_resume_at( $2, $4 ) ); }
    941934        ;
    942935
    943936exception_statement:
    944         TRY compound_statement handler_list
     937        TRY compound_statement handler_clause
    945938                { $$ = new StatementNode( build_try( $2, $3, 0 ) ); }
    946939        | TRY compound_statement finally_clause
    947940                { $$ = new StatementNode( build_try( $2, 0, $3 ) ); }
    948         | TRY compound_statement handler_list finally_clause
     941        | TRY compound_statement handler_clause finally_clause
    949942                { $$ = new StatementNode( build_try( $2, $3, $4 ) ); }
    950943        ;
    951944
    952 handler_list:
    953         handler_clause
    954                 // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block.
    955         | CATCH '(' ELLIPSIS ')' compound_statement
    956                 { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
    957         | handler_clause CATCH '(' ELLIPSIS ')' compound_statement
    958                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
    959         | CATCHRESUME '(' ELLIPSIS ')' compound_statement
    960                 { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
    961         | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement
    962                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
    963         ;
     945//handler_list:
     946//      handler_clause
     947//              // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block.
     948//      | CATCH '(' ELLIPSIS ')' compound_statement
     949//              { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
     950//      | handler_clause CATCH '(' ELLIPSIS ')' compound_statement
     951//              { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
     952//      | CATCHRESUME '(' ELLIPSIS ')' compound_statement
     953//              { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
     954//      | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement
     955//              { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
     956//      ;
    964957
    965958handler_clause:
    966         CATCH '(' push push exception_declaration pop ')' compound_statement pop
    967                 { $$ = new StatementNode( build_catch( $5, $8 ) ); }
     959        // TEMPORARY, TEST EXCEPTIONS
     960        CATCH '(' push push INTEGERconstant pop ')' compound_statement pop
     961                { $$ = new StatementNode( build_catch( CatchStmt::Terminate, nullptr, new ExpressionNode( build_constantInteger( *$5 ) ), $8 ) ); }
     962        | handler_clause CATCH '(' push push INTEGERconstant pop ')' compound_statement pop
     963                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Terminate, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); }
     964
     965        | CATCH '(' push push exception_declaration pop ')' compound_statement pop
     966                { $$ = new StatementNode( build_catch( CatchStmt::Terminate, $5, nullptr, $8 ) ); }
    968967        | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop
    969                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }
     968                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Terminate, $6, nullptr, $9 ) ) ); }
    970969        | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    971                 { $$ = new StatementNode( build_catch( $5, $8 ) ); }
     970                { $$ = new StatementNode( build_catch( CatchStmt::Resume, $5, nullptr, $8 ) ); }
    972971        | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    973                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }
     972                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Resume, $6, nullptr, $9 ) ) ); }
    974973        ;
    975974
     
    13501349        basic_declaration_specifier
    13511350        | sue_declaration_specifier
    1352         | typedef_declaration_specifier
    1353         | typegen_declaration_specifier
     1351        | type_declaration_specifier
    13541352        ;
    13551353
     
    13621360        basic_declaration_specifier
    13631361        | sue_declaration_specifier_nobody
    1364         | typedef_declaration_specifier
    1365         | typegen_declaration_specifier
     1362        | type_declaration_specifier
    13661363        ;
    13671364
     
    13691366        basic_type_specifier
    13701367        | sue_type_specifier
    1371         | typedef_type_specifier
    1372         | typegen_type_specifier
     1368        | type_type_specifier
    13731369        ;
    13741370
     
    13811377        basic_type_specifier
    13821378        | sue_type_specifier_nobody
    1383         | typedef_type_specifier
    1384         | typegen_type_specifier
     1379        | type_type_specifier
    13851380        ;
    13861381
     
    15171512
    15181513basic_type_specifier:
    1519         direct_type_name
    1520         | type_qualifier_list_opt indirect_type_name type_qualifier_list_opt
     1514        direct_type
     1515        | type_qualifier_list_opt indirect_type type_qualifier_list_opt
    15211516                { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); }
    15221517        ;
    15231518
    1524 direct_type_name:
     1519direct_type:
    15251520                // A semantic check is necessary for conflicting type qualifiers.
    15261521        basic_type_name
    15271522        | type_qualifier_list basic_type_name
    15281523                { $$ = $2->addQualifiers( $1 ); }
    1529         | direct_type_name type_qualifier
     1524        | direct_type type_qualifier
    15301525                { $$ = $1->addQualifiers( $2 ); }
    1531         | direct_type_name basic_type_name
     1526        | direct_type basic_type_name
    15321527                { $$ = $1->addType( $2 ); }
    15331528        ;
    15341529
    1535 indirect_type_name:
    1536         TYPEOF '(' type_name ')'                                                        // GCC: typeof(x) y;
     1530indirect_type:
     1531        TYPEOF '(' type ')'                                                                     // GCC: typeof(x) y;
    15371532                { $$ = $3; }
    15381533        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
    15391534                { $$ = DeclarationNode::newTypeof( $3 ); }
    1540         | ATTR_TYPEGENname '(' type_name ')'                            // CFA: e.g., @type(x) y;
     1535        | ATTR_TYPEGENname '(' type ')'                                         // CFA: e.g., @type(x) y;
    15411536                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    15421537        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
     
    15561551sue_type_specifier:                                                                             // struct, union, enum + type specifier
    15571552        elaborated_type
    1558         | type_qualifier_list elaborated_type
    1559                 { $$ = $2->addQualifiers( $1 ); }
     1553        | type_qualifier_list
     1554                { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
     1555          elaborated_type
     1556                { $$ = $3->addQualifiers( $1 ); }
    15601557        | sue_type_specifier type_qualifier
    15611558                { $$ = $1->addQualifiers( $2 ); }
     
    15801577        ;
    15811578
    1582 typedef_declaration_specifier:
    1583         typedef_type_specifier
    1584         | declaration_qualifier_list typedef_type_specifier
     1579type_declaration_specifier:
     1580        type_type_specifier
     1581        | declaration_qualifier_list type_type_specifier
    15851582                { $$ = $2->addQualifiers( $1 ); }
    1586         | typedef_declaration_specifier storage_class           // remaining OBSOLESCENT (see 2)
     1583        | type_declaration_specifier storage_class                      // remaining OBSOLESCENT (see 2)
    15871584                { $$ = $1->addQualifiers( $2 ); }
    1588         | typedef_declaration_specifier storage_class type_qualifier_list
     1585        | type_declaration_specifier storage_class type_qualifier_list
    15891586                { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
    15901587        ;
    15911588
    1592 typedef_type_specifier:                                                                 // typedef types
     1589type_type_specifier:                                                                    // typedef types
     1590        type_name
     1591        | type_qualifier_list type_name
     1592                { $$ = $2->addQualifiers( $1 ); }
     1593        | type_type_specifier type_qualifier
     1594                { $$ = $1->addQualifiers( $2 ); }
     1595        ;
     1596
     1597type_name:
    15931598        TYPEDEFname
    15941599                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    1595         | type_qualifier_list TYPEDEFname
    1596                 { $$ = DeclarationNode::newFromTypedef( $2 )->addQualifiers( $1 ); }
    1597         | typedef_type_specifier type_qualifier
    1598                 { $$ = $1->addQualifiers( $2 ); }
     1600        | '.' TYPEDEFname
     1601                { $$ = DeclarationNode::newFromTypedef( $2 ); } // FIX ME
     1602        | type_name '.' TYPEDEFname
     1603                { $$ = DeclarationNode::newFromTypedef( $3 ); } // FIX ME
     1604        | typegen_name
     1605        | '.' typegen_name
     1606                { $$ = $2; }                                                                    // FIX ME
     1607        | type_name '.' typegen_name
     1608                { $$ = $3; }                                                                    // FIX ME
     1609        ;
     1610
     1611typegen_name:                                                                                   // CFA
     1612        TYPEGENname '(' ')'
     1613                { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
     1614        | TYPEGENname '(' type_list ')'
     1615                { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
    15991616        ;
    16001617
     
    16131630                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    16141631        | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
    1615                 { typedefTable.makeTypedef( *$3 ); }
     1632                {
     1633                        typedefTable.makeTypedef( *$3 );                        // create typedef
     1634                        if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update
     1635                        forall = false;                                                         // reset
     1636                }
    16161637          '{' field_declaration_list '}'
    16171638                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1618         | aggregate_key attribute_list_opt '(' type_name_list ')' '{' field_declaration_list '}' // CFA
     1639        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA
    16191640                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
    16201641        | aggregate_type_nobody
     
    16221643
    16231644aggregate_type_nobody:                                                                  // struct, union - {...}
    1624         aggregate_key attribute_list_opt no_attr_identifier_or_type_name
     1645        aggregate_key attribute_list_opt no_attr_identifier
    16251646                {
    16261647                        typedefTable.makeTypedef( *$3 );
    16271648                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    16281649                }
    1629         | aggregate_key attribute_list_opt typegen_name         // CFA, S/R conflict
     1650        | aggregate_key attribute_list_opt TYPEDEFname
     1651                {
     1652                        typedefTable.makeTypedef( *$3 );
     1653                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
     1654                }
     1655        | aggregate_key attribute_list_opt typegen_name         // CFA
    16301656                { $$ = $3->addQualifiers( $2 ); }
    16311657        ;
     
    18651891        ;
    18661892
    1867 no_01_identifier_or_type_name:
    1868         no_01_identifier
    1869         | TYPEDEFname
    1870         | TYPEGENname
    1871         ;
    1872 
    18731893no_attr_identifier_or_type_name:
    18741894        no_attr_identifier
     
    18771897        ;
    18781898
    1879 type_name_no_function:                                                                  // sizeof, alignof, cast (constructor)
     1899type_no_function:                                                                               // sizeof, alignof, cast (constructor)
    18801900        cfa_abstract_declarator_tuple                                           // CFA
    18811901        | type_specifier
     
    18841904        ;
    18851905
    1886 type_name:                                                                                              // typeof, assertion
    1887         type_name_no_function
     1906type:                                                                                                   // typeof, assertion
     1907        type_no_function
    18881908        | cfa_abstract_function                                                         // CFA
    18891909        ;
     
    19251945designation:
    19261946        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
    1927         | no_attr_identifier_or_type_name ':'                           // GCC, field name
     1947        | no_attr_identifier ':'                                                        // GCC, field name
    19281948                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    19291949        ;
     
    19371957
    19381958designator:
    1939         '.' no_attr_identifier_or_type_name                                     // C99, field name
     1959        '.' no_attr_identifier                                                          // C99, field name
    19401960                { $$ = new ExpressionNode( build_varref( $2 ) ); }
    19411961        | '[' push assignment_expression pop ']'                        // C99, single array element
     
    19681988//     on type arguments of polymorphic functions.
    19691989
    1970 typegen_declaration_specifier:                                                  // CFA
    1971         typegen_type_specifier
    1972         | declaration_qualifier_list typegen_type_specifier
    1973                 { $$ = $2->addQualifiers( $1 ); }
    1974         | typegen_declaration_specifier storage_class           // remaining OBSOLESCENT (see 2)
    1975                 { $$ = $1->addQualifiers( $2 ); }
    1976         | typegen_declaration_specifier storage_class type_qualifier_list
    1977                 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
    1978         ;
    1979 
    1980 typegen_type_specifier:                                                                 // CFA
    1981         typegen_name
    1982         | type_qualifier_list typegen_name
    1983                 { $$ = $2->addQualifiers( $1 ); }
    1984         | typegen_type_specifier type_qualifier
    1985                 { $$ = $1->addQualifiers( $2 ); }
    1986         ;
    1987 
    1988 typegen_name:                                                                                   // CFA
    1989         TYPEGENname '(' type_name_list ')'
    1990                 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
    1991         ;
    1992 
    19931990type_parameter_list:                                                                    // CFA
    1994         type_parameter assignment_opt
    1995         | type_parameter_list ',' type_parameter assignment_opt
     1991        type_parameter
     1992                { $$ = $1; }
     1993        | type_parameter_list ',' type_parameter
    19961994                { $$ = $1->appendList( $3 ); }
     1995        ;
     1996
     1997type_initializer_opt:                                                                   // CFA
     1998        // empty
     1999                { $$ = nullptr; }
     2000        | '=' type
     2001                { $$ = $2; }
    19972002        ;
    19982003
     
    20002005        type_class no_attr_identifier_or_type_name
    20012006                { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
    2002           assertion_list_opt
    2003                 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); }
     2007          type_initializer_opt assertion_list_opt
     2008                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    20042009        | type_specifier identifier_parameter_declarator
    20052010        ;
     
    20242029
    20252030assertion:                                                                                              // CFA
    2026         '|' no_attr_identifier_or_type_name '(' type_name_list ')'
     2031        '|' no_attr_identifier_or_type_name '(' type_list ')'
    20272032                {
    20282033                        typedefTable.openTrait( *$2 );
     
    20312036        | '|' '{' push trait_declaration_list '}'
    20322037                { $$ = $4; }
    2033         | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_name_list ')'
     2038        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
    20342039                { $$ = nullptr; }
    20352040        ;
    20362041
    2037 type_name_list:                                                                                 // CFA
    2038         type_name
     2042type_list:                                                                                              // CFA
     2043        type
    20392044                { $$ = new ExpressionNode( build_typevalue( $1 ) ); }
    20402045        | assignment_expression
    2041         | type_name_list ',' type_name
     2046        | type_list ',' type
    20422047                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
    2043         | type_name_list ',' assignment_expression
     2048        | type_list ',' assignment_expression
    20442049                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    20452050        ;
     
    20572062        type_declarator_name assertion_list_opt
    20582063                { $$ = $1->addAssertions( $2 ); }
    2059         | type_declarator_name assertion_list_opt '=' type_name
     2064        | type_declarator_name assertion_list_opt '=' type
    20602065                { $$ = $1->addAssertions( $2 )->addType( $4 ); }
    20612066        ;
     
    20672072                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    20682073                }
    2069         | no_01_identifier_or_type_name '(' push type_parameter_list pop ')'
     2074        | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
    20702075                {
    20712076                        typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
     
    20932098        ;
    20942099
    2095 trait_declaration_list:                                                         // CFA
     2100trait_declaration_list:                                                                 // CFA
    20962101        trait_declaration
    20972102        | trait_declaration_list push trait_declaration
     
    20992104        ;
    21002105
    2101 trait_declaration:                                                                      // CFA
     2106trait_declaration:                                                                              // CFA
    21022107        cfa_trait_declaring_list pop ';'
    21032108        | trait_declaring_list pop ';'
  • src/Parser/parserutility.cc

    r9c951e3 rb1e63ac5  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // parseutility.cc --
     7// parserutility.cc --
    88//
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:30:39 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 14 23:45:03 2016
    13 // Update Count     : 3
     12// Last Modified On : Wed Jun 28 22:11:32 2017
     13// Update Count     : 7
    1414//
    1515
    16 #include "parseutility.h"
     16#include "parserutility.h"
    1717#include "SynTree/Type.h"
    1818#include "SynTree/Expression.h"
     
    2626        UntypedExpr *comparison = new UntypedExpr( new NameExpr( "?!=?" ) );
    2727        comparison->get_args().push_back( orig );
    28         comparison->get_args().push_back( new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0" ) ) );
     28        comparison->get_args().push_back( new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0", (unsigned long long int)0 ) ) );
    2929        return new CastExpr( comparison, new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    3030}
  • src/Parser/parserutility.h

    r9c951e3 rb1e63ac5  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // parseutility.h --
     7// parserutility.h --
    88//
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:31:46 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 15:32:58 2015
    13 // Update Count     : 2
     12// Last Modified On : Wed Jun 28 22:11:40 2017
     13// Update Count     : 3
    1414//
    1515
Note: See TracChangeset for help on using the changeset viewer.