Changeset 8c17ab0 for translator/Parser
- Timestamp:
- Nov 13, 2014, 3:09:54 PM (11 years ago)
- 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
- Location:
- translator/Parser
- Files:
-
- 4 edited
-
DeclarationNode.cc (modified) (24 diffs)
-
TypedefTable.cc (modified) (6 diffs)
-
cfa.y (modified) (2 diffs)
-
lex.l (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
translator/Parser/DeclarationNode.cc
r134b86a r8c17ab0 112 112 } 113 113 114 /* static class method */115 114 DeclarationNode * 116 115 DeclarationNode::newFunction( std::string* name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle ) … … 136 135 } 137 136 138 /* static class method */139 137 DeclarationNode * 140 138 DeclarationNode::newQualifier( Qualifier q ) … … 146 144 } 147 145 148 /* static class method */149 146 DeclarationNode * 150 147 DeclarationNode::newStorageClass( StorageClass sc ) … … 155 152 } 156 153 157 /* static class method */158 154 DeclarationNode * 159 155 DeclarationNode::newBasicType( BasicType bt ) … … 165 161 } 166 162 167 /* static class method */168 163 DeclarationNode * 169 164 DeclarationNode::newModifier( Modifier mod ) … … 175 170 } 176 171 177 /* static class method */178 172 DeclarationNode * 179 173 DeclarationNode::newForall( DeclarationNode* forall ) … … 185 179 } 186 180 187 /* static class method */188 181 DeclarationNode * 189 182 DeclarationNode::newFromTypedef( std::string* name ) … … 197 190 } 198 191 199 /* static class method */200 192 DeclarationNode * 201 193 DeclarationNode::newAggregate( TyCon kind, std::string* name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields ) … … 214 206 } 215 207 216 /* static class method */217 208 DeclarationNode * 218 209 DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) … … 229 220 } 230 221 231 /* static class method */232 222 DeclarationNode * 233 223 DeclarationNode::newEnumConstant( std::string* name, ExpressionNode *constant ) … … 239 229 } 240 230 241 /* static class method */242 231 DeclarationNode * 243 232 DeclarationNode::newName( std::string* name ) … … 248 237 } 249 238 250 /* static class method */251 239 DeclarationNode * 252 240 DeclarationNode::newFromTypeGen( std::string* name, ExpressionNode *params ) … … 260 248 } 261 249 262 /* static class method */263 250 DeclarationNode * 264 251 DeclarationNode::newTypeParam( TypeClass tc, std::string* name ) … … 272 259 } 273 260 274 /* static class method */275 261 DeclarationNode * 276 262 DeclarationNode::newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) … … 285 271 } 286 272 287 /* static class method */288 273 DeclarationNode * 289 274 DeclarationNode::newContextUse( std::string *name, ExpressionNode *params ) … … 298 283 } 299 284 300 /* static class method */301 285 DeclarationNode * 302 286 DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) … … 311 295 } 312 296 313 /* static class method */314 297 DeclarationNode * 315 298 DeclarationNode::newPointer( DeclarationNode *qualifiers ) … … 320 303 } 321 304 322 /* static class method */323 305 DeclarationNode * 324 306 DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) … … 332 314 } 333 315 334 /* static class method */335 316 DeclarationNode * 336 317 DeclarationNode::newVarArray( DeclarationNode *qualifiers ) … … 344 325 } 345 326 346 /* static class method */347 327 DeclarationNode * 348 328 DeclarationNode::newBitfield( ExpressionNode *size ) … … 353 333 } 354 334 355 /* static class method */356 335 DeclarationNode * 357 336 DeclarationNode::newTuple( DeclarationNode *members ) … … 363 342 } 364 343 365 /* static class method */366 344 DeclarationNode * 367 345 DeclarationNode::newTypeof( ExpressionNode *expr ) … … 373 351 } 374 352 375 /* static class method */376 353 DeclarationNode * 377 354 DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) … … 384 361 } 385 362 386 /* static class method */387 363 DeclarationNode * 388 364 DeclarationNode::newAttr( std::string *name, DeclarationNode *type ) -
translator/Parser/TypedefTable.cc
r134b86a r8c17ab0 1 /*2 * This file is part of the Cforall project3 *4 * $Id: TypedefTable.cc,v 1.7 2004/09/14 17:21:12 rcbilson Exp $5 *6 */7 8 1 #include <map> 9 2 #include <list> … … 19 12 #endif 20 13 21 TypedefTable::TypedefTable() 22 : currentScope(0) 23 { 24 } 14 TypedefTable::TypedefTable() : currentScope(0) {} 25 15 26 bool 27 TypedefTable::isKind(string identifier, kind_t kind) const 28 { 16 bool TypedefTable::isKind(string identifier, kind_t kind) const { 29 17 tableType::const_iterator id_pos = table.find(identifier); 30 18 if (id_pos == table.end()) { … … 35 23 } 36 24 37 bool 38 TypedefTable::isIdentifier(string identifier) const 39 { 25 bool TypedefTable::isIdentifier(string identifier) const { 40 26 return isKind(identifier, ID); 41 27 } 42 28 43 bool 44 TypedefTable::isTypedef(string identifier) const 45 { 29 bool TypedefTable::isTypedef(string identifier) const { 46 30 return isKind(identifier, TD); 47 31 } 48 32 49 bool 50 TypedefTable::isTypegen(string identifier) const 51 { 33 bool TypedefTable::isTypegen(string identifier) const { 52 34 return isKind(identifier, TG); 53 35 } 54 36 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; 37 void 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 ); 69 41 } 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 } 75 56 } 76 }77 57 } 78 58 79 void 80 TypedefTable::addToCurrentScope(const std::string &identifier, kind_t kind) 81 { 82 addToScope( identifier, kind, currentScope ); 59 void TypedefTable::addToCurrentScope(const std::string &identifier, kind_t kind) { 60 addToScope( identifier, kind, currentScope ); 83 61 } 84 62 85 void 86 TypedefTable::addToCurrentScope(kind_t kind) 87 { 88 addToCurrentScope( nextIdentifiers.top(), kind ); 63 void TypedefTable::addToCurrentScope(kind_t kind) { 64 addToCurrentScope( nextIdentifiers.top(), kind ); 89 65 } 90 66 91 void 92 TypedefTable::addToEnclosingScope(const std::string &identifier, kind_t kind) 93 { 94 assert( currentScope >= 1 ); 95 addToScope( identifier, kind, currentScope - 1 ); 67 void TypedefTable::addToEnclosingScope(const std::string &identifier, kind_t kind) { 68 assert( currentScope >= 1 ); 69 addToScope( identifier, kind, currentScope - 1 ); 96 70 } 97 71 98 void 99 TypedefTable::addToEnclosingScope(kind_t kind) 100 { 101 addToEnclosingScope( nextIdentifiers.top(), kind ); 72 void TypedefTable::addToEnclosingScope(kind_t kind) { 73 addToEnclosingScope( nextIdentifiers.top(), kind ); 102 74 } 103 75 104 void 105 TypedefTable::addToEnclosingScope2(const std::string &identifier, kind_t kind) 106 { 107 assert( currentScope >= 2 ); 108 addToScope( identifier, kind, currentScope - 2 ); 76 void TypedefTable::addToEnclosingScope2(const std::string &identifier, kind_t kind) { 77 assert( currentScope >= 2 ); 78 addToScope( identifier, kind, currentScope - 2 ); 109 79 } 110 80 111 void 112 TypedefTable::addToEnclosingScope2(kind_t kind) 113 { 114 addToEnclosingScope2( nextIdentifiers.top(), kind ); 81 void TypedefTable::addToEnclosingScope2(kind_t kind) { 82 addToEnclosingScope2( nextIdentifiers.top(), kind ); 115 83 } 116 84 117 void 118 TypedefTable::setNextIdentifier( const std::string &identifier ) 119 { 120 nextIdentifiers.top() = identifier; 85 void TypedefTable::setNextIdentifier( const std::string &identifier ) { 86 nextIdentifiers.top() = identifier; 121 87 } 122 88 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 ); 89 void 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 } 131 96 } 132 }133 97 } 134 98 135 void 136 TypedefTable::enterScope(void) 137 { 99 void TypedefTable::enterScope(void) { 138 100 currentScope += 1; 139 101 deferListStack.push( deferListType() ); … … 142 104 } 143 105 144 void 145 TypedefTable::leaveScope(void) 146 { 106 void TypedefTable::leaveScope(void) { 147 107 debugPrint( "Leaving scope " << currentScope << endl ); 148 108 for (tableType::iterator i = table.begin(); i != table.end(); i++) { … … 151 111 declList.pop_front(); 152 112 } 153 if ( declList.empty() ) {154 table.erase( i );113 if ( declList.empty() ) { 114 table.erase( i ); 155 115 } 156 116 } 157 117 currentScope -= 1; 158 118 for (deferListType::iterator i = deferListStack.top().begin(); i != deferListStack.top().end(); i++) { 159 addToCurrentScope( i->identifier, i->kind );119 addToCurrentScope( i->identifier, i->kind ); 160 120 } 161 121 deferListStack.pop(); … … 164 124 } 165 125 166 void 167 TypedefTable::enterContext( std::string contextName ) 168 { 169 currentContext = contextName; 170 contextScope = currentScope; 126 void TypedefTable::enterContext( std::string contextName ) { 127 currentContext = contextName; 128 contextScope = currentScope; 171 129 } 172 130 173 void 174 TypedefTable::leaveContext(void) 175 { 176 currentContext = ""; 131 void TypedefTable::leaveContext(void) { 132 currentContext = ""; 177 133 } 178 134 179 void 180 TypedefTable::print(void) const 181 { 135 void TypedefTable::print(void) const { 182 136 for (tableType::const_iterator i = table.begin(); i != table.end(); i++) { 183 137 debugPrint( (*i).first << ": " ); -
translator/Parser/cfa.y
r134b86a r8c17ab0 10 10 * Created On : Sat Sep 1 20:22:55 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Mon Nov 3 16:24:24201413 * Update Count : 88 012 * Last Modified On : Sun Nov 9 22:45:42 2014 13 * Update Count : 881 14 14 */ 15 15 … … 84 84 85 85 /* names and constants: lexer differentiates between identifier and typedef names */ 86 %token<tok> IDENTIFIER TYPEDEFname TYPEGENname86 %token<tok> IDENTIFIER QUOTED_IDENTIFIER TYPEDEFname TYPEGENname 87 87 %token<tok> ATTR_IDENTIFIER ATTR_TYPEDEFname ATTR_TYPEGENname 88 88 %token<tok> INTEGERconstant FLOATINGconstant CHARACTERconstant STRINGliteral -
translator/Parser/lex.l
r134b86a r8c17ab0 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Sat Nov 1 18:09:47 200313 * Update Count : 19712 * Last Modified On : Tue Nov 11 08:10:05 2014 13 * Update Count : 215 14 14 */ 15 15 … … 17 17 18 18 %{ 19 / *This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor20 directive have been performed and removed from the source. The only exceptions are preprocessor21 directives passed to the compiler (e.g., line-number directives) and C/C++ style comments, which22 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 **************************** 25 25 26 26 #include <string> … … 28 28 #include "lex.h" 29 29 #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 31 31 32 32 char *yyfilename; 33 33 34 #define WHITE_RETURN(x) /* do nothing */34 #define WHITE_RETURN(x) // do nothing 35 35 #define NEWLINE_RETURN() WHITE_RETURN('\n') 36 36 #define RETURN_VAL(x) yylval.tok.str = new std::string(yytext); \ … … 39 39 return(x) 40 40 41 #define KEYWORD_RETURN(x) RETURN_VAL(x) / * keyword */41 #define KEYWORD_RETURN(x) RETURN_VAL(x) // keyword 42 42 #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 51 void rm_underscore() { // remove underscores in constant or escape sequence 51 52 int j = 0; 52 53 for ( int i = 0; i < yyleng; i += 1 ) { … … 68 69 universal_char "\\"((u{hex_quad})|(U{hex_quad}{2})) 69 70 70 / * identifier, GCC: $ in identifier */71 // identifier, GCC: $ in identifier 71 72 identifier ([a-zA-Z_$]|{universal_char})([0-9a-zA-Z_$]|{universal_char})* 72 73 73 /* attribute identifier, GCC: $ in identifier */ 74 // quoted identifier 75 quoted_identifier "`"{identifier}"`" 76 77 // attribute identifier, GCC: $ in identifier 74 78 attr_identifier "@"{identifier} 75 79 76 / * numeric constants, CFA: '_' in constant */80 // numeric constants, CFA: '_' in constant 77 81 hex_quad {hex}{4} 78 82 integer_suffix "_"?(([uU][lL]?)|([uU]("ll"|"LL")?)|([lL][uU]?)|("ll"|"LL")[uU]?) … … 99 103 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix}? 100 104 101 / * character escape sequence, GCC: \e => esc character */105 // character escape sequence, GCC: \e => esc character 102 106 simple_escape "\\"[abefnrtv'"?\\] 107 // ' stop highlighting 103 108 octal_escape "\\"{octal}{1,3} 104 109 hex_escape "\\""x"{hex}+ 105 110 escape_seq {simple_escape}|{octal_escape}|{hex_escape}|{universal_char} 106 111 107 / * display/white-space characters */112 // display/white-space characters 108 113 h_tab [\011] 109 114 form_feed [\014] … … 112 117 h_white [ ]|{h_tab} 113 118 114 / * operators */119 // operators 115 120 op_unary_only "~"|"!" 116 121 op_unary_binary "+"|"-"|"*" … … 124 129 125 130 %x COMMENT 131 %x QUOTED 126 132 127 133 %% 128 134 /* line directives */ 129 135 ^{h_white}*"#"{h_white}*[0-9]+{h_white}*["][^"\n]+["][^\n]*"\n" { 136 /* " stop highlighting */ 130 137 char *end_num; 131 138 char *begin_string, *end_string; … … 178 185 catch {KEYWORD_RETURN(CATCH);} /* CFA */ 179 186 char {KEYWORD_RETURN(CHAR);} 180 choose {KEYWORD_RETURN(CHOOSE);} 187 choose {KEYWORD_RETURN(CHOOSE);} /* CFA */ 181 188 _Complex {KEYWORD_RETURN(COMPLEX);} /* ANSI99 */ 182 189 __complex {KEYWORD_RETURN(COMPLEX);} /* GCC */ … … 185 192 __const {KEYWORD_RETURN(CONST);} /* GCC */ 186 193 __const__ {KEYWORD_RETURN(CONST);} /* GCC */ 187 context {KEYWORD_RETURN(CONTEXT);} 194 context {KEYWORD_RETURN(CONTEXT);} /* CFA */ 188 195 continue {KEYWORD_RETURN(CONTINUE);} 189 196 default {KEYWORD_RETURN(DEFAULT);} 190 197 do {KEYWORD_RETURN(DO);} 191 198 double {KEYWORD_RETURN(DOUBLE);} 192 dtype {KEYWORD_RETURN(DTYPE);} 199 dtype {KEYWORD_RETURN(DTYPE);} /* CFA */ 193 200 else {KEYWORD_RETURN(ELSE);} 194 201 enum {KEYWORD_RETURN(ENUM);} 195 202 __extension__ {KEYWORD_RETURN(EXTENSION);} /* GCC */ 196 203 extern {KEYWORD_RETURN(EXTERN);} 197 fallthru {KEYWORD_RETURN(FALLTHRU);} 204 fallthru {KEYWORD_RETURN(FALLTHRU);} /* CFA */ 198 205 finally {KEYWORD_RETURN(FINALLY);} /* CFA */ 199 206 float {KEYWORD_RETURN(FLOAT);} 200 207 for {KEYWORD_RETURN(FOR);} 201 forall {KEYWORD_RETURN(FORALL);} 208 forall {KEYWORD_RETURN(FORALL);} /* CFA */ 202 209 fortran {KEYWORD_RETURN(FORTRAN);} 203 ftype {KEYWORD_RETURN(FTYPE);} 210 ftype {KEYWORD_RETURN(FTYPE);} /* CFA */ 204 211 goto {KEYWORD_RETURN(GOTO);} 205 212 if {KEYWORD_RETURN(IF);} … … 213 220 __label__ {KEYWORD_RETURN(LABEL);} /* GCC */ 214 221 long {KEYWORD_RETURN(LONG);} 215 lvalue {KEYWORD_RETURN(LVALUE);} 222 lvalue {KEYWORD_RETURN(LVALUE);} /* CFA */ 216 223 register {KEYWORD_RETURN(REGISTER);} 217 224 restrict {KEYWORD_RETURN(RESTRICT);} /* ANSI99 */ … … 229 236 throw {KEYWORD_RETURN(THROW);} /* CFA */ 230 237 try {KEYWORD_RETURN(TRY);} /* CFA */ 231 type {KEYWORD_RETURN(TYPE);} 238 type {KEYWORD_RETURN(TYPE);} /* CFA */ 232 239 typedef {KEYWORD_RETURN(TYPEDEF);} 233 240 typeof {KEYWORD_RETURN(TYPEOF);} /* GCC */ … … 245 252 {identifier} {IDENTIFIER_RETURN();} 246 253 {attr_identifier} {ATTRIBUTE_RETURN();} 254 "`" {BEGIN QUOTED;} 255 <QUOTED>{identifier} {IDENTIFIER_RETURN();} 256 <QUOTED>"`" {BEGIN 0;} 247 257 248 258 /* numeric constants */ … … 257 267 /* character constant, allows empty value */ 258 268 "L"?[']([^'\\\n]|{escape_seq})*['] {RETURN_VAL(CHARACTERconstant);} 269 /* ' stop highlighting */ 259 270 260 271 /* string constant */ 261 272 "L"?["]([^"\\\n]|{escape_seq})*["] {RETURN_VAL(STRINGliteral);} 273 /* " stop highlighting */ 262 274 263 275 /* punctuation */ … … 367 379 368 380 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.