Changeset 97392b69 for src


Ignore:
Timestamp:
Jun 10, 2020, 4:19:30 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
ab8a023
Parents:
a5873bd (diff), ee06db5c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into relaxed_ready

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptTranslate.cc

    ra5873bd r97392b69  
    1010// Created On       : Wed Jun 14 16:49:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr May 21 13:18:00 2020
    13 // Update Count     : 15
     12// Last Modified On : Tue May 26 10:56:00 2020
     13// Update Count     : 16
    1414//
    1515
     
    107107                        nameOf( terminate_handler_except ),
    108108                        new ConstantExpr( Constant::null(
    109                                 //new PointerType(
    110                                 //      noQualifiers,
    111                                         terminate_handler_except->get_type()->clone()
    112                                 //      )
     109                                terminate_handler_except->get_type()->clone()
    113110                                ) )
    114111                        ) ) );
     
    137134                ObjectDecl * decl = dynamic_cast<ObjectDecl *>( catchStmt->get_decl() );
    138135                // Also checking the type would be nice.
    139                 if ( decl ) {
    140                         // Pass.
    141                 } else if ( CatchStmt::Terminate == catchStmt->get_kind() ) {
    142                         SemanticError(catchStmt->location, "catch must have exception type");
    143                 } else {
    144                         SemanticError(catchStmt->location, "catchResume must have exception type");
     136                if ( !decl || !dynamic_cast<PointerType *>( decl->type ) ) {
     137                        std::string kind = (CatchStmt::Terminate == catchStmt->kind) ? "catch" : "catchResume";
     138                        SemanticError( catchStmt->location, kind + " must have pointer to an exception type" );
    145139                }
    146140
     
    232226
    233227                void premutate( StructDecl *structDecl );
    234                 Statement * postmutate( ThrowStmt *throwStmt );
    235228                Statement * postmutate( TryStmt *tryStmt );
    236229        };
     
    621614        }
    622615
    623         Statement * TryMutatorCore::postmutate( ThrowStmt * ) {
    624                 // All throws should be removed by this point.
    625                 assert( false );
    626         }
    627 
    628616        Statement * TryMutatorCore::postmutate( TryStmt *tryStmt ) {
    629617                assert( except_decl );
  • src/ControlStruct/ExceptTranslate.h

    ra5873bd r97392b69  
    2929        /* Replaces all try blocks (and their many clauses) with function definitions and calls.
    3030         * This uses the exception built-ins to produce typed output and should take place after
    31          * the resolver.
     31         * the resolver. It also produces virtual casts and should happen before they are expanded.
    3232         */
    3333}
  • src/Parser/parser.yy

    ra5873bd r97392b69  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Apr 27 12:25:42 2020
    13 // Update Count     : 4483
     12// Last Modified On : Thu May 28 12:11:45 2020
     13// Update Count     : 4500
    1414//
    1515
     
    329329%type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
    330330%type<en> comma_expression                              comma_expression_opt
    331 %type<en> argument_expression_list              argument_expression                     default_initialize_opt
     331%type<en> argument_expression_list_opt          argument_expression                     default_initialize_opt
    332332%type<ifctl> if_control_expression
    333333%type<fctl> for_control_expression              for_control_expression_list
     
    624624                // equivalent to the old x[i,j].
    625625                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }
    626         | postfix_expression '{' argument_expression_list '}' // CFA, constructor call
     626        | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call
    627627                {
    628628                        Token fn;
     
    630630                        $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
    631631                }
    632         | postfix_expression '(' argument_expression_list ')'
     632        | postfix_expression '(' argument_expression_list_opt ')'
    633633                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    634634        | postfix_expression '`' identifier                                     // CFA, postfix call
     
    662662        | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
    663663                { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
    664         | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call
     664        | '^' primary_expression '{' argument_expression_list_opt '}' // CFA, destructor call
    665665                {
    666666                        Token fn;
     
    670670        ;
    671671
    672 argument_expression_list:
     672argument_expression_list_opt:
    673673        // empty
    674674                { $$ = nullptr; }
    675675        | argument_expression
    676         | argument_expression_list ',' argument_expression
     676        | argument_expression_list_opt ',' argument_expression
    677677                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    678678        ;
     
    11961196                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11971197                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1198         | '=' comma_expression                                                                  // CFA
     1198        | '=' comma_expression                                                          // CFA
    11991199                { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12001200                                                OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    12031203        | comma_expression inclexcl comma_expression '~' comma_expression // CFA
    12041204                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
     1205        | comma_expression ';'                                                          // CFA
     1206                { $$ = forCtrl( new ExpressionNode( build_constantInteger( *new string( "0u" ) ) ), $1, nullptr, OperKinds::LThan, nullptr, nullptr ); }
    12051207        | comma_expression ';' comma_expression                         // CFA
    12061208                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12071209                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1208         | comma_expression ';' '=' comma_expression                             // CFA
     1210        | comma_expression ';' '=' comma_expression                     // CFA
    12091211                { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12101212                                                OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    13041306// If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex".
    13051307mutex_statement:
    1306         MUTEX '(' argument_expression_list ')' statement
     1308        MUTEX '(' argument_expression_list_opt ')' statement
    13071309                { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; }
    13081310        ;
     
    13211323        WAITFOR '(' cast_expression ')'
    13221324                { $$ = $3; }
    1323 //      | WAITFOR '(' cast_expression ',' argument_expression_list ')'
     1325//      | WAITFOR '(' cast_expression ',' argument_expression_list_opt ')'
    13241326//              { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    1325         | WAITFOR '(' cast_expression_list ':' argument_expression_list ')'
     1327        | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')'
    13261328                { $$ = (ExpressionNode *)($3->set_last( $5 )); }
    13271329        ;
     
    13301332        cast_expression
    13311333        | cast_expression_list ',' cast_expression
    1332                 { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     1334                // { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     1335                { SemanticError( yylloc, "List of mutex member is currently unimplemented." ); $$ = nullptr; }
    13331336        ;
    13341337
     
    20952098
    20962099aggregate_control:                                                                              // CFA
    2097         GENERATOR
     2100        MONITOR
     2101                { yyy = true; $$ = AggregateDecl::Monitor; }
     2102        | MUTEX STRUCT
     2103                { yyy = true; $$ = AggregateDecl::Monitor; }
     2104        | GENERATOR
    20982105                { yyy = true; $$ = AggregateDecl::Generator; }
    2099         | MONITOR GENERATOR
     2106        | MUTEX GENERATOR
    21002107                { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    21012108        | COROUTINE
    21022109                { yyy = true; $$ = AggregateDecl::Coroutine; }
    2103         | MONITOR
    2104                 { yyy = true; $$ = AggregateDecl::Monitor; }
    2105         | MONITOR COROUTINE
     2110        | MUTEX COROUTINE
    21062111                { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    21072112        | THREAD
    21082113                { yyy = true; $$ = AggregateDecl::Thread; }
    2109         | MONITOR THREAD
     2114        | MUTEX THREAD
    21102115                { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    21112116        ;
     
    27742779        | attr_name
    27752780                { $$ = DeclarationNode::newAttribute( $1 ); }
    2776         | attr_name '(' argument_expression_list ')'
     2781        | attr_name '(' argument_expression_list_opt ')'
    27772782                { $$ = DeclarationNode::newAttribute( $1, $3 ); }
    27782783        ;
  • src/Virtual/ExpandCasts.cc

    ra5873bd r97392b69  
    1010// Created On       : Mon Jul 24 13:59:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Aug  2 14:59:00 2017
    13 // Update Count     : 1
     12// Last Modified On : Tue May 26 14:37:00 2020
     13// Update Count     : 2
    1414//
    1515
     
    111111        }
    112112
     113        // Better error locations for generated casts.
     114        static CodeLocation castLocation( VirtualCastExpr * castExpr ) {
     115                if ( castExpr->location.isSet() ) {
     116                        return castExpr->location;
     117                } else if ( castExpr->arg->location.isSet() ) {
     118                        return castExpr->arg->location;
     119                } else if ( castExpr->result->location.isSet() ) {
     120                        return castExpr->result->location;
     121                } else {
     122                        return CodeLocation();
     123                }
     124        }
     125
    113126        Expression * VirtualCastCore::postmutate( VirtualCastExpr * castExpr ) {
    114127                assertf( castExpr->get_result(), "Virtual Cast target not found before expansion." );
     
    117130                assert( pvt_decl );
    118131
    119                 // May only cast to a pointer or reference type.
    120                 // A earlier validation should give a syntax error, this is
    121                 // just to make sure errors don't creep during translation.
    122                 // Move to helper with more detailed error messages.
    123                 PointerType * target_type =
    124                         dynamic_cast<PointerType *>( castExpr->get_result() );
    125                 assert( target_type );
     132                // Get the base type of the pointer/reference.
     133                Type * base;
     134                Type * result_type = castExpr->result;
     135                if ( PointerType * target = dynamic_cast<PointerType *>( result_type ) ) {
     136                        base = target->base;
     137                } else if ( ReferenceType * target = dynamic_cast<ReferenceType *>( result_type ) ) {
     138                        base = target->base;
     139                } else {
     140                        SemanticError( castLocation( castExpr ),
     141                                "Virtual cast type must be a pointer or reference type." );
     142                }
    126143
    127                 StructInstType * target_struct =
    128                         dynamic_cast<StructInstType *>( target_type->get_base() );
    129                 assert( target_struct );
    130 
     144                StructInstType * target_struct = dynamic_cast<StructInstType *>( base );
     145                if ( nullptr == target_struct ) {
     146                        SemanticError( castLocation( castExpr ),
     147                                "Virtual cast type must refer to a structure type." );
     148                }
    131149                StructDecl * target_decl = target_struct->get_baseStruct();
    132150
    133151                std::map<std::string, ObjectDecl *>::iterator found =
    134                         vtable_instances.find(
    135                                 get_vtable_inst_name( target_decl->get_name() ) );
     152                        vtable_instances.find( get_vtable_inst_name( target_decl->get_name() ) );
    136153                if ( vtable_instances.end() == found ) {
    137                         assertf( false, "virtual table instance not found." );
     154                        SemanticError( castLocation( castExpr ),
     155                                "Virtual cast type does not have a virtual table instance." );
    138156                }
    139157                ObjectDecl * table = found->second;
    140158
    141159                Expression * result = new CastExpr(
    142                         //new ApplicationExpr(
    143                                 //new AddressExpr( new VariableExpr( vcast_decl ) ),
    144                                 //new CastExpr( new VariableExpr( vcast_decl ),
    145                                 //      new PointerType( noQualifiers,
    146                                 //              vcast_decl->get_type()->clone()
    147                                 //              )
    148                                 //      ),
    149160                        new ApplicationExpr( VariableExpr::functionPointer( vcast_decl ), {
    150161                                        new CastExpr(
Note: See TracChangeset for help on using the changeset viewer.