Changeset 1cdfa82 for src/Common
- Timestamp:
- Apr 25, 2018, 4:55:53 PM (8 years ago)
- Branches:
- new-env, with_gc
- Children:
- 42107b4
- Parents:
- 2efe4b8 (diff), 9d5fb67 (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. - Location:
- src/Common
- Files:
-
- 7 edited
-
Debug.h (modified) (1 diff)
-
ErrorObjects.h (modified) (1 diff)
-
PassVisitor.h (modified) (4 diffs)
-
PassVisitor.impl.h (modified) (4 diffs)
-
SemanticError.cc (modified) (1 diff)
-
SemanticError.h (modified) (3 diffs)
-
utility.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/Debug.h
r2efe4b8 r1cdfa82 28 28 namespace Debug { 29 29 /// debug codegen a translation unit 30 static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label ) {30 static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) { 31 31 #ifdef DEBUG 32 32 std::list< Declaration * > decls; 33 33 34 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), [ ]( Declaration * decl ) {35 return ! LinkageSpec::isBuiltin( decl->get_linkage());34 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), [linkageFilter]( Declaration * decl ) { 35 return ! (decl->linkage & linkageFilter); 36 36 }); 37 37 38 38 std::cerr << "======" << label << "======" << std::endl; 39 CodeGen::generate( decls, std::cerr, false, true ); 39 CodeGen::generate( 40 decls, 41 std::cerr, 42 true /* doIntrinsics */, 43 true /* pretty */, 44 false /* generateC */, 45 false /* lineMarks */, 46 true /* printTypeExpr */ 47 ); 40 48 #endif 41 49 } // dump 42 50 43 static inline void treeDump( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label ) {51 static inline void treeDump( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) { 44 52 #ifdef DEBUG 45 53 std::list< Declaration * > decls; 46 54 47 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), [ ]( Declaration * decl ) {48 return ! LinkageSpec::isBuiltin( decl->get_linkage());55 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), [linkageFilter]( Declaration * decl ) { 56 return ! (decl->linkage & linkageFilter); 49 57 }); 50 58 -
src/Common/ErrorObjects.h
r2efe4b8 r1cdfa82 35 35 class SemanticErrorException : public std::exception { 36 36 public: 37 SemanticErrorException() = default;37 SemanticErrorException() = default; 38 38 SemanticErrorException( CodeLocation location, std::string error ); 39 39 ~SemanticErrorException() throw() {} -
src/Common/PassVisitor.h
r2efe4b8 r1cdfa82 66 66 virtual void visit( TypedefDecl * typeDecl ) override final; 67 67 virtual void visit( AsmDecl * asmDecl ) override final; 68 virtual void visit( StaticAssertDecl * assertDecl ) override final; 68 69 69 70 virtual void visit( CompoundStmt * compoundStmt ) override final; … … 91 92 virtual void visit( NameExpr * nameExpr ) override final; 92 93 virtual void visit( CastExpr * castExpr ) override final; 94 virtual void visit( KeywordCastExpr * castExpr ) override final; 93 95 virtual void visit( VirtualCastExpr * castExpr ) override final; 94 96 virtual void visit( AddressExpr * addressExpr ) override final; … … 163 165 virtual Declaration * mutate( TypedefDecl * typeDecl ) override final; 164 166 virtual AsmDecl * mutate( AsmDecl * asmDecl ) override final; 167 virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) override final; 165 168 166 169 virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) override final; … … 187 190 virtual Expression * mutate( UntypedExpr * untypedExpr ) override final; 188 191 virtual Expression * mutate( NameExpr * nameExpr ) override final; 189 virtual Expression * mutate( AddressExpr * castExpr ) override final;192 virtual Expression * mutate( AddressExpr * addrExpr ) override final; 190 193 virtual Expression * mutate( LabelAddressExpr * labAddressExpr ) override final; 191 194 virtual Expression * mutate( CastExpr * castExpr ) override final; 195 virtual Expression * mutate( KeywordCastExpr * castExpr ) override final; 192 196 virtual Expression * mutate( VirtualCastExpr * castExpr ) override final; 193 197 virtual Expression * mutate( UntypedMemberExpr * memberExpr ) override final; -
src/Common/PassVisitor.impl.h
r2efe4b8 r1cdfa82 685 685 686 686 //-------------------------------------------------------------------------- 687 // StaticAssertDecl 688 template< typename pass_type > 689 void PassVisitor< pass_type >::visit( StaticAssertDecl * node ) { 690 VISIT_START( node ); 691 692 maybeAccept_impl( node->condition, *this ); 693 maybeAccept_impl( node->message , *this ); 694 695 VISIT_END( node ); 696 } 697 698 template< typename pass_type > 699 StaticAssertDecl * PassVisitor< pass_type >::mutate( StaticAssertDecl * node ) { 700 MUTATE_START( node ); 701 702 maybeMutate_impl( node->condition, *this ); 703 maybeMutate_impl( node->message , *this ); 704 705 MUTATE_END( StaticAssertDecl, node ); 706 } 707 708 //-------------------------------------------------------------------------- 687 709 // CompoundStmt 688 710 template< typename pass_type > … … 1238 1260 1239 1261 //-------------------------------------------------------------------------- 1262 // KeywordCastExpr 1263 template< typename pass_type > 1264 void PassVisitor< pass_type >::visit( KeywordCastExpr * node ) { 1265 VISIT_START( node ); 1266 1267 indexerScopedAccept( node->result, *this ); 1268 maybeAccept_impl ( node->arg , *this ); 1269 1270 VISIT_END( node ); 1271 } 1272 1273 template< typename pass_type > 1274 Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) { 1275 MUTATE_START( node ); 1276 1277 indexerScopedMutate( node->env , *this ); 1278 indexerScopedMutate( node->result, *this ); 1279 maybeMutate_impl ( node->arg , *this ); 1280 1281 MUTATE_END( Expression, node ); 1282 } 1283 1284 //-------------------------------------------------------------------------- 1240 1285 // VirtualCastExpr 1241 1286 template< typename pass_type > … … 1491 1536 indexerScopedAccept( node->result, *this ); 1492 1537 maybeAccept_impl ( node->type , *this ); 1493 maybeAccept_impl ( node->member, *this );1494 1538 1495 1539 VISIT_END( node ); … … 1503 1547 indexerScopedMutate( node->result, *this ); 1504 1548 maybeMutate_impl ( node->type , *this ); 1505 maybeMutate_impl ( node->member, *this );1506 1549 1507 1550 MUTATE_END( Expression, node ); -
src/Common/SemanticError.cc
r2efe4b8 r1cdfa82 68 68 } 69 69 70 void SemanticWarningImpl( CodeLocation location, Warning, const char * const fmt, ... ) { 71 va_list args; 72 va_start(args, fmt); 73 std::string msg = fmtToString( fmt, args ); 74 va_end(args); 75 std::cerr << ErrorHelpers::bold() << location << ErrorHelpers::warning_str() << ErrorHelpers::reset_font() << msg << std::endl; 70 void SemanticWarningImpl( CodeLocation location, Warning warning, const char * const fmt, ... ) { 71 Severity severity = WarningFormats[(int)warning].severity; 72 switch(severity) { 73 case Severity::Suppress : 74 break; 75 case Severity::Warn : 76 { 77 va_list args; 78 va_start(args, fmt); 79 std::string msg = fmtToString( fmt, args ); 80 va_end(args); 81 std::cerr << ErrorHelpers::bold() << location << ErrorHelpers::warning_str() << ErrorHelpers::reset_font() << msg << std::endl; 82 } 83 break; 84 case Severity::Error : 85 { 86 va_list args; 87 va_start(args, fmt); 88 std::string msg = fmtToString( fmt, args ); 89 va_end(args); 90 SemanticError(location, msg); 91 } 92 break; 93 case Severity::Critical : 94 assertf(false, "Critical errors not implemented yet"); 95 break; 96 } 76 97 } 77 98 -
src/Common/SemanticError.h
r2efe4b8 r1cdfa82 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Aug 29 22:03:36 201713 // Update Count : 1 712 // Last Modified On : Thu Apr 19 17:52:03 2018 13 // Update Count : 19 14 14 // 15 15 … … 36 36 // Warnings 37 37 38 constexpr const char * const WarningFormats[] = { 39 "self assignment of expression: %s", 38 enum class Severity { 39 Suppress, 40 Warn, 41 Error, 42 Critical 43 }; 44 45 struct WarningData { 46 const char * const name; 47 const char * const message; 48 mutable Severity severity; 49 }; 50 51 constexpr const WarningData WarningFormats[] = { 52 {"self-assign" , "self assignment of expression: %s" , Severity::Warn}, 53 {"reference-conversion", "rvalue to reference conversion of rvalue: %s", Severity::Warn}, 54 {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn}, 40 55 }; 41 56 42 57 enum class Warning { 43 58 SelfAssignment, 59 RvalueToReferenceConversion, 60 BadQualifiersZeroOne, 44 61 NUMBER_OF_WARNINGS, //This MUST be the last warning 45 62 }; … … 50 67 ); 51 68 52 #define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id] , __VA_ARGS__)69 #define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id].message, __VA_ARGS__) 53 70 54 71 void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4))); -
src/Common/utility.h
r2efe4b8 r1cdfa82 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 : Thr Aug 17 11:38:00 201713 // Update Count : 3 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 20 22:35:33 2018 13 // Update Count : 38 14 14 // 15 15 … … 433 433 } 434 434 435 // ----------------------------------------------------------------------------- 436 // O(1) polymorphic integer ilog2, using clz, which returns the number of leading 0-bits, starting at the most 437 // significant bit (single instruction on x86) 438 439 template<typename T> 440 inline constexpr T ilog2(const T & t) { 441 if ( std::is_integral<T>::value ) { 442 const constexpr int r = sizeof(t) * __CHAR_BIT__ - 1; 443 if ( sizeof(T) == sizeof(unsigned int ) ) return r - __builtin_clz( t ); 444 if ( sizeof(T) == sizeof(unsigned long) ) return r - __builtin_clzl( t ); 445 if ( sizeof(T) == sizeof(unsigned long long) ) return r - __builtin_clzll( t ); 446 } // if 447 return -1; 448 } // ilong2 435 449 436 450
Note:
See TracChangeset
for help on using the changeset viewer.