Changeset 8024bc8 for src/Parser


Ignore:
Timestamp:
Sep 18, 2017, 11:02:23 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
6994d8c
Parents:
ed235b6 (diff), 5f782f7 (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

    red235b6 r8024bc8  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Sep 12 10:00:29 2017
    13 // Update Count     : 672
     12// Last Modified On : Thu Sep 14 23:09:34 2017
     13// Update Count     : 690
    1414//
    1515
     
    250250        sepString( str, units, '"' );                                           // separate constant from units
    251251
    252         BasicType::Kind strtype = BasicType::Char;                      // default string type
    253         switch ( str[0] ) {                                                                     // str has >= 2 characters, i.e, null string ""
     252        Type * strtype;
     253        switch ( str[0] ) {                                                                     // str has >= 2 characters, i.e, null string "" => safe to look at subscripts 0/1
    254254          case 'u':
    255                 if ( str[1] == '8' ) break;                                             // utf-8 characters
    256                 strtype = BasicType::ShortUnsignedInt;
     255                if ( str[1] == '8' ) goto Default;                              // utf-8 characters => array of char
     256                // lookup type of associated typedef
     257                strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "char16_t", false );
    257258                break;
    258259          case 'U':
    259                 strtype = BasicType::UnsignedInt;
     260                strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "char32_t", false );
    260261                break;
    261262          case 'L':
    262                 strtype = BasicType::SignedInt;
     263                strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "wchar_t", false );
    263264                break;
     265          Default:                                                                                      // char default string type
     266          default:
     267                strtype = new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char );
    264268        } // switch
    265         ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), strtype ),
     269        ArrayType * at = new ArrayType( noQualifiers, strtype,
    266270                                                                        new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
    267271                                                                        false, false );
     
    344348
    345349Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
    346         Type * targetType = maybeMoveBuildType( decl_node );
    347         Expression * castArg = maybeMoveBuild< Expression >( expr_node );
    348         return new VirtualCastExpr( castArg, targetType );
     350        return new VirtualCastExpr( maybeMoveBuild< Expression >( expr_node ), maybeMoveBuildType( decl_node ) );
    349351} // build_virtual_cast
    350352
    351353Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) {
    352         UntypedMemberExpr * ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
    353         return ret;
     354        return new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
    354355} // build_fieldSel
    355356
     
    361362        return ret;
    362363} // build_pfieldSel
    363 
    364 Expression * build_addressOf( ExpressionNode * expr_node ) {
    365                 return new AddressExpr( maybeMoveBuild< Expression >(expr_node) );
    366 } // build_addressOf
    367 
    368 Expression * build_sizeOfexpr( ExpressionNode * expr_node ) {
    369         return new SizeofExpr( maybeMoveBuild< Expression >(expr_node) );
    370 } // build_sizeOfexpr
    371 
    372 Expression * build_sizeOftype( DeclarationNode * decl_node ) {
    373         return new SizeofExpr( maybeMoveBuildType( decl_node ) );
    374 } // build_sizeOftype
    375 
    376 Expression * build_alignOfexpr( ExpressionNode * expr_node ) {
    377         return new AlignofExpr( maybeMoveBuild< Expression >(expr_node) );
    378 } // build_alignOfexpr
    379 
    380 Expression * build_alignOftype( DeclarationNode * decl_node ) {
    381         return new AlignofExpr( maybeMoveBuildType( decl_node) );
    382 } // build_alignOftype
    383364
    384365Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) {
     
    422403} // build_cond
    423404
    424 Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    425         return new CommaExpr( maybeMoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression >(expr_node2) );
    426 } // build_comma
    427 
    428 Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ) {
    429         return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) );
    430 } // build_attrexpr
    431 
    432 Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node ) {
    433         return new AttrExpr( var, maybeMoveBuildType( decl_node ) );
    434 } // build_attrtype
    435 
    436405Expression * build_tuple( ExpressionNode * expr_node ) {
    437406        list< Expression * > exprs;
     
    445414        return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
    446415} // build_func
    447 
    448 Expression * build_range( ExpressionNode * low, ExpressionNode * high ) {
    449         return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) );
    450 } // build_range
    451 
    452 Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ) {
    453         return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) );
    454 } // build_asmexpr
    455 
    456 Expression * build_valexpr( StatementNode * s ) {
    457         return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) );
    458 } // build_valexpr
    459 
    460 Expression * build_typevalue( DeclarationNode * decl ) {
    461         return new TypeExpr( maybeMoveBuildType( decl ) );
    462 } // build_typevalue
    463416
    464417Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) {
  • src/Parser/ParseNode.h

    red235b6 r8024bc8  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep 10 09:56:32 2017
    13 // Update Count     : 801
     12// Last Modified On : Thu Sep 14 23:09:39 2017
     13// Update Count     : 815
    1414//
    1515
     
    122122
    123123        template<typename T>
    124         bool isExpressionType() const {
    125                 return nullptr != dynamic_cast<T>(expr.get());
    126         }
     124        bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr.get()); }
    127125
    128126        Expression * build() const { return const_cast<ExpressionNode *>(this)->expr.release(); }
     
    172170
    173171NameExpr * build_varref( const std::string * name );
    174 Expression * build_typevalue( DeclarationNode * decl );
    175172
    176173Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
     
    178175Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member );
    179176Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member );
    180 Expression * build_addressOf( ExpressionNode * expr_node );
    181 Expression * build_sizeOfexpr( ExpressionNode * expr_node );
    182 Expression * build_sizeOftype( DeclarationNode * decl_node );
    183 Expression * build_alignOfexpr( ExpressionNode * expr_node );
    184 Expression * build_alignOftype( DeclarationNode * decl_node );
    185177Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member );
    186178Expression * build_and( ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
     
    191183Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
    192184Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 );
    193 Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
    194 Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node );
    195 Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node );
    196185Expression * build_tuple( ExpressionNode * expr_node = nullptr );
    197186Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node );
    198 Expression * build_range( ExpressionNode * low, ExpressionNode * high );
    199 Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand );
    200 Expression * build_valexpr( StatementNode * s );
    201187Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids );
    202188
  • src/Parser/parser.yy

    red235b6 r8024bc8  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 11 18:12:00 2017
    13 // Update Count     : 2787
     12// Last Modified On : Thu Sep 14 23:07:12 2017
     13// Update Count     : 2815
    1414//
    1515
     
    5656#include "LinkageSpec.h"
    5757#include "Common/SemanticError.h"                                               // error_str
     58#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
    5859
    5960extern DeclarationNode * parseTree;
     
    438439                { $$ = $2; }
    439440        | '(' compound_statement ')'                                            // GCC, lambda expression
    440                 { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
     441                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
    441442        | primary_expression '{' argument_expression_list '}' // CFA, constructor call
    442443                {
     
    562563                        switch ( $1 ) {
    563564                          case OperKinds::AddressOf:
    564                                 $$ = new ExpressionNode( build_addressOf( $2 ) );
     565                                $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild< Expression >( $2 ) ) );
    565566                                break;
    566567                          case OperKinds::PointTo:
     
    568569                                break;
    569570                          case OperKinds::And:
    570                                 $$ = new ExpressionNode( new AddressExpr( build_addressOf( $2 ) ) );
     571                                $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild< Expression >( $2 ) ) ) );
    571572                                break;
    572573                          default:
     
    581582                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); }
    582583        | SIZEOF unary_expression
    583                 { $$ = new ExpressionNode( build_sizeOfexpr( $2 ) ); }
     584                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild< Expression >( $2 ) ) ); }
    584585        | SIZEOF '(' type_no_function ')'
    585                 { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); }
     586                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); }
    586587        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    587                 { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); }
     588                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild< Expression >( $2 ) ) ); }
    588589        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    589                 { $$ = new ExpressionNode( build_alignOftype( $3 ) ); }
     590                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); }
    590591        | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
    591592                { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); }
    592593        | ATTR_IDENTIFIER
    593                 { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), nullptr ) ); }
     594                { $$ = new ExpressionNode( new AttrExpr( build_varref( $1 ), maybeMoveBuild< Expression >( (ExpressionNode *)nullptr ) ) ); }
    594595        | ATTR_IDENTIFIER '(' argument_expression ')'
    595                 { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); }
     596                { $$ = new ExpressionNode( new AttrExpr( build_varref( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
    596597        | ATTR_IDENTIFIER '(' type ')'
    597                 { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); }
     598                { $$ = new ExpressionNode( new AttrExpr( build_varref( $1 ), maybeMoveBuildType( $3 ) ) ); }
    598599        ;
    599600
     
    618619                // VIRTUAL cannot be opt because of look ahead issues
    619620        | '(' VIRTUAL ')' cast_expression
    620                 { $$ = new ExpressionNode( build_virtual_cast( nullptr, $4 ) ); }
     621                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); }
    621622        | '(' VIRTUAL type_no_function ')' cast_expression
    622                 { $$ = new ExpressionNode( build_virtual_cast( $3, $5 ) ); }
     623                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); }
    623624//      | '(' type_no_function ')' tuple
    624625//              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
     
    771772        assignment_expression
    772773        | comma_expression ',' assignment_expression
    773                 { $$ = new ExpressionNode( build_comma( $1, $3 ) ); }
     774                { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
    774775        ;
    775776
     
    894895        constant_expression                                                     { $$ = $1; }
    895896        | constant_expression ELLIPSIS constant_expression      // GCC, subrange
    896                 { $$ = new ExpressionNode( build_range( $1, $3 ) ); }
     897                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
    897898        | subrange                                                                                      // CFA, subrange
    898899        ;
     
    11541155asm_operand:                                                                                    // GCC
    11551156        string_literal '(' constant_expression ')'
    1156                 { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
     1157                { $$ = new ExpressionNode( new AsmExpr( maybeMoveBuild< Expression >( (ExpressionNode *)nullptr ), $1, maybeMoveBuild< Expression >( $3 ) ) ); }
    11571158        | '[' constant_expression ']' string_literal '(' constant_expression ')'
    1158                 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
     1159                { $$ = new ExpressionNode( new AsmExpr( maybeMoveBuild< Expression >( $2 ), $4, maybeMoveBuild< Expression >( $6 ) ) ); }
    11591160        ;
    11601161
     
    11651166                { $$ = new ExpressionNode( $1 ); }
    11661167        | asm_clobbers_list_opt ',' string_literal
    1167                 // set_last return ParseNode *
     1168                // set_last returns ParseNode *
    11681169                { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
    11691170        ;
     
    20882089                { $$ = $3; }
    20892090        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    2090                 { $$ = new ExpressionNode( build_range( $3, $5 ) ); }
     2091                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
    20912092        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
    20922093                { $$ = $4; }
     
    21652166type_list:                                                                                              // CFA
    21662167        type
    2167                 { $$ = new ExpressionNode( build_typevalue( $1 ) ); }
     2168                { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); }
    21682169        | assignment_expression
    21692170        | type_list ',' type
    2170                 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
     2171                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); }
    21712172        | type_list ',' assignment_expression
    21722173                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     
    24062407subrange:
    24072408        constant_expression '~' constant_expression                     // CFA, integer subrange
    2408                 { $$ = new ExpressionNode( build_range( $1, $3 ) ); }
     2409                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
    24092410        ;
    24102411
Note: See TracChangeset for help on using the changeset viewer.