Changeset 9a1e509 for src/Parser


Ignore:
Timestamp:
Jul 13, 2017, 3:57:23 PM (7 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, resolv-new, with_gc
Children:
bf30ab3
Parents:
1d776fd (diff), 3d4b23fa (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 references

Location:
src/Parser
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/LinkageSpec.cc

    r1d776fd r9a1e509  
    1010// Created On       : Sat May 16 13:22:09 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jun 28 11:51:00 2017
    13 // Update Count     : 24
     12// Last Modified On : Fri Jul  7 11:11:00 2017
     13// Update Count     : 25
    1414//
    1515
     
    2222#include "Common/SemanticError.h"
    2323
    24 LinkageSpec::Spec LinkageSpec::linkageCheck( const string * spec ) {
     24namespace LinkageSpec {
     25
     26Spec linkageCheck( const string * spec ) {
     27        assert( spec );
    2528        unique_ptr<const string> guard( spec ); // allocated by lexer
    2629        if ( *spec == "\"Cforall\"" ) {
     
    3538}
    3639
    37 string LinkageSpec::linkageName( LinkageSpec::Spec linkage ) {
    38         assert( 0 <= linkage && linkage < LinkageSpec::NoOfSpecs );
    39         static const char *linkageKinds[LinkageSpec::NoOfSpecs] = {
    40                 "intrinsic", "Cforall", "C", "automatically generated", "compiler built-in", "cfa built-in", "c built-in",
    41         };
    42         return linkageKinds[linkage];
     40Spec linkageUpdate( Spec old_spec, const string * cmd ) {
     41        assert( cmd );
     42        unique_ptr<const string> guard( cmd ); // allocated by lexer
     43        if ( *cmd == "\"Cforall\"" ) {
     44                old_spec.is_mangled = true;
     45                return old_spec;
     46        } else if ( *cmd == "\"C\"" ) {
     47                old_spec.is_mangled = false;
     48                return old_spec;
     49        } else {
     50                throw SemanticError( "Invalid linkage specifier " + *cmd );
     51        } // if
    4352}
    4453
    45 bool LinkageSpec::isMangled( Spec spec ) {
    46         assert( 0 <= spec && spec < LinkageSpec::NoOfSpecs );
    47         static bool decoratable[LinkageSpec::NoOfSpecs] = {
    48                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler,
    49                         true,           true,           false,  true,           false,
    50                 //      Builtin,        BuiltinC,
    51                         true,           false,
    52         };
    53         return decoratable[spec];
     54std::string linkageName( Spec linkage ) {
     55    switch ( linkage ) {
     56    case Intrinsic:
     57        return "intrinsic";
     58    case C:
     59        return "C";
     60    case Cforall:
     61        return "Cforall";
     62    case AutoGen:
     63        return "autogenerated cfa";
     64    case Compiler:
     65        return "compiler built-in";
     66    case BuiltinCFA:
     67        return "cfa built-in";
     68    case BuiltinC:
     69        return "c built-in";
     70    default:
     71        return "<unnamed linkage spec>";
     72    }
    5473}
    5574
    56 bool LinkageSpec::isGeneratable( Spec spec ) {
    57         assert( 0 <= spec && spec < LinkageSpec::NoOfSpecs );
    58         static bool generatable[LinkageSpec::NoOfSpecs] = {
    59                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler,
    60                         true,           true,           true,   true,           false,
    61                 //      Builtin,        BuiltinC,
    62                         true,           true,
    63         };
    64         return generatable[spec];
    65 }
    66 
    67 bool LinkageSpec::isOverridable( Spec spec ) {
    68         assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs );
    69         static bool overridable[LinkageSpec::NoOfSpecs] = {
    70                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler,
    71                         true,           false,          false,  true,           false,
    72                 //      Builtin,        BuiltinC,
    73                         false,          false,
    74         };
    75         return overridable[spec];
    76 }
    77 
    78 bool LinkageSpec::isBuiltin( Spec spec ) {
    79         assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs );
    80         static bool builtin[LinkageSpec::NoOfSpecs] = {
    81                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler,
    82                         true,           false,          false,  false,          true,
    83                 //      Builtin,        BuiltinC,
    84                         true,           true,
    85         };
    86         return builtin[spec];
    87 }
     75} // LinkageSpec
    8876
    8977// Local Variables: //
  • src/Parser/LinkageSpec.h

    r1d776fd r9a1e509  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // LinkageSpec.h -- 
     7// LinkageSpec.h --
    88//
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:24:28 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jun 28 11:50:00 2017
    13 // Update Count     : 12
     12// Last Modified On : Fri Jul  7 11:03:00 2017
     13// Update Count     : 13
    1414//
    1515
     
    1919#include <string>
    2020
    21 struct LinkageSpec {
    22         enum Spec {
    23                 Intrinsic,                                                                              // C built-in defined in prelude
    24                 Cforall,                                                                                // ordinary
    25                 C,                                                                                              // not overloadable, not mangled
    26                 AutoGen,                                                                                // built by translator (struct assignment)
    27                 Compiler,                                                                               // gcc internal
    28                 Builtin,                                                                                // mangled builtins
    29                 BuiltinC,                                                                               // non-mangled builtins
    30                 NoOfSpecs
     21namespace LinkageSpec {
     22        // All linkage specs are some combination of these flags:
     23        enum {
     24                Mangle = 1 << 0,
     25                Generate = 1 << 1,
     26                Overrideable = 1 << 2,
     27                Builtin = 1 << 3,
     28
     29                NoOfSpecs = 1 << 4,
    3130        };
    32  
    33         static Spec linkageCheck( const std::string * );
    34         static std::string linkageName( Spec );
    35  
    36         static bool isMangled( Spec );
    37         static bool isGeneratable( Spec );
    38         static bool isOverridable( Spec );
    39         static bool isBuiltin( Spec );
     31
     32        union Spec {
     33                unsigned int val;
     34                struct {
     35                        bool is_mangled : 1;
     36                        bool is_generatable : 1;
     37                        bool is_overridable : 1;
     38                        bool is_builtin : 1;
     39                };
     40                constexpr Spec( unsigned int val ) : val( val ) {}
     41                constexpr Spec( Spec const &other ) : val( other.val ) {}
     42                // Operators may go here.
     43                // Supports == and !=
     44                constexpr operator unsigned int () const { return val; }
     45        };
     46
     47
     48        Spec linkageCheck( const std::string * );
     49        // Returns the Spec with the given name (limited to C, Cforall & BuiltinC)
     50        Spec linkageUpdate( Spec old_spec, const std::string * cmd );
     51        /* If cmd = "C" returns a Spec that is old_spec with is_mangled = false
     52         * If cmd = "Cforall" returns old_spec Spec with is_mangled = true
     53         */
     54
     55        std::string linkageName( Spec );
     56
     57        // To Update: LinkageSpec::isXyz( cur_spec ) -> cur_spec.is_xyz
     58        inline bool isMangled( Spec spec ) { return spec.is_mangled; }
     59        inline bool isGeneratable( Spec spec ) { return spec.is_generatable; }
     60        inline bool isOverridable( Spec spec ) { return spec.is_overridable; }
     61        inline bool isBuiltin( Spec spec ) { return spec.is_builtin; }
     62
     63        // Pre-defined flag combinations:
     64        // C built-in defined in prelude
     65        constexpr Spec const Intrinsic = { Mangle | Generate | Overrideable | Builtin };
     66        // ordinary
     67        constexpr Spec const Cforall = { Mangle | Generate };
     68        // not overloadable, not mangled
     69        constexpr Spec const C = { Generate };
     70        // built by translator (struct assignment)
     71        constexpr Spec const AutoGen = { Mangle | Generate | Overrideable };
     72        // gcc internal
     73        constexpr Spec const Compiler = { Builtin };
     74        // mangled builtins
     75        constexpr Spec const BuiltinCFA = { Mangle | Generate | Builtin };
     76        // non-mangled builtins
     77        constexpr Spec const BuiltinC = { Generate | Builtin };
    4078};
    4179
  • src/Parser/StatementNode.cc

    r1d776fd r9a1e509  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 28 21:08:37 2017
    13 // Update Count     : 330
     12// Last Modified On : Tue Jul 11 21:23:15 2017
     13// Update Count     : 331
    1414//
    1515
     
    9393        std::list< Statement * > branches;
    9494        buildMoveList< Statement, StatementNode >( stmt, branches );
    95         assert( branches.size() >= 0 );                                         // size == 0 for switch (...) {}, i.e., no declaration or statements
     95        // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements
    9696        return new SwitchStmt( noLabels, maybeMoveBuild< Expression >(ctl), branches );
    9797}
  • src/Parser/lex.ll

    r1d776fd r9a1e509  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Wed Jun 28 21:03:45 2017
    13  * Update Count     : 529
     12 * Last Modified On : Wed Jul 12 18:04:44 2017
     13 * Update Count     : 535
    1414 */
    1515
     
    5959}
    6060
     61// Stop warning due to incorrectly generated flex code.
     62#pragma GCC diagnostic ignored "-Wsign-compare"
    6163%}
    6264
     
    272274__volatile__    { KEYWORD_RETURN(VOLATILE); }                   // GCC
    273275while                   { KEYWORD_RETURN(WHILE); }
     276with                    { KEYWORD_RETURN(WITH); }                               // CFA
    274277zero_t                  { NUMERIC_RETURN(ZERO_T); }                             // CFA
    275278
  • src/Parser/parser.yy

    r1d776fd r9a1e509  
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep  1 20:22:55 2001
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Jun 30 15:38:00 2017
    13 // Update Count     : 2415
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Jul 12 18:23:36 2017
     13// Update Count     : 2426
    1414//
    1515
     
    129129%token ATTRIBUTE EXTENSION                                                              // GCC
    130130%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    131 %token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT        // CFA
     131%token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH   // CFA
    132132%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    133133%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
     
    184184// statements
    185185%type<sn> labeled_statement                             compound_statement                      expression_statement            selection_statement
    186 %type<sn> iteration_statement                   jump_statement                          exception_statement                     asm_statement
     186%type<sn> iteration_statement                   jump_statement
     187%type<sn> with_statement                                exception_statement                     asm_statement
    187188%type<sn> fall_through_opt                              fall_through
    188189%type<sn> statement                                             statement_list
    189190%type<sn> block_item_list                               block_item
    190 %type<sn> case_clause
     191%type<sn> with_clause_opt
    191192%type<en> case_value
    192 %type<sn> case_value_list                               case_label                                      case_label_list
     193%type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
    193194%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    194195%type<sn> /* handler_list */                    handler_clause                          finally_clause
     
    729730        | iteration_statement
    730731        | jump_statement
     732        | with_statement
    731733        | exception_statement
    732734        | asm_statement
     
    934936        | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume
    935937                { $$ = new StatementNode( build_resume_at( $2, $4 ) ); }
     938        ;
     939
     940with_statement:
     941        WITH identifier_list compound_statement
     942                { $$ = (StatementNode *)0; }                                    // FIX ME
    936943        ;
    937944
     
    21762183                {
    21772184                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2178                         linkage = LinkageSpec::linkageCheck( $2 );
     2185                        linkage = LinkageSpec::linkageUpdate( linkage, $2 );
    21792186                }
    21802187          '{' external_definition_list_opt '}'
     
    22122219        ;
    22132220
     2221with_clause_opt:
     2222        // empty
     2223                { $$ = (StatementNode *)0; }                                    // FIX ME
     2224        | WITH identifier_list
     2225                { $$ = (StatementNode *)0; }                                    // FIX ME
     2226        ;
     2227
    22142228function_definition:
    2215         cfa_function_declaration compound_statement                     // CFA
     2229        cfa_function_declaration with_clause_opt compound_statement     // CFA
    22162230                {
    22172231                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22182232                        typedefTable.leaveScope();
    2219                         $$ = $1->addFunctionBody( $2 );
    2220                 }
    2221         | declaration_specifier function_declarator compound_statement
     2233                        $$ = $1->addFunctionBody( $3 );
     2234                }
     2235        | declaration_specifier function_declarator with_clause_opt compound_statement
    22222236                {
    22232237                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22242238                        typedefTable.leaveScope();
    2225                         $$ = $2->addFunctionBody( $3 )->addType( $1 );
    2226                 }
    2227         | type_qualifier_list function_declarator compound_statement
     2239                        $$ = $2->addFunctionBody( $4 )->addType( $1 );
     2240                }
     2241        | type_qualifier_list function_declarator with_clause_opt compound_statement
    22282242                {
    22292243                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22302244                        typedefTable.leaveScope();
    2231                         $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 );
    2232                 }
    2233         | declaration_qualifier_list function_declarator compound_statement
     2245                        $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
     2246                }
     2247        | declaration_qualifier_list function_declarator with_clause_opt compound_statement
    22342248                {
    22352249                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22362250                        typedefTable.leaveScope();
    2237                         $$ = $2->addFunctionBody( $3 )->addQualifiers( $1 );
    2238                 }
    2239         | declaration_qualifier_list type_qualifier_list function_declarator compound_statement
     2251                        $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
     2252                }
     2253        | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
    22402254                {
    22412255                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22422256                        typedefTable.leaveScope();
    2243                         $$ = $3->addFunctionBody( $4 )->addQualifiers( $2 )->addQualifiers( $1 );
     2257                        $$ = $3->addFunctionBody( $5 )->addQualifiers( $2 )->addQualifiers( $1 );
    22442258                }
    22452259
    22462260                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2247         | declaration_specifier KR_function_declarator push KR_declaration_list_opt compound_statement
     2261        | declaration_specifier KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
    22482262                {
    22492263                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22502264                        typedefTable.leaveScope();
    2251                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addType( $1 );
    2252                 }
    2253         | type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
     2265                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addType( $1 );
     2266                }
     2267        | type_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
    22542268                {
    22552269                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22562270                        typedefTable.leaveScope();
    2257                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2271                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
    22582272                }
    22592273
    22602274                // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
    2261         | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
     2275        | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
    22622276                {
    22632277                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22642278                        typedefTable.leaveScope();
    2265                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 );
    2266                 }
    2267         | declaration_qualifier_list type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement
     2279                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
     2280                }
     2281        | declaration_qualifier_list type_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
    22682282                {
    22692283                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22702284                        typedefTable.leaveScope();
    2271                         $$ = $3->addOldDeclList( $5 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
     2285                        $$ = $3->addOldDeclList( $5 )->addFunctionBody( $7 )->addQualifiers( $2 )->addQualifiers( $1 );
    22722286                }
    22732287        ;
     
    23322346        | TYPEGENname
    23332347        | CONST
    2334                 { $$ = Token{ new string( "__const__" ) }; }
     2348                { $$ = Token{ new string( "__const__" ), { nullptr, -1 } }; }
    23352349        ;
    23362350
Note: See TracChangeset for help on using the changeset viewer.