Changeset 5ef4008 for src/Parser


Ignore:
Timestamp:
Sep 13, 2024, 2:43:22 PM (13 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
8c79dc3c
Parents:
c494b84 (diff), 9739c56f (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:
6 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cpp

    rc494b84 r5ef4008  
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat May 16 13:17:07 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 23 10:22:00 2024
    13 // Update Count     : 1088
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Sep 12 22:40:35 2024
     13// Update Count     : 1090
    1414//
    1515
     
    381381                const CodeLocation & location, string & str ) {
    382382        static const ast::BasicKind kind[2][12] = {
    383                 { ast::BasicKind::Float, ast::BasicKind::Double, ast::BasicKind::LongDouble, ast::BasicKind::uuFloat80, ast::BasicKind::uuFloat128, ast::BasicKind::uFloat16, ast::BasicKind::uFloat32, ast::BasicKind::uFloat32x, ast::BasicKind::uFloat64, ast::BasicKind::uFloat64x, ast::BasicKind::uFloat128, ast::BasicKind::uFloat128x },
    384                 { ast::BasicKind::FloatComplex, ast::BasicKind::DoubleComplex, ast::BasicKind::LongDoubleComplex, ast::BasicKind::NUMBER_OF_BASIC_TYPES, ast::BasicKind::NUMBER_OF_BASIC_TYPES, ast::BasicKind::uFloat16Complex, ast::BasicKind::uFloat32Complex, ast::BasicKind::uFloat32xComplex, ast::BasicKind::uFloat64Complex, ast::BasicKind::uFloat64xComplex, ast::BasicKind::uFloat128Complex, ast::BasicKind::uFloat128xComplex },
     383                { ast::BasicKind::Float, ast::BasicKind::Double, ast::BasicKind::LongDouble, ast::BasicKind::Float80, ast::BasicKind::uuFloat128, ast::BasicKind::Float16, ast::BasicKind::Float32, ast::BasicKind::Float32x, ast::BasicKind::Float64, ast::BasicKind::Float64x, ast::BasicKind::Float128, ast::BasicKind::Float128x },
     384                { ast::BasicKind::FloatComplex, ast::BasicKind::DoubleComplex, ast::BasicKind::LongDoubleComplex, ast::BasicKind::NUMBER_OF_BASIC_TYPES, ast::BasicKind::NUMBER_OF_BASIC_TYPES, ast::BasicKind::Float16Complex, ast::BasicKind::Float32Complex, ast::BasicKind::Float32xComplex, ast::BasicKind::Float64Complex, ast::BasicKind::Float64xComplex, ast::BasicKind::Float128Complex, ast::BasicKind::Float128xComplex },
    385385        };
    386386
     
    460460        return ret;
    461461} // build_constantChar
     462
     463static bool isoctal( char ch ) {
     464        return ('0' <= ch && ch <= '7');
     465}
     466
     467// A "sequence" is the series of characters in a character/string literal
     468// that becomes a single character value in the runtime value.
     469static size_t sequenceLength( const std::string & str, size_t pos ) {
     470        // Most "sequences" are just a single character, filter those out:
     471        if ( '\\' != str[pos] ) return 1;
     472        switch ( str[pos + 1] ) {
     473                // Simple Escape Sequence (\_ where _ is one of the following):
     474          case '\'': case '\"': case '?': case '\\':
     475          case 'a': case 'b': case 'f': case 'n': case 'r': case 't': case 'v':
     476                // GCC Escape Sequence (as simple, just some different letters):
     477          case 'e':
     478                return 2;
     479                // Numeric Escape Sequence (\___ where _ is 1-3 octal digits):
     480          case '0': case '1': case '2': case '3':
     481          case '4': case '5': case '6': case '7':
     482                return ( !isoctal( str[pos + 2] ) ) ? 2 :
     483                  ( !isoctal( str[pos + 3] ) ) ? 3 : 4;
     484                  // Numeric Escape Sequence (\x_ where _ is 1 or more hexadecimal digits):
     485          case 'x': {
     486                  size_t length = 2;
     487                  while ( isxdigit( str[pos + length] ) ) ++length;
     488                  return length;
     489          }
     490                // Universal Character Name (\u____ where _ is 4 decimal digits):
     491          case 'u':
     492                return 6;
     493                // Universal Character Name (\U________ where _ is 8 decimal digits):
     494          case 'U':
     495                return 10;
     496          default:
     497                assertf( false, "Unknown escape sequence (start %c).", str[pos] );
     498                return 1;
     499        }
     500}
    462501
    463502ast::Expr * build_constantStr(
     
    485524                strtype = new ast::BasicType( ast::BasicKind::Char );
    486525        } // switch
     526
     527        // The dimension value of the type is equal to the number of "sequences"
     528        // not including the openning and closing quotes in the literal plus 1
     529        // for the implicit null terminator.
     530        size_t dimension = 1;
     531        for ( size_t pos = 1 ; pos < str.size() - 1 ;
     532                        pos += sequenceLength( str, pos ) ) {
     533                dimension += 1;
     534        }
     535
    487536        ast::ArrayType * at = new ast::ArrayType(
    488537                strtype,
    489                 // Length is adjusted: +1 for '\0' and -2 for '"'
    490                 ast::ConstantExpr::from_ulong( location, str.size() + 1 - 2 ),
     538                ast::ConstantExpr::from_ulong( location, dimension ),
    491539                ast::FixedLen,
    492540                ast::DynamicDim );
  • src/Parser/StatementNode.cpp

    rc494b84 r5ef4008  
    1111// Created On       : Sat May 16 14:59:41 2015
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Mon Sep  9 11:28:07 2024
    14 // Update Count     : 430
     13// Last Modified On : Mon Sep  9 21:49:15 2024
     14// Update Count     : 431
    1515//
    1616
     
    184184
    185185ast::Stmt * build_while( const CodeLocation & location, CondCtl * ctl, StatementNode * stmt, StatementNode * else_ ) {
    186         std::vector<ast::ptr<ast::Stmt>> astinit;                                               // maybe empty
     186        std::vector<ast::ptr<ast::Stmt>> astinit;                       // maybe empty
    187187        ast::Expr * astcond = build_if_control( ctl, astinit ); // ctl deleted, cond/init set
    188188
  • src/Parser/TypeData.cpp

    rc494b84 r5ef4008  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb 23 08:58:30 2024
    13 // Update Count     : 734
     12// Last Modified On : Thu Sep 12 22:43:59 2024
     13// Update Count     : 735
    1414//
    1515
     
    11581158        case TypeData::Double:
    11591159        case TypeData::LongDouble:                                      // not set until below
    1160         case TypeData::uuFloat80:
     1160        case TypeData::Float80:
    11611161        case TypeData::uuFloat128:
    1162         case TypeData::uFloat16:
    1163         case TypeData::uFloat32:
    1164         case TypeData::uFloat32x:
    1165         case TypeData::uFloat64:
    1166         case TypeData::uFloat64x:
    1167         case TypeData::uFloat128:
    1168         case TypeData::uFloat128x:
     1162        case TypeData::Float16:
     1163        case TypeData::Float32:
     1164        case TypeData::Float32x:
     1165        case TypeData::Float64:
     1166        case TypeData::Float64x:
     1167        case TypeData::Float128:
     1168        case TypeData::Float128x:
    11691169                static ast::BasicKind floattype[2][12] = {
    1170                         { ast::BasicKind::FloatComplex, ast::BasicKind::DoubleComplex, ast::BasicKind::LongDoubleComplex, (ast::BasicKind)-1, (ast::BasicKind)-1, ast::BasicKind::uFloat16Complex, ast::BasicKind::uFloat32Complex, ast::BasicKind::uFloat32xComplex, ast::BasicKind::uFloat64Complex, ast::BasicKind::uFloat64xComplex, ast::BasicKind::uFloat128Complex, ast::BasicKind::uFloat128xComplex, },
    1171                         { ast::BasicKind::Float, ast::BasicKind::Double, ast::BasicKind::LongDouble, ast::BasicKind::uuFloat80, ast::BasicKind::uuFloat128, ast::BasicKind::uFloat16, ast::BasicKind::uFloat32, ast::BasicKind::uFloat32x, ast::BasicKind::uFloat64, ast::BasicKind::uFloat64x, ast::BasicKind::uFloat128, ast::BasicKind::uFloat128x, },
     1170                        { ast::BasicKind::FloatComplex, ast::BasicKind::DoubleComplex, ast::BasicKind::LongDoubleComplex, (ast::BasicKind)-1, (ast::BasicKind)-1, ast::BasicKind::Float16Complex, ast::BasicKind::Float32Complex, ast::BasicKind::Float32xComplex, ast::BasicKind::Float64Complex, ast::BasicKind::Float64xComplex, ast::BasicKind::Float128Complex, ast::BasicKind::Float128xComplex, },
     1171                        { ast::BasicKind::Float, ast::BasicKind::Double, ast::BasicKind::LongDouble, ast::BasicKind::Float80, ast::BasicKind::uuFloat128, ast::BasicKind::Float16, ast::BasicKind::Float32, ast::BasicKind::Float32x, ast::BasicKind::Float64, ast::BasicKind::Float64x, ast::BasicKind::Float128, ast::BasicKind::Float128x, },
    11721172                };
    11731173
     
    11851185                        genTSError( TypeData::complexTypeNames[ td->complextype ], td->basictype );
    11861186                } // if
    1187                 if ( (td->basictype == TypeData::uuFloat80 || td->basictype == TypeData::uuFloat128) && td->complextype == TypeData::Complex ) { // gcc unsupported
     1187                if ( (td->basictype == TypeData::Float80 || td->basictype == TypeData::uuFloat128) && td->complextype == TypeData::Complex ) { // gcc unsupported
    11881188                        genTSError( TypeData::complexTypeNames[ td->complextype ], td->basictype );
    11891189                } // if
     
    12051205                const_cast<TypeData *>(td)->basictype = TypeData::Int;
    12061206                goto Integral;
     1207
     1208          case TypeData::Float32x4: case TypeData::Float64x2: case TypeData::Svfloat32: case TypeData:: Svfloat64: case TypeData::Svbool:
     1209                return nullptr;
    12071210        default:
    12081211                assertf( false, "unknown basic type" );
     
    14831486                        ast::Expr * initValue;
    14841487                        if ( ret->isCfa && ret->base ) {
    1485                                 CodeLocation location = cur->enumeratorValue->location;
    1486                                 initValue = new ast::CastExpr( location, maybeMoveBuild( cur->consume_enumeratorValue() ), ret->base );
     1488                                initValue = new ast::CastExpr( cur->enumeratorValue->location, maybeMoveBuild( cur->consume_enumeratorValue() ),
     1489                                                                                          ret->base );
    14871490                        } else {
    14881491                                initValue = maybeMoveBuild( cur->consume_enumeratorValue() );
  • src/Parser/TypeData.hpp

    rc494b84 r5ef4008  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 22 16:30:31 2024
    13 // Update Count     : 210
     12// Last Modified On : Fri Sep 13 08:13:01 2024
     13// Update Count     : 216
    1414//
    1515
     
    2828        enum BasicType {
    2929                Void, Bool, Char, Int, Int128,
    30                 Float, Double, LongDouble, uuFloat80, uuFloat128,
    31                 uFloat16, uFloat32, uFloat32x, uFloat64, uFloat64x, uFloat128, uFloat128x,
    32                 NoBasicType
     30                Float, Double, LongDouble, Float80, uuFloat128,
     31                Float16, Float32, Float32x, Float64, Float64x, Float128, Float128x,
     32                NoBasicType,
     33                Float32x4, Float64x2, Svfloat32, Svfloat64, Svbool,
    3334        };
    3435        static const char * basicTypeNames[];
  • src/Parser/lex.ll

    rc494b84 r5ef4008  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Thu Jun 27 14:38:27 2024
    13  * Update Count     : 780
     12 * Last Modified On : Wed Sep 11 17:16:23 2024
     13 * Update Count     : 791
    1414 */
    1515
     
    234234basetypeof              { KEYWORD_RETURN(BASETYPEOF); }                 // CFA
    235235_Bool                   { KEYWORD_RETURN(BOOL); }                               // C99
     236__SVBool_t              { KEYWORD_RETURN(SVBOOL); }                             // gcc (ARM)
    236237break                   { KEYWORD_RETURN(BREAK); }
    237238case                    { KEYWORD_RETURN(CASE); }
     
    270271fixup                   { QKEYWORD_RETURN(FIXUP); }                             // CFA
    271272float                   { KEYWORD_RETURN(FLOAT); }
    272 __float80               { KEYWORD_RETURN(uuFLOAT80); }                  // GCC
    273 float80                 { KEYWORD_RETURN(uuFLOAT80); }                  // GCC
     273__float80               { KEYWORD_RETURN(FLOAT80); }                    // GCC
     274float80                 { KEYWORD_RETURN(FLOAT80); }                    // GCC
    274275__float128              { KEYWORD_RETURN(uuFLOAT128); }                 // GCC
    275276float128                { KEYWORD_RETURN(uuFLOAT128); }                 // GCC
    276 _Float16                { FLOATXX(uFLOAT16); }                                  // GCC
    277 _Float32                { FLOATXX(uFLOAT32); }                                  // GCC
    278 _Float32x               { FLOATXX(uFLOAT32X); }                                 // GCC
    279 _Float64                { FLOATXX(uFLOAT64); }                                  // GCC
    280 _Float64x               { FLOATXX(uFLOAT64X); }                                 // GCC
    281 _Float128               { FLOATXX(uFLOAT128); }                                 // GCC
    282 _Float128x              { FLOATXX(uFLOAT128); }                                 // GCC
     277_Float16                { FLOATXX(FLOAT16); }                                   // GCC
     278_Float32                { FLOATXX(FLOAT32); }                                   // GCC
     279_Float32x               { FLOATXX(FLOAT32X); }                                  // GCC
     280_Float64                { FLOATXX(FLOAT64); }                                   // GCC
     281_Float64x               { FLOATXX(FLOAT64X); }                                  // GCC
     282_Float128               { FLOATXX(FLOAT128); }                                  // GCC
     283_Float128x              { FLOATXX(FLOAT128X); }                                 // GCC
     284__Float32x4_t   { FLOATXX(FLOAT32X4); }                                 // GCC (ARM)
     285__Float64x2_t   { FLOATXX(FLOAT64X2); }                                 // GCC (ARM)
     286__SVFloat32_t   { FLOATXX(SVFLOAT32); }                                 // GCC (ARM)
     287__SVFloat64_t   { FLOATXX(SVFLOAT64); }                                 // GCC (ARM)
    283288for                             { KEYWORD_RETURN(FOR); }
    284289forall                  { KEYWORD_RETURN(FORALL); }                             // CFA
  • src/Parser/parser.yy

    rc494b84 r5ef4008  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 13 11:25:16 2024
    13 // Update Count     : 6740
     12// Last Modified On : Thu Sep 12 22:48:32 2024
     13// Update Count     : 6741
    1414//
    1515
     
    366366%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    367367%token BOOL COMPLEX IMAGINARY                                                   // C99
    368 %token INT128 UINT128 uuFLOAT80 uuFLOAT128                              // GCC
    369 %token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC
     368%token INT128 UINT128 FLOAT80 uuFLOAT128                                // GCC
     369%token FLOAT16 FLOAT32 FLOAT32X FLOAT64 FLOAT64X FLOAT128 FLOAT128X // GCC
     370%token FLOAT32X4 FLOAT64X2 SVFLOAT32 SVFLOAT64 SVBOOL   // GCC (ARM)
    370371%token DECIMAL32 DECIMAL64 DECIMAL128                                   // GCC
    371372%token ZERO_T ONE_T                                                                             // CFA
     
    23642365        | DOUBLE
    23652366                { $$ = build_basic_type( TypeData::Double ); }
    2366         | uuFLOAT80
    2367                 { $$ = build_basic_type( TypeData::uuFloat80 ); }
     2367        | FLOAT80
     2368                { $$ = build_basic_type( TypeData::Float80 ); }
    23682369        | uuFLOAT128
    23692370                { $$ = build_basic_type( TypeData::uuFloat128 ); }
    2370         | uFLOAT16
    2371                 { $$ = build_basic_type( TypeData::uFloat16 ); }
    2372         | uFLOAT32
    2373                 { $$ = build_basic_type( TypeData::uFloat32 ); }
    2374         | uFLOAT32X
    2375                 { $$ = build_basic_type( TypeData::uFloat32x ); }
    2376         | uFLOAT64
    2377                 { $$ = build_basic_type( TypeData::uFloat64 ); }
    2378         | uFLOAT64X
    2379                 { $$ = build_basic_type( TypeData::uFloat64x ); }
    2380         | uFLOAT128
    2381                 { $$ = build_basic_type( TypeData::uFloat128 ); }
     2371        | FLOAT16
     2372                { $$ = build_basic_type( TypeData::Float16 ); }
     2373        | FLOAT32
     2374                { $$ = build_basic_type( TypeData::Float32 ); }
     2375        | FLOAT32X
     2376                { $$ = build_basic_type( TypeData::Float32x ); }
     2377        | FLOAT64
     2378                { $$ = build_basic_type( TypeData::Float64 ); }
     2379        | FLOAT64X
     2380                { $$ = build_basic_type( TypeData::Float64x ); }
     2381        | FLOAT128
     2382                { $$ = build_basic_type( TypeData::Float128 ); }
     2383        | FLOAT128X
     2384                { $$ = build_basic_type( TypeData::Float128x ); }
     2385        | FLOAT32X4
     2386                { $$ = build_basic_type( TypeData::Float32x4 ); }
     2387        | FLOAT64X2
     2388                { $$ = build_basic_type( TypeData::Float64x2 ); }
     2389        | SVFLOAT32
     2390                { $$ = build_basic_type( TypeData::Svfloat32 ); }
     2391        | SVFLOAT64
     2392                { $$ = build_basic_type( TypeData::Svfloat64 ); }
     2393        | SVBOOL
     2394                { $$ = build_basic_type( TypeData::Svbool ); }
    23822395        | DECIMAL32
    23832396                { SemanticError( yylloc, "_Decimal32 is currently unimplemented." ); $$ = nullptr; }
Note: See TracChangeset for help on using the changeset viewer.