Changeset 3f7e12cb for src/Parser


Ignore:
Timestamp:
Nov 8, 2017, 5:43:33 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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, stuck-waitfor-destruct, with_gc
Children:
954908d
Parents:
78315272 (diff), e35f30a (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/Parser
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r78315272 r3f7e12cb  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 12:34:05 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 10 17:02:00 2017
    13 // Update Count     : 1021
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Sep 23 18:16:48 2017
     13// Update Count     : 1024
    1414//
    1515
     
    4040using namespace std;
    4141
    42 // These must remain in the same order as the corresponding DeclarationNode enumerations.
    43 const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicTypeNames" };
     42// These must harmonize with the corresponding DeclarationNode enumerations.
     43const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "int128", "float80", "float128", "NoBasicTypeNames" };
    4444const char * DeclarationNode::complexTypeNames[] = { "_Complex", "_Imaginary", "NoComplexTypeNames" };
    4545const char * DeclarationNode::signednessNames[] = { "signed", "unsigned", "NoSignednessNames" };
     
    10311031
    10321032        if ( variable.tyClass != NoTypeClass ) {
    1033                 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype };
    1034                 assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." );
     1033                // otype is internally converted to dtype + otype parameters
     1034                static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype };
     1035                assertf( sizeof(kindMap)/sizeof(kindMap[0]) == NoTypeClass, "DeclarationNode::build: kindMap is out of sync." );
    10351036                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    1036                 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.initializer ? variable.initializer->buildType() : nullptr );
     1037                TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == Otype, variable.initializer ? variable.initializer->buildType() : nullptr );
    10371038                buildList( variable.assertions, ret->get_assertions() );
    10381039                return ret;
  • src/Parser/ExpressionNode.cc

    r78315272 r3f7e12cb  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Sep 14 23:09:34 2017
    13 // Update Count     : 690
     12// Last Modified On : Wed Sep 27 22:51:55 2017
     13// Update Count     : 781
    1414//
    1515
     
    6060static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    6161
     62static const char * lnthsInt[2][6] = {
     63        { "int8_t", "int16_t", "int32_t", "int64_t", "size_t", },
     64        { "uint8_t", "uint16_t", "uint32_t", "uint64_t", "size_t", }
     65}; // lnthsInt
     66
     67static inline void checkLNInt( string & str, int & lnth, int & size ) {
     68        string::size_type posn = str.find_first_of( "lL" ), start = posn;
     69  if ( posn == string::npos ) return;
     70        size = 4;                                                                                       // assume largest size
     71        posn += 1;                                                                                      // advance to size
     72        if ( str[posn] == '8' ) {                                                       // 8
     73                lnth = 0;
     74        } else if ( str[posn] == '1' ) {
     75                posn += 1;
     76                if ( str[posn] == '6' ) {                                               // 16
     77                        lnth = 1;
     78                } else {                                                                                // 128
     79                        posn += 1;
     80                        lnth = 5;
     81                } // if
     82        } else {
     83                if ( str[posn] == '3' ) {                                               // 32
     84                        lnth = 2;
     85                } else if ( str[posn] == '6' ) {                                // 64
     86                        lnth = 3;
     87                } else {
     88                        assertf( false, "internal error, bad integral length %s", str.c_str() );
     89                } // if
     90                posn += 1;
     91        } // if
     92        str.erase( start, posn - start + 1 );                           // remove length suffix
     93} // checkLNInt
     94
    6295static void sepNumeric( string & str, string & units ) {
    6396        string::size_type posn = str.find_first_of( "`" );
     
    69102
    70103Expression * build_constantInteger( string & str ) {
    71         static const BasicType::Kind kind[2][5] = {
     104        static const BasicType::Kind kind[2][6] = {
    72105                // short (h) must be before char (hh)
    73                 { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
    74                 { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt },
     106                { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt, BasicType::SignedInt128, },
     107                { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::UnsignedInt128, },
    75108        };
    76109
    77         string units;                                                                           // units
     110        string units;
    78111        sepNumeric( str, units );                                                       // separate constant from units
    79112
    80113        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
    81         int size;                                                                                       // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => size_t
     114        int size;                                                                                       // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => int128
     115        int lnth = -1;                                                                          // literal length
     116
    82117        unsigned long long int v;                                                       // converted integral value
    83118        size_t last = str.length() - 1;                                         // last character of constant
     
    140175                        } // if
    141176                        str.erase( last - size - 1, size + 1 );         // remove 'h'/"hh"
     177                } else {                                                                                // suffix "ln" ?
     178                        checkLNInt( str, lnth, size );
    142179                } // if
    143180        } else if ( checkL( str[ last ] ) ) {                           // suffix 'l' ?
     
    163200                str.erase( last - size, size + 1 );                             // remove 'h'/"hh"
    164201        } else if ( checkZ( str[last] ) ) {                                     // suffix 'z' ?
    165                 size = 5;
     202                lnth = 4;
    166203                str.erase( last, 1 );                                                   // remove 'z'
    167         } // if
    168 
     204        } else {                                                                                        // suffix "ln" ?
     205                checkLNInt( str, lnth, size );
     206        } // if
     207
     208        assert( 0 <= size && size < 6 );
     209        // Constant type is correct for overload resolving.
    169210        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
    170         if ( Unsigned && size < 2 ) {                                           // less than int ?
    171                 // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which eliminates warnings for large values.
     211        if ( Unsigned && size < 2 ) {                                           // hh or h, less than int ?
     212                // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which unfortunately eliminates warnings for large values.
    172213                ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );
    173         } else if ( size == 5 ) {                                                       // explicit cast to size_t
    174                 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), "size_t", false ) );
     214        } else if ( lnth != -1 ) {                                                      // explicit length ?
     215                if ( lnth == 5 ) {                                                              // int128 ?
     216                        size = 5;
     217                        ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );
     218                } else {
     219                        ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][lnth], false ) );
     220                } // if
    175221        } // if
    176222  CLEANUP:
     
    182228        return ret;
    183229} // build_constantInteger
     230
     231
     232static inline void checkLNFloat( string & str, int & lnth, int & size ) {
     233        string::size_type posn = str.find_first_of( "lL" ), start = posn;
     234  if ( posn == string::npos ) return;
     235        size = 2;                                                                                       // assume largest size
     236        lnth = 0;
     237        posn += 1;                                                                                      // advance to size
     238        if ( str[posn] == '3' ) {                                                       // 32
     239                size = 0;
     240        } else if ( str[posn] == '6' ) {                                        // 64
     241                size = 1;
     242        } else if ( str[posn] == '8' || str[posn] == '1' ) { // 80, 128
     243                size = 2;
     244                if ( str[posn] == '1' ) posn += 1;
     245        } else {
     246                assertf( false, "internal error, bad floating point length %s", str.c_str() );
     247        } // if
     248        posn += 1;
     249        str.erase( start, posn - start + 1 );                           // remove length suffix
     250} // checkLNFloat
     251
    184252
    185253Expression * build_constantFloat( string & str ) {
     
    189257        };
    190258
    191         string units;                                                                           // units
     259        string units;
    192260        sepNumeric( str, units );                                                       // separate constant from units
    193261
    194262        bool complx = false;                                                            // real, complex
    195         int size = 1;                                                                           // 0 => float, 1 => double (default), 2 => long double
     263        int size = 1;                                                                           // 0 => float, 1 => double, 2 => long double
     264        int lnth = -1;                                                                          // literal length
    196265        // floating-point constant has minimum of 2 characters: 1. or .1
    197266        size_t last = str.length() - 1;
     
    211280        } else if ( checkL( str[last] ) ) {                                     // long double ?
    212281                size = 2;
     282        } else {
     283                size = 1;                                                                               // double (default)
     284                checkLNFloat( str, lnth, size );
    213285        } // if
    214286        if ( ! complx && checkI( str[last - 1] ) ) {            // imaginary ?
     
    216288        } // if
    217289
     290        assert( 0 <= size && size < 3 );
    218291        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
     292        if ( lnth != -1 ) {                                                                     // explicit length ?
     293                ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[complx][size] ) );
     294        } // if
    219295        if ( units.length() != 0 ) {
    220296                ret = new UntypedExpr( new NameExpr( units ), { ret } );
     
    321397
    322398NameExpr * build_varref( const string * name ) {
    323         NameExpr * expr = new NameExpr( *name, nullptr );
     399        NameExpr * expr = new NameExpr( *name );
    324400        delete name;
    325401        return expr;
     
    412488        list< Expression * > args;
    413489        buildMoveList( expr_node, args );
    414         return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
     490        return new UntypedExpr( maybeMoveBuild< Expression >(function), args );
    415491} // build_func
    416492
  • src/Parser/ParseNode.h

    r78315272 r3f7e12cb  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Sep 14 23:09:39 2017
    13 // Update Count     : 815
     12// Last Modified On : Sat Sep 23 18:11:22 2017
     13// Update Count     : 821
    1414//
    1515
     
    4747#define YYLTYPE_IS_DECLARED 1 /* alert the parser that we have our own definition */
    4848
    49 extern char * yyfilename;
    50 extern int yylineno;
    5149extern YYLTYPE yylloc;
    5250
     
    197195class DeclarationNode : public ParseNode {
    198196  public:
    199         enum BasicType { Void, Bool, Char, Int, Float, Double, LongDouble, NoBasicType };
     197        // These enumerations must harmonize with their names.
     198        enum BasicType { Void, Bool, Char, Int, Float, Double, LongDouble, Int128, Float80, Float128, NoBasicType };
     199        static const char * basicTypeNames[];
    200200        enum ComplexType { Complex, Imaginary, NoComplexType };
     201        static const char * complexTypeNames[];
    201202        enum Signedness { Signed, Unsigned, NoSignedness };
     203        static const char * signednessNames[];
    202204        enum Length { Short, Long, LongLong, NoLength };
     205        static const char * lengthNames[];
    203206        enum Aggregate { Struct, Union, Trait, Coroutine, Monitor, Thread, NoAggregate };
     207        static const char * aggregateNames[];
    204208        enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass };
     209        static const char * typeClassNames[];
    205210        enum BuiltinType { Valist, Zero, One, NoBuiltinType };
    206 
    207         static const char * basicTypeNames[];
    208         static const char * complexTypeNames[];
    209         static const char * signednessNames[];
    210         static const char * lengthNames[];
    211         static const char * aggregateNames[];
    212         static const char * typeClassNames[];
    213211        static const char * builtinTypeNames[];
    214212
  • src/Parser/StatementNode.cc

    r78315272 r3f7e12cb  
    234234                target,
    235235                maybeMoveBuild<Statement >( stmt ),
    236                 maybeMoveBuild<Expression>( when )
     236                notZeroExpr( maybeMoveBuild<Expression>( when ) )
    237237        });
    238238
     
    250250        delete targetExpr;
    251251
    252         node->clauses.push_back( WaitForStmt::Clause{
     252        node->clauses.insert( node->clauses.begin(), WaitForStmt::Clause{
    253253                std::move( target ),
    254254                maybeMoveBuild<Statement >( stmt ),
    255                 maybeMoveBuild<Expression>( when )
     255                notZeroExpr( maybeMoveBuild<Expression>( when ) )
    256256        });
    257257
     
    265265                node->timeout.time      = maybeMoveBuild<Expression>( timeout );
    266266                node->timeout.statement = maybeMoveBuild<Statement >( stmt    );
    267                 node->timeout.condition = maybeMoveBuild<Expression>( when    );
     267                node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    268268        }
    269269        else {
    270                 node->orelse.statement  = maybeMoveBuild<Statement >( stmt    );
    271                 node->orelse.condition  = maybeMoveBuild<Expression>( when    );
     270                node->orelse.statement  = maybeMoveBuild<Statement >( stmt );
     271                node->orelse.condition  = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    272272        }
    273273
     
    280280        node->timeout.time      = maybeMoveBuild<Expression>( timeout );
    281281        node->timeout.statement = maybeMoveBuild<Statement >( stmt    );
    282         node->timeout.condition = maybeMoveBuild<Expression>( when    );
     282        node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    283283
    284284        node->orelse.statement = maybeMoveBuild<Statement >( else_stmt );
    285         node->orelse.condition = maybeMoveBuild<Expression>( else_when );
     285        node->orelse.condition  = notZeroExpr( maybeMoveBuild<Expression>( else_when ) );
    286286
    287287        return node;
    288288}
    289 
    290 // WaitForStmt::Target build_waitfor( const std::string * name, ExpressionNode * arguments ) {
    291 //       return WaitForStmt::Clause{
    292 
    293 //       };
    294 // }
    295289
    296290Statement *build_compound( StatementNode *first ) {
  • src/Parser/TypeData.cc

    r78315272 r3f7e12cb  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep  1 23:13:38 2017
    13 // Update Count     : 569
     12// Last Modified On : Mon Sep 25 18:33:41 2017
     13// Update Count     : 587
    1414//
    1515
     
    9898} // TypeData::TypeData
    9999
     100
    100101TypeData::~TypeData() {
    101102        delete base;
     
    161162        } // switch
    162163} // TypeData::~TypeData
     164
    163165
    164166TypeData * TypeData::clone() const {
     
    235237} // TypeData::clone
    236238
     239
    237240void TypeData::print( ostream &os, int indent ) const {
    238241        for ( int i = 0; i < Type::NumTypeQualifier; i += 1 ) {
     
    399402} // TypeData::print
    400403
     404
    401405template< typename ForallList >
    402406void buildForall( const DeclarationNode * firstNode, ForallList &outputList ) {
    403407        buildList( firstNode, outputList );
    404         for ( typename ForallList::iterator i = outputList.begin(); i != outputList.end(); ++i ) {
     408        auto n = firstNode;
     409        for ( typename ForallList::iterator i = outputList.begin(); i != outputList.end(); ++i, n = (DeclarationNode*)n->get_next() ) {
    405410                TypeDecl * td = static_cast<TypeDecl *>(*i);
    406                 if ( td->get_kind() == TypeDecl::Any ) {
     411                if ( n->variable.tyClass == DeclarationNode::Otype ) {
    407412                        // add assertion parameters to `type' tyvars in reverse order
    408413                        // add dtor:  void ^?{}(T *)
     
    430435                } // if
    431436        } // for
    432 }
     437} // buildForall
     438
    433439
    434440Type * typebuild( const TypeData * td ) {
     
    477483} // typebuild
    478484
     485
    479486TypeData * typeextractAggregate( const TypeData * td, bool toplevel ) {
    480487        TypeData * ret = nullptr;
     
    504511} // typeextractAggregate
    505512
     513
    506514Type::Qualifiers buildQualifiers( const TypeData * td ) {
    507515        return td->qualifiers;
    508516} // buildQualifiers
    509517
     518
     519static string genTSError( string msg, DeclarationNode::BasicType basictype ) {
     520        throw SemanticError( string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );
     521} // genTSError
     522
    510523Type * buildBasicType( const TypeData * td ) {
    511524        BasicType::Kind ret;
     
    513526        switch ( td->basictype ) {
    514527          case DeclarationNode::Void:
    515                 if ( td->signedness != DeclarationNode::NoSignedness && td->length != DeclarationNode::NoLength ) {
    516                         throw SemanticError( "invalid type specifier \"void\" in type: ", td );
    517                 } // if
    518 
     528                if ( td->signedness != DeclarationNode::NoSignedness ) {
     529                        genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );
     530                } // if
     531                if ( td->length != DeclarationNode::NoLength ) {
     532                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
     533                } // if
    519534                return new VoidType( buildQualifiers( td ) );
    520535                break;
     
    522537          case DeclarationNode::Bool:
    523538                if ( td->signedness != DeclarationNode::NoSignedness ) {
    524                         throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessNames[ td->signedness ] + " in type: ", td );
     539                        genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );
    525540                } // if
    526541                if ( td->length != DeclarationNode::NoLength ) {
    527                         throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthNames[ td->length ] + " in type: ", td );
     542                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
    528543                } // if
    529544
     
    538553
    539554                if ( td->length != DeclarationNode::NoLength ) {
    540                         throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthNames[ td->length ] + " in type: ", td );
     555                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
    541556                } // if
    542557
     
    557572                break;
    558573
     574          case DeclarationNode::Int128:
     575                ret = td->signedness == 1 ? BasicType::UnsignedInt128 : BasicType::SignedInt128;
     576                if ( td->length != DeclarationNode::NoLength ) {
     577                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
     578                } // if
     579                break;
     580
    559581          case DeclarationNode::Float:
     582          case DeclarationNode::Float80:
     583          case DeclarationNode::Float128:
    560584          case DeclarationNode::Double:
    561585          case DeclarationNode::LongDouble:                                     // not set until below
     
    568592          FloatingPoint: ;
    569593                if ( td->signedness != DeclarationNode::NoSignedness ) {
    570                         throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessNames[ td->signedness ] + " in type: ", td );
     594                        genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );
    571595                } // if
    572596                if ( td->length == DeclarationNode::Short || td->length == DeclarationNode::LongLong ) {
    573                         throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthNames[ td->length ] + " in type: ", td );
     597                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
    574598                } // if
    575599                if ( td->basictype == DeclarationNode::Float && td->length == DeclarationNode::Long ) {
    576                         throw SemanticError( "invalid type specifier \"long\" in type: ", td );
     600                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
    577601                } // if
    578602                if ( td->length == DeclarationNode::Long ) {
     
    593617                goto Integral;
    594618          default:
    595                 assert(false);
     619                assertf( false, "unknown basic type" );
    596620                return nullptr;
    597621        } // switch
     
    601625        return bt;
    602626} // buildBasicType
     627
    603628
    604629PointerType * buildPointer( const TypeData * td ) {
     
    612637        return pt;
    613638} // buildPointer
     639
    614640
    615641ArrayType * buildArray( const TypeData * td ) {
     
    626652} // buildArray
    627653
     654
    628655ReferenceType * buildReference( const TypeData * td ) {
    629656        ReferenceType * rt;
     
    637664} // buildReference
    638665
     666
    639667AggregateDecl * buildAggregate( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
    640668        assert( td->kind == TypeData::Aggregate );
     
    665693        return at;
    666694} // buildAggregate
     695
    667696
    668697ReferenceToType * buildComAggInst( const TypeData * type, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
     
    722751} // buildAggInst
    723752
     753
    724754ReferenceToType * buildAggInst( const TypeData * td ) {
    725755        assert( td->kind == TypeData::AggregateInst );
     
    761791} // buildAggInst
    762792
     793
    763794NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) {
    764795        assert( td->kind == TypeData::Symbolic );
     
    768799                ret = new TypedefDecl( name, scs, typebuild( td->base ), linkage );
    769800        } else {
    770                 ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Any );
     801                ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Dtype, true );
    771802        } // if
    772803        buildList( td->symbolic.params, ret->get_parameters() );
     
    774805        return ret;
    775806} // buildSymbolic
     807
    776808
    777809EnumDecl * buildEnum( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
     
    790822} // buildEnum
    791823
     824
    792825TypeInstType * buildSymbolicInst( const TypeData * td ) {
    793826        assert( td->kind == TypeData::SymbolicInst );
     
    797830        return ret;
    798831} // buildSymbolicInst
     832
    799833
    800834TupleType * buildTuple( const TypeData * td ) {
     
    807841} // buildTuple
    808842
     843
    809844TypeofType * buildTypeof( const TypeData * td ) {
    810845        assert( td->kind == TypeData::Typeof );
     
    813848        return new TypeofType( buildQualifiers( td ), td->typeexpr->build() );
    814849} // buildTypeof
     850
    815851
    816852Declaration * buildDecl( const TypeData * td, const string &name, Type::StorageClasses scs, Expression * bitfieldWidth, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, Expression *asmName, Initializer * init, std::list< Attribute * > attributes ) {
     
    836872        return nullptr;
    837873} // buildDecl
     874
    838875
    839876FunctionType * buildFunction( const TypeData * td ) {
     
    857894        return ft;
    858895} // buildFunction
     896
    859897
    860898// Transform KR routine declarations into C99 routine declarations:
  • src/Parser/lex.ll

    r78315272 r3f7e12cb  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Sun Sep 10 22:29:15 2017
    13  * Update Count     : 620
     12 * Last Modified On : Wed Oct 25 13:53:56 2017
     13 * Update Count     : 634
    1414 */
    1515
     
    9393                                // numeric constants, CFA: '_' in constant
    9494hex_quad {hex}("_"?{hex}){3}
    95 length ("ll"|"LL"|[lL])|("hh"|"HH"|[hH])
     95size_opt (8|16|32|64|128)?
     96length ("ll"|"LL"|[lL]{size_opt})|("hh"|"HH"|[hH])
    9697integer_suffix_opt ("_"?(([uU]({length}?[iI]?)|([iI]{length}))|([iI]({length}?[uU]?)|([uU]{length}))|({length}([iI]?[uU]?)|([uU][iI]))|[zZ]))?{user_suffix_opt}
    9798
     
    109110                                // GCC: D (double) and iI (imaginary) suffixes, and DL (long double)
    110111exponent "_"?[eE]"_"?[+-]?{decimal_digits}
    111 floating_suffix ([fFdDlL]?[iI]?)|([iI][lLfFdD])
     112floating_size 32|64|80|128
     113floating_length ([fFdDlL]|[lL]{floating_size})
     114floating_suffix ({floating_length}?[iI]?)|([iI]{floating_length})
    112115floating_suffix_opt ("_"?({floating_suffix}|"DL"))?{user_suffix_opt}
    113116decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal})
     
    230233__extension__   { KEYWORD_RETURN(EXTENSION); }                  // GCC
    231234extern                  { KEYWORD_RETURN(EXTERN); }
    232 fallthrough             { KEYWORD_RETURN(FALLTHRU); }                   // CFA
    233235fallthru                { KEYWORD_RETURN(FALLTHRU); }                   // CFA
     236fallthrough             { KEYWORD_RETURN(FALLTHROUGH); }                // CFA
    234237finally                 { KEYWORD_RETURN(FINALLY); }                    // CFA
    235238float                   { KEYWORD_RETURN(FLOAT); }
    236 __float128              { KEYWORD_RETURN(FLOAT); }                              // GCC
     239__float80               { KEYWORD_RETURN(FLOAT80); }                    // GCC
     240float80                 { KEYWORD_RETURN(FLOAT80); }                    // GCC
     241__float128              { KEYWORD_RETURN(FLOAT128); }                   // GCC
     242float128                { KEYWORD_RETURN(FLOAT128); }                   // GCC
    237243for                             { KEYWORD_RETURN(FOR); }
    238244forall                  { KEYWORD_RETURN(FORALL); }                             // CFA
     
    249255__inline__              { KEYWORD_RETURN(INLINE); }                             // GCC
    250256int                             { KEYWORD_RETURN(INT); }
    251 __int128                { KEYWORD_RETURN(INT); }                                // GCC
    252 __int128_t              { KEYWORD_RETURN(INT); }                                // GCC
     257__int128                { KEYWORD_RETURN(INT128); }                             // GCC
     258int128                  { KEYWORD_RETURN(INT128); }                             // GCC
    253259__label__               { KEYWORD_RETURN(LABEL); }                              // GCC
    254260long                    { KEYWORD_RETURN(LONG); }
     
    285291__typeof                { KEYWORD_RETURN(TYPEOF); }                             // GCC
    286292__typeof__              { KEYWORD_RETURN(TYPEOF); }                             // GCC
    287 __uint128_t             { KEYWORD_RETURN(INT); }                                // GCC
    288293union                   { KEYWORD_RETURN(UNION); }
    289294unsigned                { KEYWORD_RETURN(UNSIGNED); }
  • src/Parser/parser.yy

    r78315272 r3f7e12cb  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Sep 14 23:07:12 2017
    13 // Update Count     : 2815
     12// Last Modified On : Wed Oct 25 12:28:54 2017
     13// Update Count     : 2893
    1414//
    1515
     
    4343#define YYDEBUG_LEXER_TEXT (yylval)                                             // lexer loads this up each time
    4444#define YYDEBUG 1                                                                               // get the pretty debugging code to compile
    45 #define YYERROR_VERBOSE
     45#define YYERROR_VERBOSE                                                                 // more information in syntax errors
    4646
    4747#undef __GNUC_MINOR__
     
    117117bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
    118118
    119 # define YYLLOC_DEFAULT(Cur, Rhs, N)                            \
    120 do                                                              \
    121         if (N) {                                                      \
    122                 (Cur).first_line   = YYRHSLOC(Rhs, 1).first_line;           \
    123                 (Cur).first_column = YYRHSLOC(Rhs, 1).first_column;         \
    124                 (Cur).last_line    = YYRHSLOC(Rhs, N).last_line;            \
    125                 (Cur).last_column  = YYRHSLOC(Rhs, N).last_column;          \
    126                 (Cur).filename     = YYRHSLOC(Rhs, 1).filename;             \
    127         } else {                                                      \
    128                 (Cur).first_line   = (Cur).last_line   =                    \
    129                         YYRHSLOC(Rhs, 0).last_line;                               \
    130                 (Cur).first_column = (Cur).last_column =                    \
    131                         YYRHSLOC(Rhs, 0).last_column;                             \
    132                 (Cur).filename     = YYRHSLOC(Rhs, 0).filename;             \
    133         }                                                             \
    134 while (0)
     119// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     120#define YYLLOC_DEFAULT(Cur, Rhs, N)                                                                                             \
     121if ( N ) {                                                                                                                                              \
     122        (Cur).first_line   = YYRHSLOC( Rhs, 1 ).first_line;                                                     \
     123        (Cur).first_column = YYRHSLOC( Rhs, 1 ).first_column;                                           \
     124        (Cur).last_line    = YYRHSLOC( Rhs, N ).last_line;                                                      \
     125        (Cur).last_column  = YYRHSLOC( Rhs, N ).last_column;                                            \
     126        (Cur).filename     = YYRHSLOC( Rhs, 1 ).filename;                                                       \
     127} else {                                                                                                                                                \
     128        (Cur).first_line   = (Cur).last_line = YYRHSLOC( Rhs, 0 ).last_line;            \
     129        (Cur).first_column = (Cur).last_column = YYRHSLOC( Rhs, 0 ).last_column;        \
     130        (Cur).filename     = YYRHSLOC( Rhs, 0 ).filename;                                                       \
     131}
    135132%}
    136133
    137134%define parse.error verbose
    138135
    139 // Types declaration
     136// Types declaration for productions
    140137%union
    141138{
     
    173170%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    174171%token BOOL COMPLEX IMAGINARY                                                   // C99
     172%token INT128 FLOAT80 FLOAT128                                                  // GCC
    175173%token ZERO_T ONE_T                                                                             // CFA
    176174%token VALIST                                                                                   // GCC
     
    182180%token ATTRIBUTE EXTENSION                                                              // GCC
    183181%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    184 %token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA
     182%token CHOOSE DISABLE ENABLE FALLTHRU FALLTHROUGH TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA
    185183%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    186184%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
     
    252250%type<sn> exception_statement                   handler_clause                          finally_clause
    253251%type<catch_kind> handler_key
     252%type<sn> mutex_statement
    254253%type<en> when_clause                                   when_clause_opt                         waitfor                                         timeout
    255254%type<sn> waitfor_statement
     
    363362%precedence ELSE        // token precedence for start of else clause in IF/WAITFOR statement
    364363
    365 %locations
     364%locations                      // support location tracking for error messages
    366365
    367366%start translation_unit                                                                 // parse-tree root
     
    458457        | '(' compound_statement ')'                                            // GCC, lambda expression
    459458                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
    460         | primary_expression '{' argument_expression_list '}' // CFA, constructor call
    461                 {
    462                         Token fn;
    463                         fn.str = new std::string( "?{}" );                      // location undefined - use location of '{'?
    464                         $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
    465                 }
    466459        | type_name '.' no_attr_identifier                                      // CFA, nested type
    467                 { $$ = nullptr; }                                                               // FIX ME
     460                { throw SemanticError("Qualified names are currently unimplemented."); $$ = nullptr; }                                                          // FIX ME
    468461        | type_name '.' '[' push field_list pop ']'                     // CFA, nested type / tuple field selector
    469                 { $$ = nullptr; }                                                               // FIX ME
     462                { throw SemanticError("Qualified names are currently unimplemented."); $$ = nullptr; }                                                          // FIX ME
    470463        ;
    471464
     
    478471                // equivalent to the old x[i,j].
    479472                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); }
     473        | postfix_expression '{' argument_expression_list '}' // CFA, constructor call
     474                {
     475                        Token fn;
     476                        fn.str = new std::string( "?{}" );                      // location undefined - use location of '{'?
     477                        $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
     478                }
    480479        | postfix_expression '(' argument_expression_list ')'
    481480                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
     
    809808        | jump_statement
    810809        | with_statement
     810        | mutex_statement
    811811        | waitfor_statement
    812812        | exception_statement
     
    974974        ;
    975975
     976fall_through_name:                                                                              // CFA
     977        FALLTHRU
     978        | FALLTHROUGH
     979        ;
     980
    976981fall_through:                                                                                   // CFA
    977         FALLTHRU
     982        fall_through_name
    978983                { $$ = nullptr; }
    979         | FALLTHRU ';'
     984        | fall_through_name ';'
    980985                { $$ = nullptr; }
    981986        ;
     
    10331038        ;
    10341039
     1040// If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex".
     1041mutex_statement:
     1042        MUTEX '(' argument_expression_list ')' statement
     1043                { $$ = nullptr; }                                                               // FIX ME
     1044        ;
     1045
    10351046when_clause:
    10361047        WHEN '(' comma_expression ')'
     
    15511562        | VOLATILE
    15521563                { $$ = DeclarationNode::newTypeQualifier( Type::Volatile ); }
    1553         | MUTEX
    1554                 { $$ = DeclarationNode::newTypeQualifier( Type::Mutex ); }
    15551564        | ATOMIC
    15561565                { $$ = DeclarationNode::newTypeQualifier( Type::Atomic ); }
     
    16061615
    16071616basic_type_name:
    1608         CHAR
     1617        VOID
     1618                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     1619        | BOOL                                                                                          // C99
     1620                { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
     1621        | CHAR
    16091622                { $$ = DeclarationNode::newBasicType( DeclarationNode::Char ); }
     1623        | INT
     1624                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
     1625        | INT128
     1626                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 ); }
     1627        | FLOAT
     1628                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
     1629        | FLOAT80
     1630                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float80 ); }
     1631        | FLOAT128
     1632                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float128 ); }
    16101633        | DOUBLE
    16111634                { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); }
    1612         | FLOAT
    1613                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
    1614         | INT
    1615                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
    1616         | LONG
    1617                 { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
    1618         | SHORT
    1619                 { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }
     1635        | COMPLEX                                                                                       // C99
     1636                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
     1637        | IMAGINARY                                                                                     // C99
     1638                { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
    16201639        | SIGNED
    16211640                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); }
    16221641        | UNSIGNED
    16231642                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); }
    1624         | VOID
    1625                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
    1626         | BOOL                                                                                          // C99
    1627                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
    1628         | COMPLEX                                                                                       // C99
    1629                 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
    1630         | IMAGINARY                                                                                     // C99
    1631                 { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
     1643        | SHORT
     1644                { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }
     1645        | LONG
     1646                { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
    16321647        | ZERO_T
    16331648                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
     
    24762491        | TYPEDEFname
    24772492        | TYPEGENname
     2493        | FALLTHROUGH
     2494                { $$ = Token{ new string( "fallthrough" ), { nullptr, -1 } }; }
    24782495        | CONST
    24792496                { $$ = Token{ new string( "__const__" ), { nullptr, -1 } }; }
     
    26992716        paren_identifier attribute_list_opt
    27002717                { $$ = $1->addQualifiers( $2 ); }
     2718        | '&' MUTEX paren_identifier attribute_list_opt
     2719                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( Type::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
    27012720        | identifier_parameter_ptr
    27022721        | identifier_parameter_array attribute_list_opt
     
    27392758//
    27402759//              typedef int foo;
     2760//              forall( otype T ) struct foo;
    27412761//              int f( int foo ); // redefine typedef name in new scope
    27422762//
     
    27462766        typedef attribute_list_opt
    27472767                { $$ = $1->addQualifiers( $2 ); }
     2768        | '&' MUTEX typedef attribute_list_opt
     2769                { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( Type::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); }
    27482770        | type_parameter_ptr
    27492771        | type_parameter_array attribute_list_opt
     
    28922914abstract_parameter_declarator:
    28932915        abstract_parameter_ptr
     2916        | '&' MUTEX attribute_list_opt
     2917                { $$ = DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( Type::Mutex ), OperKinds::AddressOf )->addQualifiers( $3 ); }
    28942918        | abstract_parameter_array attribute_list_opt
    28952919                { $$ = $1->addQualifiers( $2 ); }
  • src/Parser/parserutility.cc

    r78315272 r3f7e12cb  
    2929
    3030Expression *notZeroExpr( Expression *orig ) {
     31        if( !orig ) return nullptr;
    3132        UntypedExpr *comparison = new UntypedExpr( new NameExpr( "?!=?" ) );
    3233        comparison->get_args().push_back( orig );
Note: See TracChangeset for help on using the changeset viewer.