Changeset 235b41f
- Timestamp:
- Sep 5, 2017, 3:41:04 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, 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:
- 416cc86
- Parents:
- 800d275 (diff), 3f8dd01 (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. - Files:
-
- 4 added
- 52 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/LaTeXmacros/lstlang.sty
r800d275 r235b41f 8 8 %% Created On : Sat May 13 16:34:42 2017 9 9 %% Last Modified By : Peter A. Buhr 10 %% Last Modified On : Mon Jul 24 20:40:37201711 %% Update Count : 1 310 %% Last Modified On : Wed Aug 30 22:11:14 2017 11 %% Update Count : 14 12 12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 13 … … 112 112 finally, forall, ftype, _Generic, _Imaginary, inline, __label__, lvalue, _Noreturn, one_t, 113 113 otype, restrict, _Static_assert, throw, throwResume, trait, try, ttype, typeof, __typeof, 114 __typeof__, virtual, w ith, zero_t},114 __typeof__, virtual, waitfor, when, with, zero_t}, 115 115 morekeywords=[2]{ 116 116 _Atomic, coroutine, is_coroutine, is_monitor, is_thread, monitor, mutex, nomutex, -
doc/refrat/keywords.tex
r800d275 r235b41f 11 11 %% Created On : Sun Aug 6 08:17:27 2017 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sun Aug 6 08:31:42201714 %% Update Count : 413 %% Last Modified On : Wed Aug 30 22:10:10 2017 14 %% Update Count : 5 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 \begin{tabular}{@{}llllll@{}} … … 52 52 ©ttype© \\ 53 53 ©virtual© \\ 54 ©w ith©\\54 ©waitfor© \\ 55 55 \end{tabular} 56 56 & 57 57 \begin{tabular}{@{}l@{}} 58 ©when© \\ 59 ©with© \\ 58 60 ©zero_t© \\ 59 \\60 \\61 61 \\ 62 62 \\ -
src/CodeGen/CodeGenerator.cc
r800d275 r235b41f 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Aug 18 15:34:00201713 // Update Count : 4 8811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 20:42:52 2017 13 // Update Count : 490 14 14 // 15 15 #include "CodeGenerator.h" … … 59 59 60 60 void CodeGenerator::asmName( DeclarationWithType * decl ) { 61 if ( ConstantExpr * asmName = d ecl->get_asmName() ) {61 if ( ConstantExpr * asmName = dynamic_cast<ConstantExpr *>(decl->get_asmName()) ) { 62 62 output << " asm ( " << asmName->get_constant()->get_value() << " )"; 63 63 } // if … … 195 195 } 196 196 197 output << kind; 198 if ( aggDecl->get_name() != "" ) 199 output << aggDecl->get_name(); 197 output << kind << aggDecl->get_name(); 200 198 201 199 if ( aggDecl->has_body() ) { … … 233 231 genAttributes( enumDecl->get_attributes() ); 234 232 235 if ( enumDecl->get_name() != "" ) 236 output << enumDecl->get_name(); 233 output << enumDecl->get_name(); 237 234 238 235 std::list< Declaration* > &memb = enumDecl->get_members(); … … 260 257 } 261 258 262 void CodeGenerator::visit( __attribute__((unused)) TraitDecl * traitDecl ) {} 259 void CodeGenerator::visit( TraitDecl * traitDecl ) { 260 assertf( ! genC, "TraitDecl nodes should not reach code generation." ); 261 extension( traitDecl ); 262 handleAggregate( traitDecl, "trait " ); 263 } 263 264 264 265 void CodeGenerator::visit( TypedefDecl * typeDecl ) { … … 545 546 extension( addressExpr ); 546 547 output << "(&"; 547 // this hack makes sure that we don't convert "constant_zero" to "0" if we're taking its address 548 if ( VariableExpr * variableExpr = dynamic_cast< VariableExpr* >( addressExpr->get_arg() ) ) { 549 output << mangleName( variableExpr->get_var() ); 550 } else { 551 addressExpr->get_arg()->accept( *this ); 552 } // if 548 addressExpr->arg->accept( *this ); 553 549 output << ")"; 550 } 551 552 void CodeGenerator::visit( LabelAddressExpr *addressExpr ) { 553 extension( addressExpr ); 554 output << "(&&" << addressExpr->arg << ")"; 554 555 } 555 556 … … 760 761 for ( Statement * stmt : stmts ) { 761 762 updateLocation( stmt ); 762 output << printLabels( stmt->get_labels() );763 output << indent << printLabels( stmt->get_labels() ); 763 764 if ( i+1 == numStmts ) { 764 765 // last statement in a statement expression needs to be handled specially - -
src/CodeGen/CodeGenerator.h
r800d275 r235b41f 59 59 virtual void visit( NameExpr *nameExpr ); 60 60 virtual void visit( AddressExpr *addressExpr ); 61 virtual void visit( LabelAddressExpr *addressExpr ); 61 62 virtual void visit( CastExpr *castExpr ); 62 63 virtual void visit( VirtualCastExpr *castExpr ); -
src/CodeGen/Generate.cc
r800d275 r235b41f 21 21 #include "CodeGenerator.h" // for CodeGenerator, doSemicolon, oper... 22 22 #include "GenType.h" // for genPrettyType 23 #include "Common/PassVisitor.h" // for PassVisitor 23 24 #include "Parser/LinkageSpec.h" // for isBuiltin, isGeneratable 24 25 #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode … … 29 30 30 31 namespace CodeGen { 32 namespace { 33 /// Removes misc. nodes that should not exist in CodeGen 34 struct TreeCleaner { 35 void visit( CompoundStmt * stmt ); 36 37 static bool shouldClean( Declaration * ); 38 }; 39 40 void cleanTree( std::list< Declaration * > & translationUnit ) { 41 PassVisitor<TreeCleaner> cleaner; 42 filter( translationUnit, [](Declaration * decl) { return TreeCleaner::shouldClean(decl); }, false ); 43 acceptAll( translationUnit, cleaner ); 44 } // cleanTree 45 } // namespace 46 31 47 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks ) { 48 cleanTree( translationUnit ); 49 32 50 CodeGen::CodeGenerator cgv( os, pretty, generateC, lineMarks ); 33 51 for ( auto & dcl : translationUnit ) { … … 52 70 os << std::endl; 53 71 } 72 73 namespace { 74 void TreeCleaner::visit( CompoundStmt * cstmt ) { 75 filter( cstmt->kids, [](Statement * stmt) { 76 if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( stmt ) ) { 77 return shouldClean( declStmt->decl ); 78 } 79 return false; 80 }, false ); 81 } 82 83 bool TreeCleaner::shouldClean( Declaration * decl ) { 84 return dynamic_cast< TraitDecl * >( decl ); 85 } 86 } // namespace 54 87 } // namespace CodeGen 55 88 -
src/CodeGen/OperatorTable.cc
r800d275 r235b41f 19 19 20 20 #include "OperatorTable.h" 21 #include "Common/utility.h" 21 22 22 23 namespace CodeGen { … … 65 66 { "?^=?", "^=", "_operator_bitxorassign", OT_INFIXASSIGN }, 66 67 { "?|=?", "|=", "_operator_bitorassign", OT_INFIXASSIGN }, 67 { "&&", "&&", "&&", OT_LABELADDRESS },68 { "0", "0", "_constant_zero", OT_CONSTANT },69 { "1", "1", "_constant_one", OT_CONSTANT }70 68 }; 71 69 … … 86 84 initialize(); 87 85 } // if 86 88 87 std::map< std::string, OperatorInfo >::const_iterator i = table.find( funcName ); 89 88 if ( i == table.end() ) { 89 if ( isPrefix( funcName, "?`" ) ) { 90 // handle literal suffixes, which are user-defined postfix operators 91 info.inputName = funcName; 92 info.symbol = funcName.substr(2); 93 info.outputName = toString( "__operator_literal_", info.symbol ); 94 info.type = OT_POSTFIX; 95 return true; 96 } 90 97 return false; 91 98 } else { -
src/Common/SemanticError.cc
r800d275 r235b41f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:21:25 201513 // Update Count : 112 // Last Modified On : Tue Aug 29 18:17:35 2017 13 // Update Count : 3 14 14 // 15 15 16 #include <cstdio> 17 #include <unistd.h> 18 #include <iostream> 19 #include <list> 20 #include <string> 16 #include <cstdio> // for fileno, stderr 17 #include <unistd.h> // for isatty 18 #include <iostream> // for basic_ostream, operator<<, ostream 19 #include <list> // for list, _List_iterator 20 #include <string> // for string, operator<<, operator+, to_string 21 21 22 #include "Common/utility.h" 22 #include "Common/utility.h" // for to_string, CodeLocation (ptr only) 23 23 #include "SemanticError.h" 24 25 inline const std::string& error_str() {26 static std::string str = isatty( fileno(stderr) ) ? "\e[31merror:\e[39m " : "error: ";27 return str;28 }29 24 30 25 SemanticError::SemanticError() { … … 49 44 void SemanticError::print( std::ostream &os ) { 50 45 using std::to_string; 51 for( auto err : errors) {52 os << to_string( err.location ) << err.description << '\n';46 for( auto err : errors ) { 47 os << to_string( err.location ) << err.description << std::endl; 53 48 } 54 49 } -
src/Common/SemanticError.h
r800d275 r235b41f 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : T hr Aug 17 14:01:00201713 // Update Count : 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Aug 29 22:03:36 2017 13 // Update Count : 17 14 14 // 15 15 16 16 #pragma once 17 17 18 #include <exception> // for exception 19 #include <iostream> // for ostream 20 #include <list> // for list 21 #include <string> // for string 18 #include <exception> // for exception 19 #include <iostream> // for ostream 20 #include <list> // for list 21 #include <string> // for string 22 #include <unistd.h> // for isatty 22 23 23 #include "CodeLocation.h" 24 #include "CodeLocation.h" // for CodeLocation, toString 24 25 25 26 struct error { … … 28 29 29 30 error() = default; 30 error( const std::string & str ) : description( str ) {}31 error( const std::string & str ) : description( str ) {} 31 32 32 void maybeSet( const CodeLocation & location ) {33 void maybeSet( const CodeLocation & location ) { 33 34 if( this->location.linenumber < 0 ) { 34 35 this->location = location; … … 41 42 SemanticError(); 42 43 SemanticError( std::string error ); 43 template< typename T > SemanticError( const std::string & error, const T *obj );44 template< typename T > SemanticError( const std::string & error, const T * obj ); 44 45 ~SemanticError() throw() {} 45 46 46 void append( SemanticError &other ); 47 static inline const std::string & error_str() { 48 static std::string str = isatty( STDERR_FILENO ) ? "\e[31merror:\e[39m " : "error: "; 49 return str; 50 } 51 52 void append( SemanticError & other ); 47 53 void append( const std::string & ); 48 54 bool isEmpty() const; 49 void print( std::ostream & os );55 void print( std::ostream & os ); 50 56 51 void set_location( const CodeLocation & location );52 // constructs an exception using the given message and the printed 53 // representation of the obj (T must have a printmethod)57 void set_location( const CodeLocation & location ); 58 // constructs an exception using the given message and the printed representation of the obj (T must have a print 59 // method) 54 60 private: 55 61 std::list< error > errors; … … 57 63 58 64 template< typename T > 59 SemanticError::SemanticError( const std::string & error, const T *obj ) {65 SemanticError::SemanticError( const std::string & error, const T * obj ) { 60 66 append( toString( error, obj ) ); 61 67 } -
src/Common/utility.h
r800d275 r235b41f 174 174 } 175 175 176 template <typename E, typename UnaryPredicate, template< typename, typename...> class Container, typename... Args > 177 void filter( Container< E *, Args... > & container, UnaryPredicate pred, bool doDelete ) { 178 auto i = begin( container ); 179 while ( i != end( container ) ) { 180 auto it = next( i ); 181 if ( pred( *i ) ) { 182 if ( doDelete ) { 183 delete *i; 184 } // if 185 container.erase( i ); 186 } // if 187 i = it; 188 } // while 189 } 190 176 191 template< typename... Args > 177 192 auto zip(Args&&... args) -> decltype(zipWith(std::forward<Args>(args)..., std::make_pair)) { … … 207 222 std::cerr << "Warning: "; 208 223 warn_single( params... ); 224 } 225 226 /// determines if `pref` is a prefix of `str` 227 static inline bool isPrefix( const std::string & str, const std::string & pref ) { 228 if ( pref.size() > str.size() ) return false; 229 auto its = std::mismatch( pref.begin(), pref.end(), str.begin() ); 230 return its.first == pref.end(); 209 231 } 210 232 -
src/GenPoly/Box.cc
r800d275 r235b41f 141 141 virtual StructDecl *mutate( StructDecl *structDecl ) override; 142 142 virtual UnionDecl *mutate( UnionDecl *unionDecl ) override; 143 virtual TraitDecl *mutate( TraitDecl *unionDecl ) override; 143 144 virtual TypeDecl *mutate( TypeDecl *typeDecl ) override; 144 145 virtual TypedefDecl *mutate( TypedefDecl *typedefDecl ) override; … … 216 217 private: 217 218 }; 218 219 219 } // anonymous namespace 220 220 … … 896 896 addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars ); 897 897 bodyStmt = new ExprStmt( noLabels, adapteeApp ); 898 // } else if ( isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {899 898 } else if ( isDynType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) { 900 899 // return type T … … 1299 1298 } 1300 1299 1301 /// determines if `pref` is a prefix of `str`1302 bool isPrefix( const std::string & str, const std::string & pref ) {1303 if ( pref.size() > str.size() ) return false;1304 auto its = std::mismatch( pref.begin(), pref.end(), str.begin() );1305 return its.first == pref.end();1306 }1307 1308 1300 DeclarationWithType * Pass2::mutate( FunctionDecl *functionDecl ) { 1309 1301 functionDecl = safe_dynamic_cast< FunctionDecl * > ( handleDecl( functionDecl ) ); … … 1352 1344 } 1353 1345 1346 TraitDecl * Pass2::mutate( TraitDecl *aggDecl ) { 1347 return handleAggDecl( aggDecl ); 1348 } 1349 1354 1350 TypeDecl * Pass2::mutate( TypeDecl *typeDecl ) { 1355 1351 addToTyVarMap( typeDecl, scopeTyVars ); … … 1377 1373 Type *Pass2::mutate( FunctionType *funcType ) { 1378 1374 scopeTyVars.beginScope(); 1375 1379 1376 makeTyVarMap( funcType, scopeTyVars ); 1380 1377 … … 1550 1547 // (alloca was previously used, but can't be safely used in loops) 1551 1548 Type *declType = objectDecl->get_type(); 1552 std::string bufName = bufNamer.newName(); 1553 ObjectDecl *newBuf = new ObjectDecl( bufName, Type::StorageClasses(), LinkageSpec::C, 0, 1549 ObjectDecl *newBuf = new ObjectDecl( bufNamer.newName(), Type::StorageClasses(), LinkageSpec::C, 0, 1554 1550 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Kind::Char), new NameExpr( sizeofName( mangleType(declType) ) ), 1555 true, false, std::list<Attribute*>{ new Attribute( std::string{"aligned"}, std::list<Expression*>{ new ConstantExpr( Constant::from_int(8) ) } ) } ), 0 );1551 true, false, std::list<Attribute*>{ new Attribute( "aligned", std::list<Expression*>{ new ConstantExpr( Constant::from_int(8) ) } ) } ), 0 ); 1556 1552 stmtsToAdd.push_back( new DeclStmt( noLabels, newBuf ) ); 1557 1553 1558 1554 delete objectDecl->get_init(); 1559 1560 objectDecl->set_init( new SingleInit( new NameExpr( bufName ) ) ); 1555 objectDecl->set_init( new SingleInit( new VariableExpr( newBuf ) ) ); 1561 1556 } 1562 1557 } -
src/GenPoly/GenPoly.cc
r800d275 r235b41f 336 336 assertf(bparam, "Aggregate parameters should be type expressions"); 337 337 338 // xxx - might need to let VoidType be a wildcard here too; could have some voids 338 // xxx - might need to let VoidType be a wildcard here too; could have some voids 339 339 // stuffed in for dtype-statics. 340 340 // if ( is<VoidType>( aparam->get_type() ) || is<VoidType>( bparam->get_type() ) ) continue; 341 341 if ( ! typesPolyCompatible( aparam->get_type(), bparam->get_type() ) ) return false; 342 342 } 343 343 344 344 return true; 345 345 } … … 350 350 // polymorphic types always match 351 351 if ( aid == type_index{typeid(TypeInstType)} ) return true; 352 352 353 353 type_index bid{ typeid(*b) }; 354 354 // polymorphic types always match 355 355 if ( bid == type_index{typeid(TypeInstType)} ) return true; 356 356 357 357 // can't match otherwise if different types 358 358 if ( aid != bid ) return false; … … 377 377 ConstantExpr *ad = dynamic_cast<ConstantExpr*>( aa->get_dimension() ); 378 378 ConstantExpr *bd = dynamic_cast<ConstantExpr*>( ba->get_dimension() ); 379 if ( ad && bd 379 if ( ad && bd 380 380 && ad->get_constant()->get_value() != bd->get_constant()->get_value() ) 381 381 return false; … … 433 433 434 434 void addToTyVarMap( TypeDecl * tyVar, TyVarMap &tyVarMap ) { 435 // xxx - should this actually be insert? 435 436 tyVarMap[ tyVar->get_name() ] = TypeDecl::Data{ tyVar }; 436 437 } -
src/InitTweak/FixInit.cc
r800d275 r235b41f 127 127 128 128 // don't go into other functions 129 virtual void visit( __attribute__((unused)) FunctionDecl *decl) override {}129 virtual void visit( FunctionDecl * ) override {} 130 130 131 131 protected: … … 913 913 // of the error. See C++ Reference 6.6 Jump Statements for details. 914 914 void InsertDtors::handleGoto( BranchStmt * stmt ) { 915 assert( stmt->get_target() != "" && "BranchStmt missing a label" ); 915 // can't do anything for computed goto 916 if ( stmt->computedTarget ) return; 917 918 assertf( stmt->get_target() != "", "BranchStmt missing a label: %s", toString( stmt ).c_str() ); 916 919 // S_L = lvars = set of objects in scope at label definition 917 920 // S_G = curVars = set of objects in scope at goto statement -
src/InitTweak/InitTweak.cc
r800d275 r235b41f 497 497 using Visitor::visit; 498 498 499 virtual void visit( __attribute((unused)) ApplicationExpr *applicationExpr ) { isConstExpr = false; } 500 virtual void visit( __attribute((unused)) UntypedExpr *untypedExpr ) { isConstExpr = false; } 501 virtual void visit( NameExpr *nameExpr ) { 502 // xxx - temporary hack, because 0 and 1 really should be constexprs, even though they technically aren't in Cforall today 503 if ( nameExpr->get_name() != "0" && nameExpr->get_name() != "1" ) isConstExpr = false; 504 } 499 virtual void visit( ApplicationExpr * ) { isConstExpr = false; } 500 virtual void visit( UntypedExpr * ) { isConstExpr = false; } 501 virtual void visit( NameExpr * ) { isConstExpr = false; } 505 502 // virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 506 503 virtual void visit( AddressExpr *addressExpr ) { … … 509 506 if ( ! dynamic_cast< NameExpr * >( arg) && ! dynamic_cast< VariableExpr * >( arg ) && ! dynamic_cast< MemberExpr * >( arg ) && ! dynamic_cast< UntypedMemberExpr * >( arg ) ) isConstExpr = false; 510 507 } 511 virtual void visit( __attribute((unused)) LabelAddressExpr *labAddressExpr ) { isConstExpr = false; } 512 virtual void visit( __attribute((unused)) UntypedMemberExpr *memberExpr ) { isConstExpr = false; } 513 virtual void visit( __attribute((unused)) MemberExpr *memberExpr ) { isConstExpr = false; } 514 virtual void visit( __attribute((unused)) VariableExpr *variableExpr ) { isConstExpr = false; } 508 virtual void visit( UntypedMemberExpr * ) { isConstExpr = false; } 509 virtual void visit( MemberExpr * ) { isConstExpr = false; } 510 virtual void visit( VariableExpr * ) { isConstExpr = false; } 515 511 // these might be okay? 516 512 // virtual void visit( SizeofExpr *sizeofExpr ); … … 523 519 // virtual void visit( LogicalExpr *logicalExpr ); 524 520 // virtual void visit( ConditionalExpr *conditionalExpr ); 525 virtual void visit( __attribute((unused)) TypeExpr *typeExpr) { isConstExpr = false; }526 virtual void visit( __attribute((unused)) AsmExpr *asmExpr) { isConstExpr = false; }527 virtual void visit( __attribute((unused)) UntypedValofExpr *valofExpr) { isConstExpr = false; }528 virtual void visit( __attribute((unused)) CompoundLiteralExpr *compLitExpr) { isConstExpr = false; }529 virtual void visit( __attribute((unused)) UntypedTupleExpr *tupleExpr) { isConstExpr = false; }530 virtual void visit( __attribute((unused)) TupleExpr *tupleExpr) { isConstExpr = false; }531 virtual void visit( __attribute((unused)) TupleAssignExpr *tupleExpr) { isConstExpr = false; }521 virtual void visit( TypeExpr * ) { isConstExpr = false; } 522 virtual void visit( AsmExpr * ) { isConstExpr = false; } 523 virtual void visit( UntypedValofExpr * ) { isConstExpr = false; } 524 virtual void visit( CompoundLiteralExpr * ) { isConstExpr = false; } 525 virtual void visit( UntypedTupleExpr * ) { isConstExpr = false; } 526 virtual void visit( TupleExpr * ) { isConstExpr = false; } 527 virtual void visit( TupleAssignExpr * ) { isConstExpr = false; } 532 528 533 529 bool isConstExpr; -
src/Parser/ExpressionNode.cc
r800d275 r235b41f 7 7 // ExpressionNode.cc -- 8 8 // 9 // Author : Rodolfo G. Esteves9 // Author : Peter A. Buhr 10 10 // Created On : Sat May 16 13:17:07 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Aug 2 11:12:00201713 // Update Count : 56811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 22:21:21 2017 13 // Update Count : 639 14 14 // 15 15 … … 58 58 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 59 59 60 Expression * build_constantInteger( const std::string & str ) { 60 static void sepNumeric( string & str, string & units ) { 61 string::size_type posn = str.find_first_of( "`" ); 62 if ( posn != string::npos ) { 63 units = "?" + str.substr( posn ); // extract units 64 str.erase( posn ); // remove units 65 } // if 66 } // sepNumeric 67 68 Expression * build_constantInteger( string & str ) { 61 69 static const BasicType::Kind kind[2][3] = { 62 70 { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, 63 71 { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 64 72 }; 73 74 string units; // units 75 sepNumeric( str, units ); // separate constant from units 76 65 77 bool dec = true, Unsigned = false; // decimal, unsigned constant 66 78 int size; // 0 => int, 1 => long, 2 => long long … … 69 81 Expression * ret; 70 82 83 // ROB: what do we do with units on 0 and 1? 71 84 // special constants 72 85 if ( str == "0" ) { … … 134 147 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 135 148 CLEANUP: 149 if ( units.length() != 0 ) { 150 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 151 } // if 152 136 153 delete &str; // created by lex 137 154 return ret; 138 155 } // build_constantInteger 139 156 140 Expression * build_constantFloat( const std::string & str ) {157 Expression * build_constantFloat( string & str ) { 141 158 static const BasicType::Kind kind[2][3] = { 142 159 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, 143 160 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, 144 161 }; 162 163 string units; // units 164 sepNumeric( str, units ); // separate constant from units 145 165 146 166 bool complx = false; // real, complex … … 169 189 170 190 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) ); 191 if ( units.length() != 0 ) { 192 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 193 } // if 194 171 195 delete &str; // created by lex 172 196 return ret; 173 197 } // build_constantFloat 174 198 175 Expression * build_constantChar( const std::string & str ) { 199 static void sepString( string & str, string & units, char delimit ) { 200 string::size_type posn = str.find_last_of( delimit ) + 1; 201 if ( posn != str.length() ) { 202 units = "?" + str.substr( posn ); // extract units 203 str.erase( posn ); // remove units 204 } // if 205 } // sepString 206 207 Expression * build_constantChar( string & str ) { 208 string units; // units 209 sepString( str, units, '\'' ); // separate constant from units 210 176 211 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) ); 212 if ( units.length() != 0 ) { 213 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 214 } // if 215 177 216 delete &str; // created by lex 178 217 return ret; 179 218 } // build_constantChar 180 219 181 ConstantExpr * build_constantStr( const std::string & str ) { 182 // string should probably be a primitive type 183 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), 184 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 185 false, false ); 186 ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 220 Expression * build_constantStr( string & str ) { 221 string units; // units 222 sepString( str, units, '"' ); // separate constant from units 223 224 BasicType::Kind strtype = BasicType::Char; // default string type 225 switch ( str[0] ) { // str has >= 2 characters, i.e, null string "" 226 case 'u': 227 if ( str[1] == '8' ) break; // utf-8 characters 228 strtype = BasicType::ShortUnsignedInt; 229 break; 230 case 'U': 231 strtype = BasicType::UnsignedInt; 232 break; 233 case 'L': 234 strtype = BasicType::SignedInt; 235 break; 236 } // switch 237 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), strtype ), 238 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 239 false, false ); 240 Expression * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 241 if ( units.length() != 0 ) { 242 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 243 } // if 244 187 245 delete &str; // created by lex 188 246 return ret; 189 247 } // build_constantStr 190 248 191 Expression * build_field_name_FLOATINGconstant( const st d::string & str ) {249 Expression * build_field_name_FLOATINGconstant( const string & str ) { 192 250 // str is of the form A.B -> separate at the . and return member expression 193 251 int a, b; 194 252 char dot; 195 st d::stringstream ss( str );253 stringstream ss( str ); 196 254 ss >> a >> dot >> b; 197 255 UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) ); … … 207 265 } else { 208 266 return new UntypedMemberExpr( fracts, fieldName ); 209 } 210 } 267 } // if 268 } // if 211 269 return fieldName; 212 270 } // make_field_name_fraction_constants … … 216 274 } // build_field_name_fraction_constants 217 275 218 Expression * build_field_name_REALFRACTIONconstant( const st d::string & str ) {276 Expression * build_field_name_REALFRACTIONconstant( const string & str ) { 219 277 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str ); 220 Expression * ret = build_constantInteger( *new st d::string( str.substr(1) ) );278 Expression * ret = build_constantInteger( *new string( str.substr(1) ) ); 221 279 delete &str; 222 280 return ret; 223 281 } // build_field_name_REALFRACTIONconstant 224 282 225 Expression * build_field_name_REALDECIMALconstant( const st d::string & str ) {283 Expression * build_field_name_REALDECIMALconstant( const string & str ) { 226 284 if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str ); 227 Expression * ret = build_constantInteger( *new st d::string( str.substr( 0, str.size()-1 ) ) );285 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) ); 228 286 delete &str; 229 287 return ret; … … 236 294 } // build_varref 237 295 238 296 // TODO: get rid of this and OperKinds and reuse code from OperatorTable 239 297 static const char * OperName[] = { // must harmonize with OperKinds 240 298 // diadic … … 244 302 "?[?]", "...", 245 303 // monadic 246 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&"304 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", 247 305 }; // OperName 248 306 … … 307 365 308 366 Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) { 309 std::list< Expression * > args;367 list< Expression * > args; 310 368 args.push_back( maybeMoveBuild< Expression >(expr_node) ); 311 369 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); … … 313 371 314 372 Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) { 315 std::list< Expression * > args;316 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx 373 list< Expression * > args; 374 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code. 317 375 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 318 376 } // build_unary_ptr 319 377 320 378 Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 321 std::list< Expression * > args;379 list< Expression * > args; 322 380 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 323 381 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); … … 326 384 327 385 Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 328 std::list< Expression * > args;386 list< Expression * > args; 329 387 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 330 388 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); … … 349 407 350 408 Expression * build_tuple( ExpressionNode * expr_node ) { 351 std::list< Expression * > exprs;409 list< Expression * > exprs; 352 410 buildMoveList( expr_node, exprs ); 353 411 return new UntypedTupleExpr( exprs );; … … 355 413 356 414 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) { 357 std::list< Expression * > args;415 list< Expression * > args; 358 416 buildMoveList( expr_node, args ); 359 417 return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr ); … … 364 422 } // build_range 365 423 366 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr* constraint, ExpressionNode * operand ) {424 Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ) { 367 425 return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) ); 368 426 } // build_asmexpr -
src/Parser/ParseNode.h
r800d275 r235b41f 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:28:16 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thr Aug 17 13:46:00201713 // Update Count : 79 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 19:24:34 2017 13 // Update Count : 799 14 14 // 15 15 … … 154 154 Index, Range, 155 155 // monadic 156 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress,156 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, 157 157 Ctor, Dtor, 158 158 }; // OperKinds … … 162 162 }; 163 163 164 Expression * build_constantInteger( conststd::string &str );165 Expression * build_constantFloat( conststd::string &str );166 Expression * build_constantChar( conststd::string &str );167 ConstantExpr * build_constantStr( conststd::string &str );164 Expression * build_constantInteger( std::string &str ); 165 Expression * build_constantFloat( std::string &str ); 166 Expression * build_constantChar( std::string &str ); 167 Expression * build_constantStr( std::string &str ); 168 168 Expression * build_field_name_FLOATINGconstant( const std::string & str ); 169 169 Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts ); … … 197 197 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ); 198 198 Expression * build_range( ExpressionNode * low, ExpressionNode * high ); 199 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr* constraint, ExpressionNode * operand );199 Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ); 200 200 Expression * build_valexpr( StatementNode * s ); 201 201 Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ); … … 330 330 bool hasEllipsis; 331 331 LinkageSpec::Spec linkage; 332 ConstantExpr*asmName;332 Expression *asmName; 333 333 std::list< Attribute * > attributes; 334 334 InitializerNode * initializer; … … 413 413 Statement * build_finally( StatementNode * stmt ); 414 414 Statement * build_compound( StatementNode * first ); 415 Statement * build_asmstmt( bool voltile, ConstantExpr* instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );415 Statement * build_asmstmt( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); 416 416 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when ); 417 417 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing ); -
src/Parser/StatementNode.cc
r800d275 r235b41f 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:01:31201713 // Update Count : 34 512 // Last Modified On : Fri Sep 1 23:25:23 2017 13 // Update Count : 346 14 14 // 15 15 … … 99 99 } // if 100 100 101 Expression * cond = ctl->condition ? maybeMoveBuild< Expression >(ctl->condition) : new VariableExpr( dynamic_cast<DeclarationWithType *>( dynamic_cast<DeclStmt *>( init.back() )->decl ) ); 101 Expression * cond = nullptr; 102 if ( ctl->condition ) { 103 // compare the provided condition against 0 104 cond = notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) ); 105 } else { 106 for ( Statement * stmt : init ) { 107 // build the && of all of the declared variables compared against 0 108 DeclStmt * declStmt = safe_dynamic_cast< DeclStmt * >( stmt ); 109 DeclarationWithType * dwt = safe_dynamic_cast< DeclarationWithType * >( declStmt->decl ); 110 Expression * nze = notZeroExpr( new VariableExpr( dwt ) ); 111 cond = cond ? new LogicalExpr( cond, nze, true ) : nze; 112 } 113 } 102 114 delete ctl; 103 return new IfStmt( noLabels, notZeroExpr( cond ), thenb, elseb, init );115 return new IfStmt( noLabels, cond, thenb, elseb, init ); 104 116 } 105 117 … … 288 300 } 289 301 290 Statement *build_asmstmt( bool voltile, ConstantExpr*instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {302 Statement *build_asmstmt( bool voltile, Expression *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) { 291 303 std::list< Expression * > out, in; 292 304 std::list< ConstantExpr * > clob; -
src/Parser/TypeData.cc
r800d275 r235b41f 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:12:51 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Aug 14 10:41:00201713 // Update Count : 56 811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 1 23:13:38 2017 13 // Update Count : 569 14 14 // 15 15 … … 814 814 } // buildTypeof 815 815 816 Declaration * buildDecl( const TypeData * td, const string &name, Type::StorageClasses scs, Expression * bitfieldWidth, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, ConstantExpr*asmName, Initializer * init, std::list< Attribute * > attributes ) {816 Declaration * buildDecl( const TypeData * td, const string &name, Type::StorageClasses scs, Expression * bitfieldWidth, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, Expression *asmName, Initializer * init, std::list< Attribute * > attributes ) { 817 817 if ( td->kind == TypeData::Function ) { 818 818 if ( td->function.idList ) { // KR function ? -
src/Parser/TypeData.h
r800d275 r235b41f 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:18:36 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Aug 14 10:38:00201713 // Update Count : 1 8911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 1 23:33:45 2017 13 // Update Count : 190 14 14 // 15 15 … … 118 118 TupleType * buildTuple( const TypeData * ); 119 119 TypeofType * buildTypeof( const TypeData * ); 120 Declaration * buildDecl( const TypeData *, const std::string &, Type::StorageClasses, Expression *, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec, ConstantExpr *asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );120 Declaration * buildDecl( const TypeData *, const std::string &, Type::StorageClasses, Expression *, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec, Expression * asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() ); 121 121 FunctionType * buildFunction( const TypeData * ); 122 122 void buildKRFunction( const TypeData::Function_t & function ); -
src/Parser/lex.ll
r800d275 r235b41f 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : T ue Aug 22 22:43:39201713 * Update Count : 5 5812 * Last Modified On : Thu Aug 31 21:30:10 2017 13 * Update Count : 598 14 14 */ 15 15 … … 19 19 20 20 %{ 21 // Th islexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been21 // The lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been 22 22 // performed and removed from the source. The only exceptions are preprocessor directives passed to the compiler (e.g., 23 23 // line-number directives) and C/C++ style comments, which are ignored. … … 25 25 //**************************** Includes and Defines **************************** 26 26 27 unsigned int column = 0; // position of the end of the last token parsed 28 #define YY_USER_ACTION column += yyleng; // trigger before each matching rule's action 29 27 30 #include <string> 28 31 #include <cstdio> // FILENAME_MAX 32 using namespace std; 29 33 30 34 #include "ParseNode.h" … … 32 36 33 37 char *yyfilename; 34 st d::string *strtext;// accumulate parts of character and string constant value38 string *strtext; // accumulate parts of character and string constant value 35 39 36 40 #define RETURN_LOCN(x) yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x ) 37 #define RETURN_VAL(x) yylval.tok.str = new st d::string( yytext ); RETURN_LOCN( x )41 #define RETURN_VAL(x) yylval.tok.str = new string( yytext ); RETURN_LOCN( x ) 38 42 #define RETURN_CHAR(x) yylval.tok.str = nullptr; RETURN_LOCN( x ) 39 43 #define RETURN_STR(x) yylval.tok.str = strtext; RETURN_LOCN( x ) 40 44 41 45 #define WHITE_RETURN(x) // do nothing 42 #define NEWLINE_RETURN() WHITE_RETURN( '\n' )46 #define NEWLINE_RETURN() column = 0; WHITE_RETURN( '\n' ) 43 47 #define ASCIIOP_RETURN() RETURN_CHAR( (int)yytext[0] ) // single character operator 44 48 #define NAMEDOP_RETURN(x) RETURN_CHAR( x ) // multichar operator, with a name … … 53 57 yyleng = 0; 54 58 for ( int i = 0; yytext[i] != '\0'; i += 1 ) { 59 if ( yytext[i] == '`' ) { 60 // copy user suffix 61 for ( ; yytext[i] != '\0'; i += 1 ) { 62 yytext[yyleng] = yytext[i]; 63 yyleng += 1; 64 } // for 65 break; 66 } // if 55 67 if ( yytext[i] != '_' ) { 56 68 yytext[yyleng] = yytext[i]; … … 77 89 attr_identifier "@"{identifier} 78 90 91 user_suffix_opt ("`"{identifier})? 92 79 93 // numeric constants, CFA: '_' in constant 80 94 hex_quad {hex}("_"?{hex}){3} 81 integer_suffix "_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?)))95 integer_suffix_opt ("_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?))))? 82 96 83 97 octal_digits ({octal})|({octal}({octal}|"_")*{octal}) 84 98 octal_prefix "0""_"? 85 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix }?99 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt}{user_suffix_opt} 86 100 87 101 nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal}) 88 decimal_constant {nonzero_digits}{integer_suffix }?102 decimal_constant {nonzero_digits}{integer_suffix_opt}{user_suffix_opt} 89 103 90 104 hex_digits ({hex})|({hex}({hex}|"_")*{hex}) 91 105 hex_prefix "0"[xX]"_"? 92 hex_constant {hex_prefix}{hex_digits}{integer_suffix}? 93 106 hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt}{user_suffix_opt} 107 108 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 109 floating_suffix_opt ("_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL"))? 94 110 decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal}) 95 real_decimal {decimal_digits}"."{exponent}?{floating_suffix }?96 real_fraction "."{decimal_digits}{exponent}?{floating_suffix }?111 real_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt}{user_suffix_opt} 112 real_fraction "."{decimal_digits}{exponent}?{floating_suffix_opt}{user_suffix_opt} 97 113 real_constant {decimal_digits}{real_fraction} 98 114 exponent "_"?[eE]"_"?[+-]?{decimal_digits} 99 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 100 floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL") 101 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}? 115 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix_opt}{user_suffix_opt} 102 116 103 117 binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits} 104 118 hex_fractional_constant ({hex_digits}?"."{hex_digits})|({hex_digits}".") 105 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix }?119 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix_opt} 106 120 107 121 // character escape sequence, GCC: \e => esc character … … 154 168 memcpy( &filename, begin_string + 1, length ); // copy file name from yytext 155 169 filename[ length ] = '\0'; // terminate string with sentinel 156 // std::cout << "file " << filename << " line " << lineno << std::endl;170 //cout << "file " << filename << " line " << lineno << endl; 157 171 yylineno = lineno; 158 172 yyfilename = filename; … … 302 316 303 317 /* character constant, allows empty value */ 304 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new st d::string( yytext, yyleng ); }318 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); } 305 319 <QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); } 306 <QUOTE>['\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }320 <QUOTE>['\n]{user_suffix_opt} { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); } 307 321 /* ' stop highlighting */ 308 322 309 323 /* string constant */ 310 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new st d::string( yytext, yyleng ); }324 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); } 311 325 <STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); } 312 <STRING>["\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }326 <STRING>["\n]{user_suffix_opt} { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); } 313 327 /* " stop highlighting */ 314 328 … … 383 397 {op_unary}"?" { IDENTIFIER_RETURN(); } // unary 384 398 "?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); } 385 "^?{}" { IDENTIFIER_RETURN(); } 399 "^?{}" { IDENTIFIER_RETURN(); } 400 "?`"{identifier} { IDENTIFIER_RETURN(); } // unit operator 386 401 "?"{op_binary_over}"?" { IDENTIFIER_RETURN(); } // binary 387 402 /* … … 422 437 } 423 438 424 /* unknown character s*/425 . { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }439 /* unknown character */ 440 . { yyerror( "unknown character" ); } 426 441 427 442 %% 443 // ----end of lexer---- 444 445 void yyerror( const char * errmsg ) { 446 cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1 447 << ": " << SemanticError::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl; 448 } 428 449 429 450 // Local Variables: // -
src/Parser/parser.yy
r800d275 r235b41f 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 28 13:24:10201713 // Update Count : 27 2012 // Last Modified On : Sun Sep 3 20:43:19 2017 13 // Update Count : 2742 14 14 // 15 15 … … 48 48 #include <cstdio> 49 49 #include <stack> 50 using namespace std; 51 50 52 #include "ParseNode.h" 51 53 #include "TypedefTable.h" 52 54 #include "TypeData.h" 53 55 #include "LinkageSpec.h" 54 using namespace std; 56 #include "Common/SemanticError.h" // error_str 55 57 56 58 extern DeclarationNode * parseTree; … … 98 100 StatementNode * sn; 99 101 WaitForStmt * wfs; 100 ConstantExpr* constant;102 Expression * constant; 101 103 IfCtl * ifctl; 102 104 ForCtl * fctl; … … 534 536 $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); 535 537 break; 538 case OperKinds::And: 539 $$ = new ExpressionNode( new AddressExpr( build_addressOf( $2 ) ) ); 540 break; 536 541 default: 537 542 assert( false ); … … 560 565 | ATTR_IDENTIFIER '(' type ')' 561 566 { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); } 562 // | ANDAND IDENTIFIER // GCC, address of label563 // { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2 ) ); }564 567 ; 565 568 … … 3133 3136 // ----end of grammar---- 3134 3137 3135 extern char *yytext;3136 3137 void yyerror( const char * ) {3138 if ( yyfilename ) {3139 cout << yyfilename << ":";3140 } // if3141 cout << yylineno << ":1 syntax error at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl;3142 }3143 3144 3138 // Local Variables: // 3145 3139 // mode: c++ // -
src/ResolvExpr/AlternativeFinder.cc
r800d275 r235b41f 698 698 699 699 void AlternativeFinder::visit( UntypedExpr *untypedExpr ) { 700 {701 std::string fname = InitTweak::getFunctionName( untypedExpr );702 if ( fname == "&&" ) {703 VoidType v = Type::Qualifiers(); // resolve to type void *704 PointerType pt( Type::Qualifiers(), v.clone() );705 UntypedExpr *vexpr = untypedExpr->clone();706 vexpr->set_result( pt.clone() );707 alternatives.push_back( Alternative( vexpr, env, Cost::zero) );708 return;709 }710 }711 712 700 AlternativeFinder funcFinder( indexer, env ); 713 701 funcFinder.findWithAdjustment( untypedExpr->get_function() ); … … 749 737 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->get_result()->stripReferences() ) ) { 750 738 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 751 referenceToRvalueConversion( func->expr ); 739 Alternative newFunc( *func ); 740 referenceToRvalueConversion( newFunc.expr ); 752 741 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 753 742 // XXX 754 743 //Designators::check_alternative( function, *actualAlt ); 755 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) );744 makeFunctionAlternatives( newFunc, function, *actualAlt, std::back_inserter( candidates ) ); 756 745 } 757 746 } 758 747 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->get_result()->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer) 759 referenceToRvalueConversion( func->expr );760 748 EqvClass eqvClass; 761 749 if ( func->env.lookup( typeInst->get_name(), eqvClass ) && eqvClass.type ) { 762 750 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) { 751 Alternative newFunc( *func ); 752 referenceToRvalueConversion( newFunc.expr ); 763 753 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 764 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) );754 makeFunctionAlternatives( newFunc, function, *actualAlt, std::back_inserter( candidates ) ); 765 755 } // for 766 756 } // if … … 773 763 if ( PointerType *pointer = dynamic_cast< PointerType* >( funcOp->expr->get_result()->stripReferences() ) ) { 774 764 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 775 referenceToRvalueConversion( funcOp->expr ); 765 Alternative newFunc( *funcOp ); 766 referenceToRvalueConversion( newFunc.expr ); 776 767 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 777 768 AltList currentAlt; 778 769 currentAlt.push_back( *func ); 779 770 currentAlt.insert( currentAlt.end(), actualAlt->begin(), actualAlt->end() ); 780 makeFunctionAlternatives( *funcOp, function, currentAlt, std::back_inserter( candidates ) );771 makeFunctionAlternatives( newFunc, function, currentAlt, std::back_inserter( candidates ) ); 781 772 } // for 782 773 } // if … … 853 844 } // if 854 845 } // for 846 } 847 848 void AlternativeFinder::visit( LabelAddressExpr * expr ) { 849 alternatives.push_back( Alternative( expr->clone(), env, Cost::zero) ); 855 850 } 856 851 -
src/ResolvExpr/AlternativeFinder.h
r800d275 r235b41f 54 54 virtual void visit( UntypedExpr *untypedExpr ); 55 55 virtual void visit( AddressExpr *addressExpr ); 56 virtual void visit( LabelAddressExpr *labelExpr ); 56 57 virtual void visit( CastExpr *castExpr ); 57 58 virtual void visit( VirtualCastExpr *castExpr ); -
src/ResolvExpr/RenameVars.cc
r800d275 r235b41f 88 88 typeBefore( aggregateUseType ); 89 89 acceptAll( aggregateUseType->get_parameters(), *this ); 90 acceptAll( aggregateUseType->get_members(), *this );91 90 typeAfter( aggregateUseType ); 92 91 } -
src/ResolvExpr/TypeEnvironment.cc
r800d275 r235b41f 25 25 26 26 namespace ResolvExpr { 27 // adding this comparison operator significantly improves assertion resolution run time for28 // some cases. The current resolution algorithm's speed partially depends on the order of29 // assertions. Assertions which have fewer possible matches should appear before30 // assertions which have more possible matches. This seems to imply that this could31 // be further improved by providing an indexer as an additional argument and ordering based32 // on the number of matches of the same kind (object, function) for the names of the33 // declarations.34 //35 // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this comparator.36 bool AssertCompare::operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) const {37 // Objects are always less than functions38 if ( ObjectDecl * objectDecl1 = dynamic_cast< ObjectDecl * >( d1 ) ) {39 if ( ObjectDecl * objectDecl2 = dynamic_cast< ObjectDecl * >( d2 ) ) {40 // objects are ordered by name then type pointer, in that order41 int cmp = objectDecl1->get_name().compare( objectDecl2->get_name() );42 return cmp < 0 ||43 ( cmp == 0 && objectDecl1->get_type() < objectDecl2->get_type() );44 } else {45 return true;46 }47 } else if ( FunctionDecl * funcDecl1 = dynamic_cast< FunctionDecl * >( d1 ) ) {48 if ( FunctionDecl * funcDecl2 = dynamic_cast< FunctionDecl * >( d2 ) ) {49 // functions are ordered by name, # parameters, # returnVals, type pointer in that order50 FunctionType * ftype1 = funcDecl1->get_functionType();51 FunctionType * ftype2 = funcDecl2->get_functionType();52 int numThings1 = ftype1->get_parameters().size() + ftype1->get_returnVals().size();53 int numThings2 = ftype2->get_parameters().size() + ftype2->get_returnVals().size();54 if ( numThings1 < numThings2 ) return true;55 if ( numThings1 > numThings2 ) return false;56 57 // if ( ftype1->get_parameters().size() < ftype2->get_parameters().size() ) return true;58 // else if ( ftype1->get_parameters().size() > ftype2->get_parameters().size() ) return false;59 // // same number of parameters60 // if ( ftype1->get_returnVals().size() < ftype2->get_returnVals().size() ) return true;61 // else if ( ftype1->get_returnVals().size() > ftype2->get_returnVals().size() ) return false;62 // same number of return vals63 // int cmp = funcDecl1->get_name().compare( funcDecl2->get_name() );64 // if ( cmp < 0 ) return true;65 // else if ( cmp > 0 ) return false;66 // // same name67 return ftype1 < ftype2;68 } else {69 return false;70 }71 } else {72 assert( false );73 }74 }75 76 27 void printAssertionSet( const AssertionSet &assertions, std::ostream &os, int indent ) { 77 28 for ( AssertionSet::const_iterator i = assertions.begin(); i != assertions.end(); ++i ) { -
src/ResolvExpr/TypeEnvironment.h
r800d275 r235b41f 28 28 29 29 namespace ResolvExpr { 30 // adding this comparison operator significantly improves assertion resolution run time for 31 // some cases. The current resolution algorithm's speed partially depends on the order of 32 // assertions. Assertions which have fewer possible matches should appear before 33 // assertions which have more possible matches. This seems to imply that this could 34 // be further improved by providing an indexer as an additional argument and ordering based 35 // on the number of matches of the same kind (object, function) for the names of the 36 // declarations. 37 // 38 // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this comparator. 30 39 struct AssertCompare { 31 bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) const; 40 bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) const { 41 int cmp = d1->get_name().compare( d2->get_name() ); 42 return cmp < 0 || 43 ( cmp == 0 && d1->get_type() < d2->get_type() ); 44 } 32 45 }; 33 46 struct AssertionSetValue { -
src/SymTab/Indexer.cc
r800d275 r235b41f 398 398 void Indexer::visit( LabelAddressExpr *labAddressExpr ) { 399 399 acceptNewScope( labAddressExpr->get_result(), *this ); 400 maybeAccept( labAddressExpr->get_arg(), *this );401 400 } 402 401 … … 554 553 555 554 556 void Indexer::visit( TraitInstType *contextInst ) { 557 acceptAll( contextInst->get_parameters(), *this ); 558 acceptAll( contextInst->get_members(), *this ); 555 void Indexer::visit( TraitInstType *traitInst ) { 556 acceptAll( traitInst->get_parameters(), *this ); 559 557 } 560 558 -
src/SymTab/Validate.cc
r800d275 r235b41f 127 127 public: 128 128 LinkReferenceToTypes( bool doDebug, const Indexer *indexer ); 129 using Parent::visit; 129 using Parent::visit; 130 void visit( TypeInstType *typeInst ) final; 131 130 132 void visit( EnumInstType *enumInst ) final; 131 133 void visit( StructInstType *structInst ) final; 132 134 void visit( UnionInstType *unionInst ) final; 133 void visit( TraitInstType *contextInst ) final; 135 void visit( TraitInstType *traitInst ) final; 136 134 137 void visit( EnumDecl *enumDecl ) final; 135 138 void visit( StructDecl *structDecl ) final; 136 139 void visit( UnionDecl *unionDecl ) final; 137 void visit( TypeInstType *typeInst ) final; 140 void visit( TraitDecl * traitDecl ) final; 141 138 142 private: 139 143 const Indexer *indexer; … … 240 244 }; 241 245 246 struct LabelAddressFixer final : public WithGuards { 247 std::set< Label > labels; 248 249 void premutate( FunctionDecl * funcDecl ); 250 Expression * postmutate( AddressExpr * addrExpr ); 251 }; 242 252 243 253 FunctionDecl * dereferenceOperator = nullptr; … … 253 263 PassVisitor<ValidateGenericParameters> genericParams; 254 264 PassVisitor<FindSpecialDeclarations> finder; 265 PassVisitor<LabelAddressFixer> labelAddrFixer; 255 266 256 267 EliminateTypedef::eliminateTypedef( translationUnit ); … … 270 281 ArrayLength::computeLength( translationUnit ); 271 282 acceptAll( translationUnit, finder ); 283 mutateAll( translationUnit, labelAddrFixer ); 272 284 } 273 285 … … 287 299 288 300 HoistStruct::HoistStruct() : inStruct( false ) { 289 }290 291 void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) {292 std::list< Declaration * >::iterator i = declList.begin();293 while ( i != declList.end() ) {294 std::list< Declaration * >::iterator next = i;295 ++next;296 if ( pred( *i ) ) {297 if ( doDelete ) {298 delete *i;299 } // if300 declList.erase( i );301 } // if302 i = next;303 } // while304 301 } 305 302 … … 453 450 } 454 451 455 void LinkReferenceToTypes::visit( TraitInstType *traitInst ) { 452 template< typename Decl > 453 void normalizeAssertions( std::list< Decl * > & assertions ) { 454 // ensure no duplicate trait members after the clone 455 auto pred = [](Decl * d1, Decl * d2) { 456 // only care if they're equal 457 DeclarationWithType * dwt1 = dynamic_cast<DeclarationWithType *>( d1 ); 458 DeclarationWithType * dwt2 = dynamic_cast<DeclarationWithType *>( d2 ); 459 if ( dwt1 && dwt2 ) { 460 if ( dwt1->get_name() == dwt2->get_name() && ResolvExpr::typesCompatible( dwt1->get_type(), dwt2->get_type(), SymTab::Indexer() ) ) { 461 // std::cerr << "=========== equal:" << std::endl; 462 // std::cerr << "d1: " << d1 << std::endl; 463 // std::cerr << "d2: " << d2 << std::endl; 464 return false; 465 } 466 } 467 return d1 < d2; 468 }; 469 std::set<Decl *, decltype(pred)> unique_members( assertions.begin(), assertions.end(), pred ); 470 // if ( unique_members.size() != assertions.size() ) { 471 // std::cerr << "============different" << std::endl; 472 // std::cerr << unique_members.size() << " " << assertions.size() << std::endl; 473 // } 474 475 std::list< Decl * > order; 476 order.splice( order.end(), assertions ); 477 std::copy_if( order.begin(), order.end(), back_inserter( assertions ), [&]( Decl * decl ) { 478 return unique_members.count( decl ); 479 }); 480 } 481 482 // expand assertions from trait instance, performing the appropriate type variable substitutions 483 template< typename Iterator > 484 void expandAssertions( TraitInstType * inst, Iterator out ) { 485 assertf( inst->baseTrait, "Trait instance not linked to base trait: %s", toString( inst ).c_str() ); 486 std::list< DeclarationWithType * > asserts; 487 for ( Declaration * decl : inst->baseTrait->members ) { 488 asserts.push_back( safe_dynamic_cast<DeclarationWithType *>( decl->clone() ) ); 489 } 490 // substitute trait decl parameters for instance parameters 491 applySubstitution( inst->baseTrait->parameters.begin(), inst->baseTrait->parameters.end(), inst->parameters.begin(), asserts.begin(), asserts.end(), out ); 492 } 493 494 void LinkReferenceToTypes::visit( TraitDecl * traitDecl ) { 495 Parent::visit( traitDecl ); 496 497 if ( traitDecl->name == "sized" ) { 498 // "sized" is a special trait - flick the sized status on for the type variable 499 assertf( traitDecl->parameters.size() == 1, "Built-in trait 'sized' has incorrect number of parameters: %zd", traitDecl->parameters.size() ); 500 TypeDecl * td = traitDecl->parameters.front(); 501 td->set_sized( true ); 502 } 503 504 // move assertions from type parameters into the body of the trait 505 for ( TypeDecl * td : traitDecl->parameters ) { 506 for ( DeclarationWithType * assert : td->assertions ) { 507 if ( TraitInstType * inst = dynamic_cast< TraitInstType * >( assert->get_type() ) ) { 508 expandAssertions( inst, back_inserter( traitDecl->members ) ); 509 } else { 510 traitDecl->members.push_back( assert->clone() ); 511 } 512 } 513 deleteAll( td->assertions ); 514 td->assertions.clear(); 515 } // for 516 } 517 518 void LinkReferenceToTypes::visit( TraitInstType * traitInst ) { 456 519 Parent::visit( traitInst ); 457 if ( traitInst->get_name() == "sized" ) {458 // "sized" is a special trait with no members - just flick the sized status on for the type variable459 if ( traitInst->get_parameters().size() != 1 ) {460 throw SemanticError( "incorrect number of trait parameters: ", traitInst );461 }462 TypeExpr * param = safe_dynamic_cast< TypeExpr * > ( traitInst->get_parameters().front() );463 TypeInstType * inst = safe_dynamic_cast< TypeInstType * > ( param->get_type() );464 TypeDecl * decl = inst->get_baseType();465 decl->set_sized( true );466 // since "sized" is special, the next few steps don't apply467 return;468 }469 470 520 // handle other traits 471 TraitDecl *traitDecl = indexer->lookupTrait( traitInst-> get_name());521 TraitDecl *traitDecl = indexer->lookupTrait( traitInst->name ); 472 522 if ( ! traitDecl ) { 473 throw SemanticError( "use of undeclared trait " + traitInst-> get_name());523 throw SemanticError( "use of undeclared trait " + traitInst->name ); 474 524 } // if 475 525 if ( traitDecl->get_parameters().size() != traitInst->get_parameters().size() ) { 476 526 throw SemanticError( "incorrect number of trait parameters: ", traitInst ); 477 527 } // if 478 479 for ( TypeDecl * td : traitDecl->get_parameters() ) { 480 for ( DeclarationWithType * assert : td->get_assertions() ) { 481 traitInst->get_members().push_back( assert->clone() ); 482 } // for 483 } // for 484 485 // need to clone members of the trait for ownership purposes 486 std::list< Declaration * > members; 487 std::transform( traitDecl->get_members().begin(), traitDecl->get_members().end(), back_inserter( members ), [](Declaration * dwt) { return dwt->clone(); } ); 488 489 applySubstitution( traitDecl->get_parameters().begin(), traitDecl->get_parameters().end(), traitInst->get_parameters().begin(), members.begin(), members.end(), back_inserter( traitInst->get_members() ) ); 528 traitInst->baseTrait = traitDecl; 490 529 491 530 // need to carry over the 'sized' status of each decl in the instance … … 498 537 } 499 538 } 539 // normalizeAssertions( traitInst->members ); 500 540 } 501 541 … … 561 601 void forallFixer( Type * func ) { 562 602 for ( TypeDecl * type : func->get_forall() ) { 563 std::list< DeclarationWithType * > toBeDone, nextRound; 564 toBeDone.splice( toBeDone.end(), type->get_assertions() ); 565 while ( ! toBeDone.empty() ) { 566 for ( DeclarationWithType * assertion : toBeDone ) { 567 if ( TraitInstType *traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) { 568 // expand trait instance into all of its members 569 for ( Declaration * member : traitInst->get_members() ) { 570 DeclarationWithType *dwt = safe_dynamic_cast< DeclarationWithType * >( member ); 571 nextRound.push_back( dwt->clone() ); 572 } 573 delete traitInst; 574 } else { 575 // pass assertion through 576 FixFunction fixer; 577 assertion = assertion->acceptMutator( fixer ); 578 if ( fixer.get_isVoid() ) { 579 throw SemanticError( "invalid type void in assertion of function ", func ); 580 } 581 type->get_assertions().push_back( assertion ); 582 } // if 583 } // for 584 toBeDone.clear(); 585 toBeDone.splice( toBeDone.end(), nextRound ); 586 } // while 603 std::list< DeclarationWithType * > asserts; 604 asserts.splice( asserts.end(), type->assertions ); 605 // expand trait instances into their members 606 for ( DeclarationWithType * assertion : asserts ) { 607 if ( TraitInstType *traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) { 608 // expand trait instance into all of its members 609 expandAssertions( traitInst, back_inserter( type->assertions ) ); 610 delete traitInst; 611 } else { 612 // pass other assertions through 613 type->assertions.push_back( assertion ); 614 } // if 615 } // for 616 // apply FixFunction to every assertion to check for invalid void type 617 for ( DeclarationWithType *& assertion : type->assertions ) { 618 FixFunction fixer; 619 assertion = assertion->acceptMutator( fixer ); 620 if ( fixer.get_isVoid() ) { 621 throw SemanticError( "invalid type void in assertion of function ", func ); 622 } // if 623 } // for 624 // normalizeAssertions( type->assertions ); 587 625 } // for 588 626 } … … 752 790 CompoundStmt *ret = Mutator::mutate( compoundStmt ); 753 791 scopeLevel -= 1; 754 std::list< Statement * >::iterator i = compoundStmt->get_kids().begin(); 755 while ( i != compoundStmt->get_kids().end() ) { 756 std::list< Statement * >::iterator next = i+1; 757 if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) { 792 // remove and delete decl stmts 793 filter( compoundStmt->kids, [](Statement * stmt) { 794 if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( stmt ) ) { 758 795 if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) { 759 delete *i; 760 compoundStmt->get_kids().erase( i ); 796 return true; 761 797 } // if 762 798 } // if 763 i = next;764 } // while799 return false; 800 }, true); 765 801 typedefNames.endScope(); 766 802 return ret; … … 771 807 template<typename AggDecl> 772 808 AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) { 773 std::list<Declaration *>::iterator it = aggDecl->get_members().begin(); 774 for ( ; it != aggDecl->get_members().end(); ) { 775 std::list< Declaration * >::iterator next = it+1; 776 if ( dynamic_cast< TypedefDecl * >( *it ) ) { 777 delete *it; 778 aggDecl->get_members().erase( it ); 779 } // if 780 it = next; 781 } 809 filter( aggDecl->members, isTypedef, true ); 782 810 return aggDecl; 783 811 } … … 957 985 } 958 986 987 struct LabelFinder { 988 std::set< Label > & labels; 989 LabelFinder( std::set< Label > & labels ) : labels( labels ) {} 990 void previsit( Statement * stmt ) { 991 for ( Label & l : stmt->labels ) { 992 labels.insert( l ); 993 } 994 } 995 }; 996 997 void LabelAddressFixer::premutate( FunctionDecl * funcDecl ) { 998 GuardValue( labels ); 999 PassVisitor<LabelFinder> finder( labels ); 1000 funcDecl->accept( finder ); 1001 } 1002 1003 Expression * LabelAddressFixer::postmutate( AddressExpr * addrExpr ) { 1004 // convert &&label into label address 1005 if ( AddressExpr * inner = dynamic_cast< AddressExpr * >( addrExpr->arg ) ) { 1006 if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( inner->arg ) ) { 1007 if ( labels.count( nameExpr->name ) ) { 1008 Label name = nameExpr->name; 1009 delete addrExpr; 1010 return new LabelAddressExpr( name ); 1011 } 1012 } 1013 } 1014 return addrExpr; 1015 } 1016 959 1017 void FindSpecialDeclarations::previsit( FunctionDecl * funcDecl ) { 960 1018 if ( ! dereferenceOperator ) { -
src/SynTree/AddressExpr.cc
r800d275 r235b41f 70 70 } 71 71 72 LabelAddressExpr::LabelAddressExpr( const Label &arg ) : arg( arg ) { 73 // label address always has type void * 74 result = new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ); 75 } 76 LabelAddressExpr::LabelAddressExpr( const LabelAddressExpr & other ) : Expression( other ), arg( other.arg ) {} 77 LabelAddressExpr::~LabelAddressExpr() {} 78 79 void LabelAddressExpr::print( std::ostream & os, int indent ) const { 80 os << "Address of label:" << std::endl << std::string( indent+2, ' ' ) << arg; 81 } 82 72 83 // Local Variables: // 73 84 // tab-width: 4 // -
src/SynTree/Declaration.h
r800d275 r235b41f 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Aug 14 10:15:00201713 // Update Count : 1 2811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 19:24:06 2017 13 // Update Count : 131 14 14 // 15 15 … … 82 82 int scopeLevel = 0; 83 83 84 ConstantExpr*asmName;84 Expression *asmName; 85 85 std::list< Attribute * > attributes; 86 86 … … 97 97 DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; } 98 98 99 ConstantExpr*get_asmName() const { return asmName; }100 DeclarationWithType * set_asmName( ConstantExpr*newValue ) { asmName = newValue; return this; }99 Expression *get_asmName() const { return asmName; } 100 DeclarationWithType * set_asmName( Expression *newValue ) { asmName = newValue; return this; } 101 101 102 102 std::list< Attribute * >& get_attributes() { return attributes; } -
src/SynTree/Expression.h
r800d275 r235b41f 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Aug 8 11:54:00201713 // Update Count : 4 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 19:23:46 2017 13 // Update Count : 48 14 14 // 15 15 16 #pragma once 16 17 … … 24 25 #include "Constant.h" // for Constant 25 26 #include "Initializer.h" // for Designation (ptr only), Initializer 27 #include "Label.h" // for Label 26 28 #include "Mutator.h" // for Mutator 27 29 #include "SynTree.h" // for UniqueId … … 173 175 }; 174 176 175 // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack 177 // GCC &&label 178 // https://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Labels-as-Values.html 176 179 class LabelAddressExpr : public Expression { 177 180 public: 178 Expression *arg;179 180 LabelAddressExpr( Expression *arg );181 Label arg; 182 183 LabelAddressExpr( const Label &arg ); 181 184 LabelAddressExpr( const LabelAddressExpr & other ); 182 185 virtual ~LabelAddressExpr(); 183 184 Expression * get_arg() const { return arg; }185 void set_arg(Expression * newValue ) { arg = newValue; }186 186 187 187 virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); } … … 540 540 public: 541 541 Expression * inout; 542 ConstantExpr* constraint;542 Expression * constraint; 543 543 Expression * operand; 544 544 545 AsmExpr( Expression * inout, ConstantExpr* constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}545 AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 546 546 AsmExpr( const AsmExpr & other ); 547 547 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; }; … … 550 550 void set_inout( Expression * newValue ) { inout = newValue; } 551 551 552 ConstantExpr* get_constraint() const { return constraint; }553 void set_constraint( ConstantExpr* newValue ) { constraint = newValue; }552 Expression * get_constraint() const { return constraint; } 553 void set_constraint( Expression * newValue ) { constraint = newValue; } 554 554 555 555 Expression * get_operand() const { return operand; } -
src/SynTree/Mutator.cc
r800d275 r235b41f 246 246 labelAddressExpr->set_env( maybeMutate( labelAddressExpr->get_env(), *this ) ); 247 247 labelAddressExpr->set_result( maybeMutate( labelAddressExpr->get_result(), *this ) ); 248 labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );249 248 return labelAddressExpr; 250 249 } … … 538 537 Type * Mutator::mutate( TraitInstType *aggregateUseType ) { 539 538 handleReferenceToType( aggregateUseType ); 540 mutateAll( aggregateUseType->get_members(), *this );541 539 return aggregateUseType; 542 540 } -
src/SynTree/ReferenceToType.cc
r800d275 r235b41f 132 132 std::string TraitInstType::typeString() const { return "trait"; } 133 133 134 TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) { 135 cloneAll( other.members, members ); 134 TraitInstType::TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes ) : Parent( tq, baseTrait->name, attributes ), baseTrait( baseTrait ) {} 135 136 TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ), baseTrait( other.baseTrait ) { 136 137 } 137 138 138 139 TraitInstType::~TraitInstType() { 139 deleteAll( members );140 140 } 141 141 -
src/SynTree/Statement.cc
r800d275 r235b41f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:17:20201713 // Update Count : 6 712 // Last Modified On : Sun Sep 3 20:46:44 2017 13 // Update Count : 68 14 14 // 15 15 … … 52 52 53 53 54 AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr*instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement( labels ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}54 AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement( labels ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {} 55 55 56 56 AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) { … … 89 89 90 90 BranchStmt::BranchStmt( std::list<Label> labels, Label target, Type type ) throw ( SemanticError ) : 91 Statement( labels ), originalTarget( target ), target( target ), computedTarget( NULL), type( type ) {91 Statement( labels ), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) { 92 92 //actually this is a syntactic error signaled by the parser 93 if ( type == BranchStmt::Goto && target.empty() ) 93 if ( type == BranchStmt::Goto && target.empty() ) { 94 94 throw SemanticError("goto without target"); 95 } 95 96 } 96 97 97 98 BranchStmt::BranchStmt( std::list<Label> labels, Expression *computedTarget, Type type ) throw ( SemanticError ) : 98 99 Statement( labels ), computedTarget( computedTarget ), type( type ) { 99 if ( type != BranchStmt::Goto || computedTarget == 0 )100 if ( type != BranchStmt::Goto || computedTarget == nullptr ) { 100 101 throw SemanticError("Computed target not valid in branch statement"); 102 } 101 103 } 102 104 103 105 void BranchStmt::print( std::ostream &os, int indent ) const { 104 106 os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ; 107 if ( target != "" ) os << string( indent+2, ' ' ) << "with target: " << target << endl; 108 if ( originalTarget != "" ) os << string( indent+2, ' ' ) << "with original target: " << originalTarget << endl; 109 if ( computedTarget != nullptr ) os << string( indent+2, ' ' ) << "with computed target: " << computedTarget << endl; 105 110 } 106 111 -
src/SynTree/Statement.h
r800d275 r235b41f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 15:37:53201713 // Update Count : 7 212 // Last Modified On : Sun Sep 3 20:46:46 2017 13 // Update Count : 77 14 14 // 15 15 … … 98 98 public: 99 99 bool voltile; 100 ConstantExpr*instruction;100 Expression *instruction; 101 101 std::list<Expression *> output, input; 102 102 std::list<ConstantExpr *> clobber; 103 103 std::list<Label> gotolabels; 104 104 105 AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> input, std::list<Expression *> output, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );105 AsmStmt( std::list<Label> labels, bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ); 106 106 AsmStmt( const AsmStmt &other ); 107 107 virtual ~AsmStmt(); … … 109 109 bool get_voltile() { return voltile; } 110 110 void set_voltile( bool newValue ) { voltile = newValue; } 111 ConstantExpr *get_instruction() { return instruction; }112 void set_instruction( ConstantExpr *newValue ) { instruction = newValue; }113 std::list<Expression *> & get_output() { return output; }114 void set_output( const std::list<Expression *> & newValue ) { output = newValue; }115 std::list<Expression *> & get_input() { return input; }111 Expression * get_instruction() { return instruction; } 112 void set_instruction( Expression * newValue ) { instruction = newValue; } 113 std::list<Expression *> & get_output() { return output; } 114 void set_output( const std::list<Expression *> & newValue ) { output = newValue; } 115 std::list<Expression *> & get_input() { return input; } 116 116 void set_input( const std::list<Expression *> &newValue ) { input = newValue; } 117 std::list<ConstantExpr *> & get_clobber() { return clobber; }117 std::list<ConstantExpr *> & get_clobber() { return clobber; } 118 118 void set_clobber( const std::list<ConstantExpr *> &newValue ) { clobber = newValue; } 119 std::list<Label> & get_gotolabels() { return gotolabels; }119 std::list<Label> & get_gotolabels() { return gotolabels; } 120 120 void set_gotolabels( const std::list<Label> &newValue ) { gotolabels = newValue; } 121 121 122 virtual AsmStmt * clone() const { return new AsmStmt( *this ); }123 virtual void accept( Visitor & v ) { v.visit( this ); }124 virtual Statement * acceptMutator( Mutator &m ) { return m.mutate( this ); }125 virtual void print( std::ostream & os, int indent = 0 ) const;122 virtual AsmStmt * clone() const { return new AsmStmt( *this ); } 123 virtual void accept( Visitor & v ) { v.visit( this ); } 124 virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); } 125 virtual void print( std::ostream & os, int indent = 0 ) const; 126 126 }; 127 127 -
src/SynTree/Type.h
r800d275 r235b41f 471 471 typedef ReferenceToType Parent; 472 472 public: 473 // this member is filled in by the validate pass, which instantiates the members of the correponding 474 // aggregate with the actual type parameters specified for this use of the context 475 std::list< Declaration* > members; 476 477 TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {} 473 // this decl is not "owned" by the trait inst; it is merely a pointer to elsewhere in the tree, 474 // where the trait used in this type is actually defined 475 TraitDecl * baseTrait = nullptr; 476 477 TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {} 478 TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 478 479 TraitInstType( const TraitInstType & other ); 479 480 ~TraitInstType(); 480 481 std::list< Declaration* >& get_members() { return members; }482 481 483 482 virtual bool isComplete() const; -
src/SynTree/TypeSubstitution.h
r800d275 r235b41f 177 177 void applySubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actual, MemberIterator memberBegin, MemberIterator memberEnd, OutputIterator out ) { 178 178 TypeSubstitution sub = TypeSubstitution( formalBegin, formalEnd, actual ); 179 for ( std::list< Declaration* >::iteratori = memberBegin; i != memberEnd; ++i ) {179 for ( auto i = memberBegin; i != memberEnd; ++i ) { 180 180 sub.apply( *i ); 181 181 *out++ = *i; -
src/SynTree/Visitor.cc
r800d275 r235b41f 205 205 void Visitor::visit( LabelAddressExpr *labAddressExpr ) { 206 206 maybeAccept( labAddressExpr->get_result(), *this ); 207 maybeAccept( labAddressExpr->get_arg(), *this );208 207 } 209 208 … … 429 428 void Visitor::visit( TraitInstType *aggregateUseType ) { 430 429 handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); 431 acceptAll( aggregateUseType->get_members(), *this );432 430 } 433 431 -
src/libcfa/concurrency/coroutine
r800d275 r235b41f 1 // - *- Mode: CFA - *-2 1 // 3 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo … … 11 10 // Created On : Mon Nov 28 12:27:26 2016 12 11 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Sat Jul 22 09:57:17201714 // Update Count : 212 // Last Modified On : Wed Aug 30 07:58:29 2017 13 // Update Count : 3 15 14 // 16 15 -
src/libcfa/gmp
r800d275 r235b41f 10 10 // Created On : Tue Apr 19 08:43:43 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 24 09:24:51201713 // Update Count : 1612 // Last Modified On : Mon Sep 4 09:54:33 2017 13 // Update Count : 20 14 14 // 15 15 … … 32 32 static inline void ?{}( Int & this, const char * val ) { if ( mpz_init_set_str( this.mpz, val, 0 ) ) abort(); } 33 33 static inline void ^?{}( Int & this ) { mpz_clear( this.mpz ); } 34 35 // literal 36 static inline Int ?`mp( signed long int init ) { return (Int){ init }; } 37 static inline Int ?`mp( unsigned long int init ) { return (Int){ init }; } 38 static inline Int ?`mp( const char * init ) { return (Int){ init }; } 34 39 35 40 // assignment -
src/prelude/prelude.cf
r800d275 r235b41f 1 // -*- Mode: C -*-2 1 // 3 2 // Copyright (C) Glen Ditchfield 1994, 1999 … … 8 7 // Created On : Sat Nov 29 07:23:41 2014 9 8 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Tue Jul 5 18:04:40 201611 // Update Count : 9 29 // Last Modified On : Wed Aug 30 07:56:07 2017 10 // Update Count : 93 12 11 // 13 12 … … 15 14 16 15 // Section numbers from: http://plg.uwaterloo.ca/~cforall/refrat.pdf 16 17 // ------------------------------------------------------------ 18 // 19 // Section 6.7.11 Trait Declarations 20 // Note: the sized trait is used in declarations later in this 21 // file, so it must be out of order. 22 // 23 // ------------------------------------------------------------ 24 25 trait sized(dtype T) {}; 17 26 18 27 // ------------------------------------------------------------ -
src/tests/.expect/64/gmp.txt
r800d275 r235b41f 5 5 y:97 6 6 y:12345678901234567890123456789 7 y:200 8 y:-400 9 y:24691357802469135780246913578 7 10 y:3 8 11 y:-3 -
src/tests/.expect/dtor-early-exit-ERR1.txt
r800d275 r235b41f 1 1 dtor-early-exit.c:142:1 error: jump to label 'L1' crosses initialization of y Branch (Goto) 2 with target: L1 3 with original target: L1 2 4 -
src/tests/.expect/dtor-early-exit-ERR2.txt
r800d275 r235b41f 1 1 dtor-early-exit.c:142:1 error: jump to label 'L2' crosses initialization of y Branch (Goto) 2 with target: L2 3 with original target: L2 2 4 -
src/tests/.expect/ifcond.txt
r800d275 r235b41f 1 1 x != 0 correct 2 x != 0 && y == 0 incorrect2 x != 0 && y != 0 correct 3 3 x == y correct -
src/tests/div.c
r800d275 r235b41f 1 // -*- Mode: C -*-2 1 // 3 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo … … 11 10 // Created On : Tue Aug 8 16:28:43 2017 12 11 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Wed Aug 9 17:09:40201714 // Update Count : 1 612 // Last Modified On : Wed Aug 30 07:56:28 2017 13 // Update Count : 17 15 14 // 16 15 -
src/tests/dtor-early-exit.c
r800d275 r235b41f 220 220 } 221 221 222 // TODO: implement __label__ and uncomment these lines 223 void computedGoto() { 224 // __label__ bar; 225 void *ptr; 226 ptr = &&foo; 227 goto *ptr; 228 assert(false); 229 foo: ; 230 // void f() { 231 // ptr = &&bar; 232 // goto *ptr; 233 // assert(false); 234 // } 235 // f(); 236 // assert(false); 237 // bar: ; 238 } 239 222 240 int main() { 223 241 sepDisable(sout); … … 229 247 sout | endl; 230 248 h(); 249 250 computedGoto(); 231 251 } 232 252 -
src/tests/gmp.c
r800d275 r235b41f 10 10 // Created On : Tue Apr 19 08:55:51 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 25 12:50:01201713 // Update Count : 5 4412 // Last Modified On : Mon Sep 4 09:51:18 2017 13 // Update Count : 550 14 14 // 15 15 … … 29 29 sout | "y:" | y | endl; 30 30 y = "12345678901234567890123456789"; 31 sout | "y:" | y | endl; 32 y = 100`mp + 100`mp; 33 sout | "y:" | y | endl; 34 y = -200u`mp + -200u`mp; 35 sout | "y:" | y | endl; 36 y = "12345678901234567890123456789"`mp + "12345678901234567890123456789"`mp; 31 37 sout | "y:" | y | endl; 32 38 y = si; -
src/tests/ifcond.c
r800d275 r235b41f 1 // -*- Mode: C -*- 2 // 1 // 3 2 // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo 4 3 // 5 4 // The contents of this file are covered under the licence agreement in the 6 5 // file "LICENCE" distributed with Cforall. 7 // 8 // ifcond.c -- 9 // 6 // 7 // ifcond.c -- 8 // 10 9 // Author : Peter A. Buhr 11 10 // Created On : Sat Aug 26 10:13:11 2017 12 // Last Modified By : Peter A. Buhr13 // Last Modified On : Tue Aug 29 08:25:02201714 // Update Count : 1 215 // 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Sep 01 15:22:19 2017 13 // Update Count : 14 14 // 16 15 17 #include <fstream>16 #include <fstream> 18 17 19 18 int f( int r ) { return r; } … … 28 27 } // if 29 28 30 if ( int x = 4, y = 0 ) { // FIXME && distribution 29 if ( int x = 4, y = 0 ) { 30 sout | "x != 0 && y != 0 incorrect" | endl; 31 } else if ( int x = 4, y = 1 ) { 31 32 sout | "x != 0 && y != 0 correct" | endl; 32 33 sout | "x != 0 &&y == 0 incorrect" | endl;33 } else { 34 sout | "x == 0 || y == 0 incorrect" | endl; 34 35 } // if 35 36 -
src/tests/stdincludes.c
r800d275 r235b41f 1 // -*- Mode: C++ -*-2 1 // 3 2 // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo … … 11 10 // Created On : Tue Aug 29 08:26:14 2017 12 11 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Tue Aug 29 08:52:11201714 // Update Count : 412 // Last Modified On : Wed Aug 30 07:56:39 2017 13 // Update Count : 5 15 14 // 16 15 -
tools/prettyprinter/lex.ll
r800d275 r235b41f 7 7 * lex.ll -- 8 8 * 9 * Author : Rodolfo Gabriel Esteves9 * Author : Peter A. Buhr 10 10 * Created On : Sat Dec 15 11:45:59 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Fri Jul 21 23:06:16 201713 * Update Count : 2 5412 * Last Modified On : Tue Aug 29 17:33:36 2017 13 * Update Count : 268 14 14 */ 15 15 16 16 %option stack 17 17 %option yylineno 18 %option nounput 18 19 19 20 %{ … … 30 31 string comment_str; 31 32 string code_str; 33 34 // Stop warning due to incorrectly generated flex code. 35 #pragma GCC diagnostic ignored "-Wsign-compare" 32 36 %} 33 37 … … 44 48 /* ---------------------------- Token Section ---------------------------- */ 45 49 %% 46 <INITIAL,C_CODE>"/*" { /* C style comments */ 47 #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT) 48 cerr << "\"/*\" : " << yytext << endl; 49 #endif 50 if ( YYSTATE == C_CODE ) code_str += yytext; 51 else comment_str += yytext; 52 yy_push_state(C_COMMENT); 53 } 54 <C_COMMENT>(.|"\n") { /* C style comments */ 55 #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT) 56 cerr << "<C_COMMENT>(.|\\n) : " << yytext << endl; 57 #endif 58 if ( yy_top_state() == C_CODE ) code_str += yytext; 59 else comment_str += yytext; 60 } 61 <C_COMMENT>"*/" { /* C style comments */ 62 #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT) 63 cerr << "<C_COMMENT>\"*/\" : " << yytext << endl; 64 #endif 65 if ( yy_top_state() == C_CODE ) code_str += yytext; 66 else { 67 comment_str += yytext; 68 //cerr << "C COMMENT : " << endl << comment_str << endl; 69 ws_list.push_back( comment_str ); 70 comment_str = ""; 71 } 72 yy_pop_state(); 73 } 74 <INITIAL,C_CODE>"//"[^\n]*"\n" { /* C++ style comments */ 75 #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT) 76 cerr << "\"//\"[^\\n]*\"\n\" : " << yytext << endl; 77 #endif 78 if ( YYSTATE == C_CODE ) code_str += yytext; 79 else { 80 comment_str += yytext; 81 //cerr << "C++ COMMENT : " << endl << comment_str << endl; 82 ws_list.push_back( comment_str ); 83 comment_str = ""; 84 } 85 } 50 <INITIAL,C_CODE>"/*" { // C style comments */ 51 #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT) 52 cerr << "\"/*\" : " << yytext << endl; 53 #endif 54 if ( YYSTATE == C_CODE ) code_str += yytext; 55 else comment_str += yytext; 56 yy_push_state(C_COMMENT); 57 } 58 <C_COMMENT>(.|"\n") { // C style comments 59 #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT) 60 cerr << "<C_COMMENT>(.|\\n) : " << yytext << endl; 61 #endif 62 if ( yy_top_state() == C_CODE ) code_str += yytext; 63 else comment_str += yytext; 64 } 65 <C_COMMENT>"*/" { // C style comments 66 #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT) 67 cerr << "<C_COMMENT>\"*/\" : " << yytext << endl; 68 #endif 69 if ( yy_top_state() == C_CODE ) code_str += yytext; 70 else { 71 comment_str += yytext; 72 //cerr << "C COMMENT : " << endl << comment_str << endl; 73 ws_list.push_back( comment_str ); 74 comment_str = ""; 75 } 76 yy_pop_state(); 77 } 86 78 87 ";" { RETURN_TOKEN( ';' ) } 88 ":" { RETURN_TOKEN( ':' ) } 89 "|" { RETURN_TOKEN( '|' ) } 90 "," { RETURN_TOKEN( ',' ) } 91 "<" { RETURN_TOKEN( '<' ) } 92 ">" { RETURN_TOKEN( '>' ) } 79 <INITIAL,C_CODE>"//"[^\n]*"\n" { // C++ style comments 80 #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT) 81 cerr << "\"//\"[^\\n]*\"\n\" : " << yytext << endl; 82 #endif 83 if ( YYSTATE == C_CODE ) code_str += yytext; 84 else { 85 comment_str += yytext; 86 //cerr << "C++ COMMENT : " << endl << comment_str << endl; 87 ws_list.push_back( comment_str ); 88 comment_str = ""; 89 } 90 } 93 91 94 [[:space:]]+ { /* [ \t\n]+ */ 95 ws_list.push_back( yytext ); 96 //cerr << "WS : " << "\"" << yytext << "\"" << endl; 97 } 92 ";" { RETURN_TOKEN( ';' ) } 93 ":" { RETURN_TOKEN( ':' ) } 94 "|" { RETURN_TOKEN( '|' ) } 95 "," { RETURN_TOKEN( ',' ) } 96 "<" { RETURN_TOKEN( '<' ) } 97 ">" { RETURN_TOKEN( '>' ) } 98 98 99 <INITIAL>"{" { RETURN_TOKEN( '{' ) } 100 <INITIAL>"}" { RETURN_TOKEN( '}' ) } 101 <C_CODE>"{" { 102 #if defined(DEBUG_ALL) | defined(DEBUG_C) 103 cerr << "<C_CODE>. : " << yytext << endl; 104 #endif 105 code_str += yytext; 106 RETURN_TOKEN( '{' ) 107 } 108 <C_CODE>"}" { 109 #if defined(DEBUG_ALL) | defined(DEBUG_C) 110 cerr << "<C_CODE>. : " << yytext << endl; 111 #endif 112 code_str += yytext; 113 RETURN_TOKEN( '}' ) 114 } 99 [[:space:]]+ { // [ \t\n]+ 100 ws_list.push_back( yytext ); 101 //cerr << "WS : " << "\"" << yytext << "\"" << endl; 102 } 103 104 <INITIAL>"{" { RETURN_TOKEN( '{' ) } 105 <INITIAL>"}" { RETURN_TOKEN( '}' ) } 106 <C_CODE>"{" { 107 #if defined(DEBUG_ALL) | defined(DEBUG_C) 108 cerr << "<C_CODE>. : " << yytext << endl; 109 #endif 110 code_str += yytext; 111 RETURN_TOKEN( '{' ) 112 } 113 <C_CODE>"}" { 114 #if defined(DEBUG_ALL) | defined(DEBUG_C) 115 cerr << "<C_CODE>. : " << yytext << endl; 116 #endif 117 code_str += yytext; 118 RETURN_TOKEN( '}' ) 119 } 115 120 116 121 "%%" { RETURN_TOKEN( MARK ) } 117 122 "%{" { RETURN_TOKEN( LCURL ) } 118 <C_CODE>"%}" 123 <C_CODE>"%}" { RETURN_TOKEN( RCURL ) } 119 124 120 ^"%union" { RETURN_TOKEN( UNION ) } 121 ^"%start" { RETURN_TOKEN( START ) } 122 ^"%token" { RETURN_TOKEN( TOKEN ) } 123 ^"%type" { RETURN_TOKEN( TYPE ) } 124 ^"%left" { RETURN_TOKEN( LEFT ) } 125 ^"%right" { RETURN_TOKEN( RIGHT ) } 126 ^"%nonassoc" { RETURN_TOKEN( NONASSOC ) } 127 ^"%pure_parser" { RETURN_TOKEN( PURE_PARSER ) } 128 ^"%semantic_parser" { RETURN_TOKEN( SEMANTIC_PARSER ) } 129 ^"%expect" { RETURN_TOKEN( EXPECT ) } 125 ^"%union" { RETURN_TOKEN( UNION ) } 126 ^"%start" { RETURN_TOKEN( START ) } 127 ^"%token" { RETURN_TOKEN( TOKEN ) } 128 ^"%type" { RETURN_TOKEN( TYPE ) } 129 ^"%left" { RETURN_TOKEN( LEFT ) } 130 ^"%right" { RETURN_TOKEN( RIGHT ) } 131 ^"%nonassoc" { RETURN_TOKEN( NONASSOC ) } 132 ^"%precedence" { RETURN_TOKEN( PRECEDENCE ) } 133 ^"%pure_parser" { RETURN_TOKEN( PURE_PARSER ) } 134 ^"%semantic_parser" { RETURN_TOKEN( SEMANTIC_PARSER ) } 135 ^"%expect" { RETURN_TOKEN( EXPECT ) } 130 136 ^"%thong" { RETURN_TOKEN( THONG ) } 131 137 132 138 "%prec" { RETURN_TOKEN( PREC ) } 133 139 134 {integer} 135 [']{c_char}['] 136 {identifier} 140 {integer} { RETURN_TOKEN( INTEGER ); } 141 [']{c_char}['] { RETURN_TOKEN( CHARACTER ); } 142 {identifier} { RETURN_TOKEN( IDENTIFIER ); } 137 143 138 <C_CODE>["]{s_char}*["] { /* hide braces "{}" in strings */139 140 141 142 143 144 <C_CODE>["]{s_char}*["] { // hide braces "{}" in strings 145 #if defined(DEBUG_ALL) | defined(DEBUG_C) 146 cerr << "<C_CODE>. : " << yytext << endl; 147 #endif 148 code_str += yytext; 149 } 144 150 145 <C_CODE>(.|\n) { /* must be last rule of C_CODE */146 147 148 149 150 151 <C_CODE>(.|\n) { // must be last rule of C_CODE 152 #if defined(DEBUG_ALL) | defined(DEBUG_C) 153 cerr << "<C_CODE>. : " << yytext << endl; 154 #endif 155 code_str += yytext; 156 } 151 157 152 . { printf("UNKNOWN CHARACTER:%s\n", yytext); } /* unknown characters */ 158 /* unknown characters */ 159 . { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); } 153 160 %% 154 161 void lexC(void) { -
tools/prettyprinter/parser.hh
r800d275 r235b41f 59 59 RIGHT = 269, 60 60 NONASSOC = 270, 61 TYPE = 271, 62 PURE_PARSER = 272, 63 SEMANTIC_PARSER = 273, 64 EXPECT = 274, 65 THONG = 275, 66 PREC = 276, 67 END_TERMINALS = 277, 68 _SECTIONS = 278, 69 _DEFSECTION_OPT = 279, 70 _LITERALBLOCK = 280, 71 _DECLARATION = 281, 72 _TAG_OPT = 282, 73 _NAMENOLIST = 283, 74 _NAMENO = 284, 75 _NAMELIST = 285, 76 _RULESECTION = 286, 77 _RULE = 287, 78 _LHS = 288, 79 _RHS = 289, 80 _PREC = 290, 81 _ACTION = 291, 82 _USERSECTION_OPT = 292 61 PRECEDENCE = 271, 62 TYPE = 272, 63 PURE_PARSER = 273, 64 SEMANTIC_PARSER = 274, 65 EXPECT = 275, 66 THONG = 276, 67 PREC = 277, 68 END_TERMINALS = 278, 69 _SECTIONS = 279, 70 _DEFSECTION_OPT = 280, 71 _LITERALBLOCK = 281, 72 _DECLARATION = 282, 73 _TAG_OPT = 283, 74 _NAMENOLIST = 284, 75 _NAMENO = 285, 76 _NAMELIST = 286, 77 _RULESECTION = 287, 78 _RULE = 288, 79 _LHS = 289, 80 _RHS = 290, 81 _PREC = 291, 82 _ACTION = 292, 83 _USERSECTION_OPT = 293 83 84 }; 84 85 #endif … … 97 98 #define RIGHT 269 98 99 #define NONASSOC 270 99 #define TYPE 271 100 #define PURE_PARSER 272 101 #define SEMANTIC_PARSER 273 102 #define EXPECT 274 103 #define THONG 275 104 #define PREC 276 105 #define END_TERMINALS 277 106 #define _SECTIONS 278 107 #define _DEFSECTION_OPT 279 108 #define _LITERALBLOCK 280 109 #define _DECLARATION 281 110 #define _TAG_OPT 282 111 #define _NAMENOLIST 283 112 #define _NAMENO 284 113 #define _NAMELIST 285 114 #define _RULESECTION 286 115 #define _RULE 287 116 #define _LHS 288 117 #define _RHS 289 118 #define _PREC 290 119 #define _ACTION 291 120 #define _USERSECTION_OPT 292 100 #define PRECEDENCE 271 101 #define TYPE 272 102 #define PURE_PARSER 273 103 #define SEMANTIC_PARSER 274 104 #define EXPECT 275 105 #define THONG 276 106 #define PREC 277 107 #define END_TERMINALS 278 108 #define _SECTIONS 279 109 #define _DEFSECTION_OPT 280 110 #define _LITERALBLOCK 281 111 #define _DECLARATION 282 112 #define _TAG_OPT 283 113 #define _NAMENOLIST 284 114 #define _NAMENO 285 115 #define _NAMELIST 286 116 #define _RULESECTION 287 117 #define _RULE 288 118 #define _LHS 289 119 #define _RHS 290 120 #define _PREC 291 121 #define _ACTION 292 122 #define _USERSECTION_OPT 293 121 123 122 124 /* Value type. */ … … 129 131 Token *tokenp; 130 132 131 #line 13 2"parser.hh" /* yacc.c:1909 */133 #line 134 "parser.hh" /* yacc.c:1909 */ 132 134 }; 133 135 -
tools/prettyprinter/parser.yy
r800d275 r235b41f 10 10 // Created On : Sat Dec 15 13:44:21 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Jun 29 09:26:47201713 // Update Count : 104 512 // Last Modified On : Tue Aug 29 16:34:10 2017 13 // Update Count : 1047 14 14 // 15 15 … … 67 67 %token<tokenp> RIGHT // %right 68 68 %token<tokenp> NONASSOC // %nonassoc 69 %token<tokenp> PRECEDENCE // %precedence 69 70 %token<tokenp> TYPE // %type 70 71 %token<tokenp> PURE_PARSER // %pure_parser … … 259 260 | RIGHT 260 261 | NONASSOC 262 | PRECEDENCE 261 263 ; 262 264
Note: See TracChangeset
for help on using the changeset viewer.