Ignore:
Timestamp:
May 25, 2018, 5:01:37 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, with_gc
Children:
3ed994e
Parents:
2c88368
git-author:
Rob Schluntz <rschlunt@…> (05/25/18 16:59:30)
git-committer:
Rob Schluntz <rschlunt@…> (05/25/18 17:01:37)
Message:

Add AST support for _Generic, along with C codegen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r2c88368 rd807ca28  
    175175        bool flag;
    176176        CatchStmt::Kind catch_kind;
     177        GenericExpr * genexpr;
    177178}
    178179
     
    259260%type<flag> asm_volatile_opt
    260261%type<en> handler_predicate_opt
     262%type<genexpr> generic_association generic_assoc_list
    261263
    262264// statements
     
    501503                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    502504        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    503                 { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; }
     505                {
     506                        // add the missing control expression to the GenericExpr and return it
     507                        $5->control = maybeMoveBuild<Expression>( $3 );
     508                        $$ = new ExpressionNode( $5 );
     509                }
    504510        ;
    505511
    506512generic_assoc_list:                                                                             // C11
    507         | generic_association
     513        generic_association
    508514        | generic_assoc_list ',' generic_association
     515                {
     516                        // steal the association node from the singleton and delete the wrapper
     517                        $1->associations.splice($1->associations.end(), $3->associations);
     518                        delete $3;
     519                        $$ = $1;
     520                }
    509521        ;
    510522
    511523generic_association:                                                                    // C11
    512524        type_no_function ':' assignment_expression
     525                {
     526                        // create a GenericExpr wrapper with one association pair
     527                        $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } );
     528                }
    513529        | DEFAULT ':' assignment_expression
     530                { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); }
    514531        ;
    515532
Note: See TracChangeset for help on using the changeset viewer.