Changeset 8c17ab0 for translator/Parser


Ignore:
Timestamp:
Nov 13, 2014, 3:09:54 PM (10 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
c8ffe20b
Parents:
134b86a
Message:

add quoted identifiers, add compilation include directory, reformatted some files

Location:
translator/Parser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • translator/Parser/DeclarationNode.cc

    r134b86a r8c17ab0  
    112112}
    113113
    114 /* static class method */
    115114DeclarationNode *
    116115DeclarationNode::newFunction( std::string* name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle )
     
    136135}
    137136
    138 /* static class method */
    139137DeclarationNode *
    140138DeclarationNode::newQualifier( Qualifier q )
     
    146144}
    147145
    148 /* static class method */
    149146DeclarationNode *
    150147DeclarationNode::newStorageClass( StorageClass sc )
     
    155152}
    156153
    157 /* static class method */
    158154DeclarationNode *
    159155DeclarationNode::newBasicType( BasicType bt )
     
    165161}
    166162
    167 /* static class method */
    168163DeclarationNode *
    169164DeclarationNode::newModifier( Modifier mod )
     
    175170}
    176171
    177 /* static class method */
    178172DeclarationNode *
    179173DeclarationNode::newForall( DeclarationNode* forall )
     
    185179}
    186180
    187 /* static class method */
    188181DeclarationNode *
    189182DeclarationNode::newFromTypedef( std::string* name )
     
    197190}
    198191
    199 /* static class method */
    200192DeclarationNode *
    201193DeclarationNode::newAggregate( TyCon kind, std::string* name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields )
     
    214206}
    215207
    216 /* static class method */
    217208DeclarationNode *
    218209DeclarationNode::newEnum( std::string *name, DeclarationNode *constants )
     
    229220}
    230221
    231 /* static class method */
    232222DeclarationNode *
    233223DeclarationNode::newEnumConstant( std::string* name, ExpressionNode *constant )
     
    239229}
    240230
    241 /* static class method */
    242231DeclarationNode *
    243232DeclarationNode::newName( std::string* name )
     
    248237}
    249238
    250 /* static class method */
    251239DeclarationNode *
    252240DeclarationNode::newFromTypeGen( std::string* name, ExpressionNode *params )
     
    260248}
    261249
    262 /* static class method */
    263250DeclarationNode *
    264251DeclarationNode::newTypeParam( TypeClass tc, std::string* name )
     
    272259}
    273260
    274 /* static class method */
    275261DeclarationNode *
    276262DeclarationNode::newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts )
     
    285271}
    286272
    287 /* static class method */
    288273DeclarationNode *
    289274DeclarationNode::newContextUse( std::string *name, ExpressionNode *params )
     
    298283}
    299284
    300 /* static class method */
    301285DeclarationNode *
    302286DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams )
     
    311295}
    312296
    313 /* static class method */
    314297DeclarationNode *
    315298DeclarationNode::newPointer( DeclarationNode *qualifiers )
     
    320303}
    321304
    322 /* static class method */
    323305DeclarationNode *
    324306DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic )
     
    332314}
    333315
    334 /* static class method */
    335316DeclarationNode *
    336317DeclarationNode::newVarArray( DeclarationNode *qualifiers )
     
    344325}
    345326
    346 /* static class method */
    347327DeclarationNode *
    348328DeclarationNode::newBitfield( ExpressionNode *size )
     
    353333}
    354334
    355 /* static class method */
    356335DeclarationNode *
    357336DeclarationNode::newTuple( DeclarationNode *members )
     
    363342}
    364343
    365 /* static class method */
    366344DeclarationNode *
    367345DeclarationNode::newTypeof( ExpressionNode *expr )
     
    373351}
    374352
    375 /* static class method */
    376353DeclarationNode *
    377354DeclarationNode::newAttr( std::string *name, ExpressionNode *expr )
     
    384361}
    385362
    386 /* static class method */
    387363DeclarationNode *
    388364DeclarationNode::newAttr( std::string *name, DeclarationNode *type )
  • translator/Parser/TypedefTable.cc

    r134b86a r8c17ab0  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TypedefTable.cc,v 1.7 2004/09/14 17:21:12 rcbilson Exp $
    5  *
    6  */
    7 
    81#include <map>
    92#include <list>
     
    1912#endif
    2013
    21 TypedefTable::TypedefTable()
    22     : currentScope(0)
    23 {
    24 }
     14TypedefTable::TypedefTable() : currentScope(0) {}
    2515
    26 bool
    27 TypedefTable::isKind(string identifier, kind_t kind) const
    28 {
     16bool TypedefTable::isKind(string identifier, kind_t kind) const {
    2917    tableType::const_iterator id_pos = table.find(identifier);
    3018    if (id_pos == table.end()) {
     
    3523}
    3624
    37 bool
    38 TypedefTable::isIdentifier(string identifier) const
    39 {
     25bool TypedefTable::isIdentifier(string identifier) const {
    4026    return isKind(identifier, ID);
    4127}
    4228
    43 bool
    44 TypedefTable::isTypedef(string identifier) const
    45 {
     29bool TypedefTable::isTypedef(string identifier) const {
    4630    return isKind(identifier, TD);
    4731}
    4832
    49 bool
    50 TypedefTable::isTypegen(string identifier) const
    51 {
     33bool TypedefTable::isTypegen(string identifier) const {
    5234    return isKind(identifier, TG);
    5335}
    5436
    55 void
    56 TypedefTable::addToScope(const std::string &identifier, kind_t kind, int scope)
    57 {
    58   if( currentContext != "" && scope == contextScope ) {
    59     DeferredEntry entry = { identifier, kind };
    60     contexts[currentContext].push_back( entry );
    61   } else {
    62     debugPrint( "Adding " << identifier << " as type " << kind << " scope " << scope << " from scope " << currentScope << endl );
    63     Entry newEntry = { scope, kind };
    64     tableType::iterator curPos = table.find(identifier);
    65     if (curPos == table.end()) {
    66       list<Entry> newList;
    67       newList.push_front(newEntry);
    68       table[identifier] = newList;
     37void TypedefTable::addToScope(const std::string &identifier, kind_t kind, int scope) {
     38    if ( currentContext != "" && scope == contextScope ) {
     39        DeferredEntry entry = { identifier, kind };
     40        contexts[currentContext].push_back( entry );
    6941    } else {
    70       list<Entry>::iterator listPos = (*curPos).second.begin();
    71       while( listPos != (*curPos).second.end() && listPos->scope > scope ) {
    72         listPos++;
    73       }
    74       (*curPos).second.insert(listPos, newEntry);
     42        debugPrint( "Adding " << identifier << " as type " << kind << " scope " << scope << " from scope " << currentScope << endl );
     43        Entry newEntry = { scope, kind };
     44        tableType::iterator curPos = table.find(identifier);
     45        if (curPos == table.end()) {
     46            list<Entry> newList;
     47            newList.push_front(newEntry);
     48            table[identifier] = newList;
     49        } else {
     50            list<Entry>::iterator listPos = (*curPos).second.begin();
     51            while( listPos != (*curPos).second.end() && listPos->scope > scope ) {
     52                listPos++;
     53            }
     54            (*curPos).second.insert(listPos, newEntry);
     55        }
    7556    }
    76   }
    7757}
    7858
    79 void
    80 TypedefTable::addToCurrentScope(const std::string &identifier, kind_t kind)
    81 {
    82   addToScope( identifier, kind, currentScope );
     59void TypedefTable::addToCurrentScope(const std::string &identifier, kind_t kind) {
     60    addToScope( identifier, kind, currentScope );
    8361}
    8462
    85 void
    86 TypedefTable::addToCurrentScope(kind_t kind)
    87 {
    88   addToCurrentScope( nextIdentifiers.top(), kind );
     63void TypedefTable::addToCurrentScope(kind_t kind) {
     64    addToCurrentScope( nextIdentifiers.top(), kind );
    8965}
    9066
    91 void
    92 TypedefTable::addToEnclosingScope(const std::string &identifier, kind_t kind)
    93 {
    94   assert( currentScope >= 1 );
    95   addToScope( identifier, kind, currentScope - 1 );
     67void TypedefTable::addToEnclosingScope(const std::string &identifier, kind_t kind) {
     68    assert( currentScope >= 1 );
     69    addToScope( identifier, kind, currentScope - 1 );
    9670}
    9771
    98 void
    99 TypedefTable::addToEnclosingScope(kind_t kind)
    100 {
    101   addToEnclosingScope( nextIdentifiers.top(), kind );
     72void TypedefTable::addToEnclosingScope(kind_t kind) {
     73    addToEnclosingScope( nextIdentifiers.top(), kind );
    10274}
    10375
    104 void
    105 TypedefTable::addToEnclosingScope2(const std::string &identifier, kind_t kind)
    106 {
    107   assert( currentScope >= 2 );
    108   addToScope( identifier, kind, currentScope - 2 );
     76void TypedefTable::addToEnclosingScope2(const std::string &identifier, kind_t kind) {
     77    assert( currentScope >= 2 );
     78    addToScope( identifier, kind, currentScope - 2 );
    10979}
    11080
    111 void
    112 TypedefTable::addToEnclosingScope2(kind_t kind)
    113 {
    114   addToEnclosingScope2( nextIdentifiers.top(), kind );
     81void TypedefTable::addToEnclosingScope2(kind_t kind) {
     82    addToEnclosingScope2( nextIdentifiers.top(), kind );
    11583}
    11684
    117 void
    118 TypedefTable::setNextIdentifier( const std::string &identifier )
    119 {
    120   nextIdentifiers.top() = identifier;
     85void TypedefTable::setNextIdentifier( const std::string &identifier ) {
     86    nextIdentifiers.top() = identifier;
    12187}
    12288
    123 void
    124 TypedefTable::openContext( std::string contextName )
    125 {
    126   map< string, deferListType >::iterator i = contexts.find( contextName );
    127   if( i != contexts.end() ) {
    128     deferListType &entries = i->second;
    129     for (deferListType::iterator i = entries.begin(); i != entries.end(); i++) {
    130       addToEnclosingScope( i->identifier, i->kind );
     89void TypedefTable::openContext( std::string contextName ) {
     90    map< string, deferListType >::iterator i = contexts.find( contextName );
     91    if ( i != contexts.end() ) {
     92        deferListType &entries = i->second;
     93        for (deferListType::iterator i = entries.begin(); i != entries.end(); i++) {
     94            addToEnclosingScope( i->identifier, i->kind );
     95        }
    13196    }
    132   }
    13397}
    13498
    135 void
    136 TypedefTable::enterScope(void)
    137 {
     99void TypedefTable::enterScope(void) {
    138100    currentScope += 1;
    139101    deferListStack.push( deferListType() );
     
    142104}
    143105
    144 void
    145 TypedefTable::leaveScope(void)
    146 {
     106void TypedefTable::leaveScope(void) {
    147107    debugPrint( "Leaving scope " << currentScope << endl );
    148108    for (tableType::iterator i = table.begin(); i != table.end(); i++) {
     
    151111            declList.pop_front();
    152112        }
    153         if( declList.empty() ) {
    154           table.erase( i );
     113        if ( declList.empty() ) {
     114            table.erase( i );
    155115        }
    156116    }
    157117    currentScope -= 1;
    158118    for (deferListType::iterator i = deferListStack.top().begin(); i != deferListStack.top().end(); i++) {
    159       addToCurrentScope( i->identifier, i->kind );
     119        addToCurrentScope( i->identifier, i->kind );
    160120    }
    161121    deferListStack.pop();
     
    164124}
    165125
    166 void
    167 TypedefTable::enterContext( std::string contextName )
    168 {
    169   currentContext = contextName;
    170   contextScope = currentScope;
     126void TypedefTable::enterContext( std::string contextName ) {
     127    currentContext = contextName;
     128    contextScope = currentScope;
    171129}
    172130
    173 void
    174 TypedefTable::leaveContext(void)
    175 {
    176   currentContext = "";
     131void TypedefTable::leaveContext(void) {
     132    currentContext = "";
    177133}
    178134
    179 void
    180 TypedefTable::print(void) const
    181 {
     135void TypedefTable::print(void) const {
    182136    for (tableType::const_iterator i = table.begin(); i != table.end(); i++) {
    183137        debugPrint( (*i).first << ": " );
  • translator/Parser/cfa.y

    r134b86a r8c17ab0  
    1010 * Created On       : Sat Sep  1 20:22:55 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Mon Nov  3 16:24:24 2014
    13  * Update Count     : 880
     12 * Last Modified On : Sun Nov  9 22:45:42 2014
     13 * Update Count     : 881
    1414 */
    1515
     
    8484
    8585/* names and constants: lexer differentiates between identifier and typedef names */
    86 %token<tok> IDENTIFIER          TYPEDEFname             TYPEGENname
     86%token<tok> IDENTIFIER          QUOTED_IDENTIFIER       TYPEDEFname             TYPEGENname
    8787%token<tok> ATTR_IDENTIFIER     ATTR_TYPEDEFname        ATTR_TYPEGENname
    8888%token<tok> INTEGERconstant     FLOATINGconstant        CHARACTERconstant       STRINGliteral
  • translator/Parser/lex.l

    r134b86a r8c17ab0  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Sat Nov  1 18:09:47 2003
    13  * Update Count     : 197
     12 * Last Modified On : Tue Nov 11 08:10:05 2014
     13 * Update Count     : 215
    1414 */
    1515
     
    1717
    1818%{
    19 /* This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor
    20   directive have been performed and removed from the source. The only exceptions are preprocessor
    21   directives passed to the compiler (e.g., line-number directives) and C/C++ style comments, which
    22    are ignored. */
    23 
    24 /*************** Includes and Defines *****************************/
     19// This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor
     20// directive have been performed and removed from the source. The only exceptions are preprocessor
     21// directives passed to the compiler (e.g., line-number directives) and C/C++ style comments, which
     22// are ignored.
     23
     24//**************************** Includes and Defines ****************************
    2525
    2626#include <string>
     
    2828#include "lex.h"
    2929#include "ParseNode.h"
    30 #include "cfa.tab.h" /* YACC generated definitions based on C++ grammar */
     30#include "cfa.tab.h" // YACC generated definitions based on C++ grammar
    3131
    3232char *yyfilename;
    3333
    34 #define WHITE_RETURN(x)         /* do nothing */
     34#define WHITE_RETURN(x)                                 // do nothing
    3535#define NEWLINE_RETURN()        WHITE_RETURN('\n')
    3636#define RETURN_VAL(x)           yylval.tok.str = new std::string(yytext); \
     
    3939                                return(x)
    4040
    41 #define KEYWORD_RETURN(x)       RETURN_VAL(x)           /* keyword */
     41#define KEYWORD_RETURN(x)       RETURN_VAL(x)           // keyword
    4242#define IDENTIFIER_RETURN()     RETURN_VAL((typedefTable.isIdentifier(yytext) ? IDENTIFIER : typedefTable.isTypedef(yytext) ? TYPEDEFname : TYPEGENname))
    43 #define ATTRIBUTE_RETURN()      RETURN_VAL((typedefTable.isIdentifier(yytext) ? ATTR_IDENTIFIER : typedefTable.isTypedef(yytext) ? ATTR_TYPEDEFname : ATTR_TYPEGENname))
    44 
    45 #define ASCIIOP_RETURN()        RETURN_VAL((int)yytext[0]) /* single character operator */
    46 #define NAMEDOP_RETURN(x)       RETURN_VAL(x)           /* multichar operator, with a name */
    47 
    48 #define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL(x) /* numeric constant */
    49 
    50 void rm_underscore() {                                  /* remove underscores in constant or escape sequence */
     43//#define ATTRIBUTE_RETURN()    RETURN_VAL((typedefTable.isIdentifier(yytext) ? ATTR_IDENTIFIER : typedefTable.isTypedef(yytext) ? ATTR_TYPEDEFname : ATTR_TYPEGENname))
     44#define ATTRIBUTE_RETURN()      RETURN_VAL(ATTR_IDENTIFIER)
     45
     46#define ASCIIOP_RETURN()        RETURN_VAL((int)yytext[0]) // single character operator
     47#define NAMEDOP_RETURN(x)       RETURN_VAL(x)           // multichar operator, with a name
     48
     49#define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL(x) // numeric constant
     50
     51void rm_underscore() {                                  // remove underscores in constant or escape sequence
    5152    int j = 0;
    5253    for ( int i = 0; i < yyleng; i += 1 ) {
     
    6869universal_char "\\"((u{hex_quad})|(U{hex_quad}{2}))
    6970
    70         /* identifier, GCC: $ in identifier */
     71        // identifier, GCC: $ in identifier
    7172identifier ([a-zA-Z_$]|{universal_char})([0-9a-zA-Z_$]|{universal_char})*
    7273
    73         /* attribute identifier, GCC: $ in identifier */
     74        // quoted identifier
     75quoted_identifier "`"{identifier}"`"
     76
     77        // attribute identifier, GCC: $ in identifier
    7478attr_identifier "@"{identifier}
    7579
    76         /*  numeric constants, CFA: '_' in constant */
     80        // numeric constants, CFA: '_' in constant
    7781hex_quad {hex}{4}
    7882integer_suffix "_"?(([uU][lL]?)|([uU]("ll"|"LL")?)|([lL][uU]?)|("ll"|"LL")[uU]?)
     
    99103hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix}?
    100104
    101         /* character escape sequence, GCC: \e => esc character */
     105        // character escape sequence, GCC: \e => esc character
    102106simple_escape "\\"[abefnrtv'"?\\]
     107        // ' stop highlighting
    103108octal_escape "\\"{octal}{1,3}
    104109hex_escape "\\""x"{hex}+
    105110escape_seq {simple_escape}|{octal_escape}|{hex_escape}|{universal_char}
    106111
    107         /* display/white-space characters */
     112        // display/white-space characters
    108113h_tab [\011]
    109114form_feed [\014]
     
    112117h_white [ ]|{h_tab}
    113118
    114         /* operators */
     119        // operators
    115120op_unary_only "~"|"!"
    116121op_unary_binary "+"|"-"|"*"
     
    124129
    125130%x COMMENT
     131%x QUOTED
    126132
    127133%%
    128134        /* line directives */
    129135^{h_white}*"#"{h_white}*[0-9]+{h_white}*["][^"\n]+["][^\n]*"\n" {
     136        /* " stop highlighting */
    130137        char *end_num;
    131138        char *begin_string, *end_string;
     
    178185catch                   {KEYWORD_RETURN(CATCH);}        /* CFA */
    179186char                    {KEYWORD_RETURN(CHAR);}
    180 choose                  {KEYWORD_RETURN(CHOOSE);}
     187choose                  {KEYWORD_RETURN(CHOOSE);}       /* CFA */
    181188_Complex                {KEYWORD_RETURN(COMPLEX);}      /* ANSI99 */
    182189__complex               {KEYWORD_RETURN(COMPLEX);}      /* GCC */
     
    185192__const                 {KEYWORD_RETURN(CONST);}        /* GCC */
    186193__const__               {KEYWORD_RETURN(CONST);}        /* GCC */
    187 context                 {KEYWORD_RETURN(CONTEXT);}
     194context                 {KEYWORD_RETURN(CONTEXT);}      /* CFA */
    188195continue                {KEYWORD_RETURN(CONTINUE);}
    189196default                 {KEYWORD_RETURN(DEFAULT);}
    190197do                      {KEYWORD_RETURN(DO);}
    191198double                  {KEYWORD_RETURN(DOUBLE);}
    192 dtype                   {KEYWORD_RETURN(DTYPE);}
     199dtype                   {KEYWORD_RETURN(DTYPE);}        /* CFA */
    193200else                    {KEYWORD_RETURN(ELSE);}
    194201enum                    {KEYWORD_RETURN(ENUM);}
    195202__extension__           {KEYWORD_RETURN(EXTENSION);}    /* GCC */
    196203extern                  {KEYWORD_RETURN(EXTERN);}
    197 fallthru                {KEYWORD_RETURN(FALLTHRU);}
     204fallthru                {KEYWORD_RETURN(FALLTHRU);}     /* CFA */
    198205finally                 {KEYWORD_RETURN(FINALLY);}      /* CFA */
    199206float                   {KEYWORD_RETURN(FLOAT);}
    200207for                     {KEYWORD_RETURN(FOR);}
    201 forall                  {KEYWORD_RETURN(FORALL);}
     208forall                  {KEYWORD_RETURN(FORALL);}       /* CFA */
    202209fortran                 {KEYWORD_RETURN(FORTRAN);}
    203 ftype                   {KEYWORD_RETURN(FTYPE);}
     210ftype                   {KEYWORD_RETURN(FTYPE);}        /* CFA */
    204211goto                    {KEYWORD_RETURN(GOTO);}
    205212if                      {KEYWORD_RETURN(IF);}
     
    213220__label__               {KEYWORD_RETURN(LABEL);}        /* GCC */
    214221long                    {KEYWORD_RETURN(LONG);}
    215 lvalue                  {KEYWORD_RETURN(LVALUE);}
     222lvalue                  {KEYWORD_RETURN(LVALUE);}       /* CFA */
    216223register                {KEYWORD_RETURN(REGISTER);}
    217224restrict                {KEYWORD_RETURN(RESTRICT);}     /* ANSI99 */
     
    229236throw                   {KEYWORD_RETURN(THROW);}        /* CFA */
    230237try                     {KEYWORD_RETURN(TRY);}          /* CFA */
    231 type                    {KEYWORD_RETURN(TYPE);}
     238type                    {KEYWORD_RETURN(TYPE);}         /* CFA */
    232239typedef                 {KEYWORD_RETURN(TYPEDEF);}
    233240typeof                  {KEYWORD_RETURN(TYPEOF);}       /* GCC */
     
    245252{identifier}            {IDENTIFIER_RETURN();}
    246253{attr_identifier}       {ATTRIBUTE_RETURN();}
     254"`"                     {BEGIN QUOTED;}
     255<QUOTED>{identifier}    {IDENTIFIER_RETURN();}
     256<QUOTED>"`"             {BEGIN 0;}
    247257
    248258        /* numeric constants */
     
    257267        /* character constant, allows empty value */
    258268"L"?[']([^'\\\n]|{escape_seq})*['] {RETURN_VAL(CHARACTERconstant);}
     269        /* ' stop highlighting */
    259270
    260271        /* string constant */
    261272"L"?["]([^"\\\n]|{escape_seq})*["] {RETURN_VAL(STRINGliteral);}
     273        /* " stop highlighting */
    262274
    263275        /* punctuation */
     
    367379
    368380
    369 /* Local Variables: */
    370 /* fill-column: 100 */
    371 /* compile-command: "gmake" */
    372 /* End: */
     381// Local Variables:
     382// fill-column: 100
     383// compile-command: "make"
     384// End:
Note: See TracChangeset for help on using the changeset viewer.