Changeset 874ffa4


Ignore:
Timestamp:
Mar 4, 2019, 2:54:05 PM (5 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
1bb9a9a
Parents:
1cb7fab2 (diff), 0050a5f (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:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r1cb7fab2 r874ffa4  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 13 18:07:38 2019
    13 // Update Count     : 902
     12// Last Modified On : Thu Feb 28 21:36:38 2019
     13// Update Count     : 933
    1414//
    1515
     
    5757static inline bool checkD( char c ) { return c == 'd' || c == 'D'; }
    5858static inline bool checkF80( char c ) { return c == 'w' || c == 'W'; }
     59static inline bool checkF128( char c ) { return c == 'q' || c == 'Q'; }
    5960static inline bool checkL( char c ) { return c == 'l' || c == 'L'; }
    60 static inline bool checkF128( char c ) { return c == 'q' || c == 'Q'; }
    6161static inline bool checkI( char c ) { return c == 'i' || c == 'I'; }
    6262static inline bool checkB( char c ) { return c == 'b' || c == 'B'; }
    6363static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
     64static inline bool checkN( char c ) { return c == 'n' || c == 'N'; }
     65
     66void lnthSuffix( string & str, int & type, int & ltype ) {
     67        string::size_type posn = str.find_last_of( "lL" );
     68        if ( posn != string::npos ) {
     69                type = 3;                                                                               // default
     70                posn += 1;                                                                              // advance to size
     71                if ( str[posn] == '3' ) {                                               // 32
     72                        type = ltype = 2; str.erase( posn, 2 );
     73                } else if ( str[posn] == '6' ) {                                // 64
     74                        type = ltype = 3; str.erase( posn, 2 );
     75                } else if ( str[posn] == '8' ) {                                // 8
     76                        type = ltype = 1; str.erase( posn, 1 );
     77                } else if ( str[posn] == '1' ) {
     78                        if ( str[posn + 1] == '6' ) {                           // 16
     79                                type = ltype = 0; str.erase( posn, 2 );
     80                        } else {                                                                        // 128
     81                                type = ltype = 5; str.erase( posn, 3 );
     82                        } // if
     83                } // if
     84        } // if
     85} // lnthSuffix
    6486
    6587Expression * build_constantInteger( string & str ) {
     
    82104        size_t last = str.length() - 1;                                         // last subscript of constant
    83105        Expression * ret;
     106        string fred( str );
    84107
    85108        // special constants
     
    93116        } // if
    94117
    95         // Cannot be "0"
     118        // Cannot be just "0"/"1"; sscanf stops at the suffix, if any; value goes over the wall so always generate
    96119
    97120        if ( str[0] == '0' ) {                                                          // radix character ?
     
    115138        } else {                                                                                        // decimal constant ?
    116139                sscanf( (char *)str.c_str(), "%llu", &v );
    117                 //printf( "%llu %llu\n", v, v );
    118         } // if
    119 
    120         // At least one digit in integer constant, so safe to backup while looking for suffix.
     140                //printf( "%llu\n", v );
     141        } // if
    121142
    122143        string::size_type posn;
    123144
    124         if ( str.find_last_of( "uU" ) != string::npos ) Unsigned = true;
    125 
    126         posn = str.rfind( "hh" );
    127         if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; }
    128 
    129         posn = str.rfind( "HH" );
    130         if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; }
    131 
    132         posn = str.find_last_of( "hH" );
    133         if ( posn != string::npos ) { type = 0; str.erase( posn, 1 ); goto FINI; }
    134 
    135         posn = str.find_last_of( "zZ" );
    136         if ( posn != string::npos ) { Unsigned = true; type = 2; ltype = 4; str.erase( posn, 1 ); goto FINI; }
    137 
    138         if ( str.rfind( "ll" ) != string::npos || str.rfind( "LL" ) != string::npos ) { type = 4; goto FINI; }
    139 
    140         posn = str.find_last_of( "lL" );
    141         if ( posn != string::npos ) {
    142                 type = 3;                                                                               // default
    143                 posn += 1;                                                                              // advance to size
    144                 if ( str[posn] == '3' ) {                                               // 32
    145                         type = ltype = 2; str.erase( posn, 2 );
    146                 } else if ( str[posn] == '6' ) {                                // 64
    147                         type = ltype = 3; str.erase( posn, 2 );
    148                 } else if ( str[posn] == '8' ) {                                // 8
    149                         type = ltype = 1; str.erase( posn, 1 );
    150                 } else if ( str[posn] == '1' ) {
    151                         if ( str[posn + 1] == '6' ) {                           // 16
    152                                 type = ltype = 0; str.erase( posn, 2 );
    153                         } else {                                                                        // 128
    154                                 type = ltype = 5; str.erase( posn, 3 );
     145        if ( isdigit( str[last] ) ) {                                           // no suffix ?
     146                lnthSuffix( str, type, ltype );                                 // could have length suffix
     147                if ( type == -1 ) {
     148                        // no suffix type, use value to determine type
     149                        if ( v <= INT_MAX ) {                                           // signed int
     150                                type = 2;
     151                        } else if ( v <= UINT_MAX && ! dec ) {          // unsigned int
     152                                type = 2;
     153                                Unsigned = true;                                                // unsigned
     154                        } else if ( v <= LONG_MAX ) {                           // signed long int
     155                                type = 3;
     156                        } else if ( v <= ULONG_MAX && ( ! dec || LONG_MAX == LLONG_MAX ) ) { // signed long int
     157                                type = 3;
     158                                Unsigned = true;                                                // unsigned long int
     159                        } else if ( v <= LLONG_MAX ) {                          // signed long long int
     160                                type = 4;
     161                        } else {                                                                        // unsigned long long int
     162                                type = 4;
     163                                Unsigned = true;                                                // unsigned long long int
    155164                        } // if
    156165                } // if
    157         } // if
    158   FINI:
    159 
    160         if ( type == -1 ) {                                                                     // no suffix type, use value
    161                 if ( v <= INT_MAX ) {                                                   // signed int
    162                         type = 2;
    163                 } else if ( v <= UINT_MAX && ! dec ) {                  // unsigned int
    164                         type = 2;
    165                         Unsigned = true;                                                        // unsigned
    166                 } else if ( v <= LONG_MAX ) {                                   // signed long int
    167                         type = 3;
    168                 } else if ( v <= ULONG_MAX && ( ! dec || LONG_MAX == LLONG_MAX ) ) { // signed long int
    169                         type = 3;
    170                         Unsigned = true;                                                        // unsigned long int
    171                 } else if ( v <= LLONG_MAX ) {                                  // signed long long int
    172                         type = 4;
    173                 } else {                                                                                // unsigned long long int
    174                         type = 4;
    175                         Unsigned = true;                                                        // unsigned long long int
    176                 } // if
    177         } // if
    178 
     166        } else {
     167                // At least one digit in integer constant, so safe to backup while looking for suffix.
     168
     169                if ( str.find_last_of( "uU" ) != string::npos ) Unsigned = true;
     170
     171                posn = str.rfind( "hh" );
     172                if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; }
     173
     174                posn = str.rfind( "HH" );
     175                if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; }
     176
     177                posn = str.find_last_of( "hH" );
     178                if ( posn != string::npos ) { type = 0; str.erase( posn, 1 ); goto FINI; }
     179
     180                posn = str.find_last_of( "nN" );
     181                if ( posn != string::npos ) { type = 2; str.erase( posn, 1 ); goto FINI; }
     182
     183                posn = str.find_last_of( "zZ" );
     184                if ( posn != string::npos ) { Unsigned = true; type = 2; ltype = 4; str.erase( posn, 1 ); goto FINI; }
     185
     186                if ( str.rfind( "ll" ) != string::npos || str.rfind( "LL" ) != string::npos ) { type = 4; goto FINI; }
     187
     188                lnthSuffix( str, type, ltype );                                 // must be after check for "ll"
     189                if ( type == -1 ) { type = 3; goto FINI; }
     190          FINI: ;
     191        } // if
     192
     193        //if ( !( 0 <= type && type < 6 ) ) { printf( "%s %lu %d %s\n", fred.c_str(), fred.length(), type, str.c_str() ); }
    179194        assert( 0 <= type && type < 6 );
     195
    180196        // Constant type is correct for overload resolving.
    181197        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][type] ), str, v ) );
     
    191207                } // if
    192208        } // if
    193   CLEANUP:
    194 
     209
     210  CLEANUP: ;
    195211        delete &str;                                                                            // created by lex
    196212        return ret;
  • src/Parser/TypeData.h

    r1cb7fab2 r874ffa4  
    3131        struct Aggregate_t {
    3232                DeclarationNode::Aggregate kind;
    33                 const std::string * name;
    34                 DeclarationNode * params;
    35                 ExpressionNode * actuals;                                               // holds actual parameters later applied to AggInst
    36                 DeclarationNode * fields;
     33                const std::string * name = nullptr;
     34                DeclarationNode * params = nullptr;
     35                ExpressionNode * actuals = nullptr;                                             // holds actual parameters later applied to AggInst
     36                DeclarationNode * fields = nullptr;
    3737                bool body;
    3838                bool anon;
    3939
    4040                bool tagged;
    41                 const std::string * parent;
     41                const std::string * parent = nullptr;
    4242        };
    4343
    4444        struct AggInst_t {
    45                 TypeData * aggregate;
    46                 ExpressionNode * params;
     45                TypeData * aggregate = nullptr;
     46                ExpressionNode * params = nullptr;
    4747                bool hoistType;
    4848        };
    4949
    5050        struct Array_t {
    51                 ExpressionNode * dimension;
     51                ExpressionNode * dimension = nullptr;
    5252                bool isVarLen;
    5353                bool isStatic;
     
    5555
    5656        struct Enumeration_t {
    57                 const std::string * name;
    58                 DeclarationNode * constants;
     57                const std::string * name = nullptr;
     58                DeclarationNode * constants = nullptr;
    5959                bool body;
    6060                bool anon;
     
    6262
    6363        struct Function_t {
    64                 mutable DeclarationNode * params;                               // mutables modified in buildKRFunction
    65                 mutable DeclarationNode * idList;                               // old-style
    66                 mutable DeclarationNode * oldDeclList;
    67                 StatementNode * body;
    68                 ExpressionNode * withExprs;                                             // expressions from function's with_clause
     64                mutable DeclarationNode * params = nullptr;                             // mutables modified in buildKRFunction
     65                mutable DeclarationNode * idList = nullptr;                             // old-style
     66                mutable DeclarationNode * oldDeclList = nullptr;
     67                StatementNode * body = nullptr;
     68                ExpressionNode * withExprs = nullptr;                                           // expressions from function's with_clause
    6969        };
    7070
    7171        struct Symbolic_t {
    72                 const std::string * name;
     72                const std::string * name = nullptr;
    7373                bool isTypedef;                                                                 // false => TYPEGENname, true => TYPEDEFname
    74                 DeclarationNode * params;
    75                 ExpressionNode * actuals;
    76                 DeclarationNode * assertions;
     74                DeclarationNode * params = nullptr;
     75                ExpressionNode * actuals = nullptr;
     76                DeclarationNode * assertions = nullptr;
    7777        };
    7878
    7979        struct Qualified_t {                                                            // qualified type S.T
    80                 TypeData * parent;
    81                 TypeData * child;
     80                TypeData * parent = nullptr;
     81                TypeData * child = nullptr;
    8282        };
    8383
     
    9393
    9494        Type::Qualifiers qualifiers;
    95         DeclarationNode * forall;
     95        DeclarationNode * forall = nullptr;
    9696
    9797        Aggregate_t aggregate;
     
    102102        Symbolic_t symbolic;
    103103        Qualified_t qualified;
    104         DeclarationNode * tuple;
    105         ExpressionNode * typeexpr;
     104        DeclarationNode * tuple = nullptr;
     105        ExpressionNode * typeexpr = nullptr;
    106106
    107107        TypeData( Kind k = Unknown );
  • src/Parser/lex.ll

    r1cb7fab2 r874ffa4  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Wed Feb 13 17:33:53 2019
    13  * Update Count     : 702
     12 * Last Modified On : Wed Feb 27 22:44:03 2019
     13 * Update Count     : 704
    1414 */
    1515
     
    9999hex_quad {hex}("_"?{hex}){3}
    100100size_opt (8|16|32|64|128)?
    101 length ("ll"|"LL"|[lL]{size_opt})|("hh"|"HH"|[hH])
     101length ("ll"|"LL"|[lL]{size_opt})|("hh"|"HH"|[hHnN])
    102102integer_suffix_opt ("_"?(([uU]({length}?[iI]?)|([iI]{length}))|([iI]({length}?[uU]?)|([uU]{length}))|({length}([iI]?[uU]?)|([uU][iI]))|[zZ]))?
    103103
Note: See TracChangeset for help on using the changeset viewer.