Changes in / [e58dfb9:35cd219]
- Location:
- src
- Files:
-
- 1 added
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/SemanticError.cc
re58dfb9 r35cd219 22 22 #include "SemanticError.h" 23 23 24 #include <unistd.h> 25 26 inline const std::string& error_str() { 27 static std::string str = isatty( fileno(stderr) ) ? "\e[31merror:\e[39m " : "error: "; 28 return str; 29 } 30 24 31 SemanticError::SemanticError() { 25 32 } 26 33 27 34 SemanticError::SemanticError( std::string error ) { 28 35 append( error ); 29 36 } 30 37 31 38 void SemanticError::append( SemanticError &other ) { 32 39 errors.splice( errors.end(), other.errors ); 33 40 } 34 41 35 42 void SemanticError::append( const std::string & msg ) { 36 errors.push_back( std::string( "Error: ") + msg );43 errors.emplace_back( error_str() + msg ); 37 44 } 38 45 … … 42 49 43 50 void SemanticError::print( std::ostream &os ) { 44 std::copy( errors.begin(), errors.end(), std::ostream_iterator< std::string >( os, "\n" ) ); 51 using std::to_string; 52 for(auto err : errors) { 53 os << to_string( err.location ) << err.description << '\n'; 54 } 55 } 56 57 void SemanticError::set_location( const CodeLocation& location ) { 58 errors.begin()->maybeSet( location ); 45 59 } 46 60 -
src/Common/SemanticError.h
re58dfb9 r35cd219 23 23 #include <iostream> 24 24 25 #include "utility.h" 26 27 struct error { 28 std::string description; 29 CodeLocation location; 30 31 error() = default; 32 error( const std::string& str ) : description( str ) {} 33 34 void maybeSet( const CodeLocation& location ) { 35 if( this->location.linenumber < 0 ) { 36 this->location = location; 37 } 38 } 39 }; 40 25 41 class SemanticError : public std::exception { 26 42 public: … … 35 51 void print( std::ostream &os ); 36 52 53 void set_location( const CodeLocation& location ); 37 54 // constructs an exception using the given message and the printed 38 55 // representation of the obj (T must have a print method) 39 56 private: 40 std::list< std::string> errors;57 std::list< error > errors; 41 58 }; 42 59 -
src/Common/utility.h
re58dfb9 r35cd219 25 25 #include <sstream> 26 26 #include <string> 27 27 28 #include <cassert> 28 29 29 template< typename T > 30 30 static inline T * maybeClone( const T *orig ) { … … 303 303 return group_iterate_t<Args...>(args...); 304 304 } 305 306 struct CodeLocation { 307 int linenumber; 308 std::string filename; 309 310 CodeLocation() 311 : linenumber( -1 ) 312 , filename("") 313 {} 314 315 CodeLocation( const char* filename, int lineno ) 316 : linenumber( lineno ) 317 , filename(filename ? filename : "") 318 {} 319 }; 320 321 inline std::string to_string( const CodeLocation& location ) { 322 return location.linenumber >= 0 ? location.filename + ":" + std::to_string(location.linenumber) + " " : ""; 323 } 305 324 #endif // _UTILITY_H 306 325 -
src/GenPoly/Box.cc
re58dfb9 r35cd219 236 236 } // if 237 237 } catch( SemanticError &e ) { 238 e.set_location( (*i)->location ); 238 239 errors.append( e ); 239 240 } // try -
src/InitTweak/FixInit.cc
re58dfb9 r35cd219 313 313 translationUnit.splice( i, fixer.staticDtorDecls ); 314 314 } catch( SemanticError &e ) { 315 e.set_location( (*i)->location ); 315 316 errors.append( e ); 316 317 } // try -
src/Parser/DeclarationNode.cc
re58dfb9 r35cd219 921 921 Declaration * decl = extr->build(); 922 922 if ( decl ) { 923 decl->location = cur->location; 923 924 * out++ = decl; 924 925 } // if … … 928 929 Declaration * decl = cur->build(); 929 930 if ( decl ) { 931 decl->location = cur->location; 930 932 * out++ = decl; 931 933 } // if 932 934 } catch( SemanticError &e ) { 935 e.set_location( cur->location ); 933 936 errors.append( e ); 934 937 } // try … … 950 953 if ( decl ) { 951 954 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 955 dwt->location = cur->location; 952 956 * out++ = dwt; 953 957 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) { 954 958 StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 955 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr ); 959 auto obj = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr ); 960 obj->location = cur->location; 961 * out++ = obj; 956 962 delete agg; 957 963 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) { 958 964 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 959 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr ); 965 auto obj = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr ); 966 obj->location = cur->location; 967 * out++ = obj; 960 968 } // if 961 969 } // if 962 970 } catch( SemanticError &e ) { 971 e.set_location( cur->location ); 963 972 errors.append( e ); 964 973 } // try … … 979 988 * out++ = cur->buildType(); 980 989 } catch( SemanticError &e ) { 990 e.set_location( cur->location ); 981 991 errors.append( e ); 982 992 } // try -
src/Parser/ParseNode.h
re58dfb9 r35cd219 39 39 //############################################################################## 40 40 41 extern char* yyfilename; 42 extern int yylineno; 43 41 44 class ParseNode { 42 45 public: … … 65 68 ParseNode * next = nullptr; 66 69 std::string * name = nullptr; 70 CodeLocation location = { yyfilename, yylineno }; 67 71 }; // ParseNode 68 72 … … 410 414 while ( cur ) { 411 415 try { 412 // SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) );413 416 SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) ); 414 417 if ( result ) { 418 result->location = cur->location; 415 419 * out++ = result; 416 420 } // if 417 421 } catch( SemanticError &e ) { 422 e.set_location( cur->location ); 418 423 errors.append( e ); 419 424 } // try -
src/ResolvExpr/Resolver.cc
re58dfb9 r35cd219 86 86 Resolver resolver; 87 87 acceptAll( translationUnit, resolver ); 88 #if 089 resolver.print( cerr );90 for ( std::list< Declaration * >::iterator i = translationUnit.begin(); i != translationUnit.end(); ++i ) {91 (*i)->print( std::cerr );92 (*i)->accept( resolver );93 } // for94 #endif95 88 } 96 89 -
src/SynTree/Declaration.h
re58dfb9 r35cd219 17 17 #define DECLARATION_H 18 18 19 #include <string> 20 21 #include "BaseSyntaxNode.h" 22 #include "Mutator.h" 23 #include "Visitor.h" 19 24 #include "SynTree.h" 20 #include "Visitor.h"21 #include "Mutator.h"22 25 #include "Parser/LinkageSpec.h" 23 26 #include "Parser/ParseNode.h" 24 #include <string> 25 26 class Declaration { 27 28 class Declaration : public BaseSyntaxNode { 27 29 public: 28 30 Declaration( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage ); -
src/SynTree/Expression.h
re58dfb9 r35cd219 19 19 #include <map> 20 20 #include <memory> 21 22 #include "BaseSyntaxNode.h" 23 #include "Constant.h" 24 #include "Mutator.h" 21 25 #include "SynTree.h" 22 26 #include "Visitor.h" 23 #include "Mutator.h"24 #include "Constant.h"25 27 #include "Common/UniqueName.h" 26 28 27 29 /// Expression is the root type for all expressions 28 class Expression {30 class Expression : public BaseSyntaxNode{ 29 31 public: 30 32 Expression( Expression * _aname = nullptr ); -
src/SynTree/Initializer.h
re58dfb9 r35cd219 17 17 #define INITIALIZER_H 18 18 19 #include <cassert> 20 21 #include "BaseSyntaxNode.h" 22 #include "Mutator.h" 19 23 #include "SynTree.h" 24 #include "Type.h" 20 25 #include "Visitor.h" 21 #include "Mutator.h"22 #include "Type.h"23 24 #include <cassert>25 26 26 27 const std::list<Expression*> noDesignators; 27 28 28 29 // Initializer: base class for object initializers (provide default values) 29 class Initializer {30 class Initializer : public BaseSyntaxNode { 30 31 public: 31 32 // Initializer( std::string _name = std::string(""), int _pos = 0 ); -
src/SynTree/Mutator.h
re58dfb9 r35cd219 139 139 } // if 140 140 } catch( SemanticError &e ) { 141 e.set_location( (*i)->location ); 141 142 errors.append( e ); 142 143 } // try -
src/SynTree/Statement.h
re58dfb9 r35cd219 17 17 #define STATEMENT_H 18 18 19 #include "BaseSyntaxNode.h" 20 #include "Label.h" 21 #include "Mutator.h" 19 22 #include "SynTree.h" 23 #include "Type.h" 20 24 #include "Visitor.h" 21 #include "Mutator.h"22 25 #include "Common/SemanticError.h" 23 #include "Type.h" 24 #include "Label.h" 25 26 class Statement { 26 27 class Statement : public BaseSyntaxNode { 27 28 public: 28 29 Statement( std::list<Label> labels ); -
src/SynTree/Type.h
re58dfb9 r35cd219 17 17 #define TYPE_H 18 18 19 #include "BaseSyntaxNode.h" 20 #include "Mutator.h" 19 21 #include "SynTree.h" 20 22 #include "Visitor.h" 21 #include "Mutator.h"22 23 #include "Common/utility.h" 23 24 24 class Type {25 class Type : public BaseSyntaxNode { 25 26 public: 26 27 struct Qualifiers { -
src/SynTree/Visitor.h
re58dfb9 r35cd219 133 133 } 134 134 } catch( SemanticError &e ) { 135 e.set_location( (*i)->location ); 135 136 errors.append( e ); 136 137 } … … 159 160 } // if 160 161 } catch( SemanticError &e ) { 162 e.set_location( (*i)->location ); 161 163 errors.append( e ); 162 164 } // try -
src/tests/.expect/castError.txt
re58dfb9 r35cd219 1 Error: Can't choose between 3 alternatives for expression Cast of:1 castError.c:7 error: Can't choose between 3 alternatives for expression Cast of: 2 2 Name: f 3 3 -
src/tests/.expect/completeTypeError.txt
re58dfb9 r35cd219 1 Error: No reasonable alternatives for expression Applying untyped:1 completeTypeError.c:34 error: No reasonable alternatives for expression Applying untyped: 2 2 Name: *? 3 3 ...to: … … 5 5 6 6 7 Error: No reasonable alternatives for expression Applying untyped:7 completeTypeError.c:36 error: No reasonable alternatives for expression Applying untyped: 8 8 Name: baz 9 9 ...to: … … 11 11 12 12 13 Error: No reasonable alternatives for expression Applying untyped:13 completeTypeError.c:37 error: No reasonable alternatives for expression Applying untyped: 14 14 Name: quux 15 15 ...to: … … 17 17 18 18 19 Error: No reasonable alternatives for expression Applying untyped:19 completeTypeError.c:58 error: No reasonable alternatives for expression Applying untyped: 20 20 Name: baz 21 21 ...to: … … 23 23 24 24 25 Error: No reasonable alternatives for expression Applying untyped:25 completeTypeError.c:59 error: No reasonable alternatives for expression Applying untyped: 26 26 Name: quux 27 27 ...to: … … 29 29 30 30 31 Error: No reasonable alternatives for expression Applying untyped:31 completeTypeError.c:60 error: No reasonable alternatives for expression Applying untyped: 32 32 Name: *? 33 33 ...to: … … 35 35 36 36 37 Error: No reasonable alternatives for expression Applying untyped:37 completeTypeError.c:72 error: No reasonable alternatives for expression Applying untyped: 38 38 Name: baz 39 39 ...to: -
src/tests/.expect/constant0-1DP.txt
re58dfb9 r35cd219 1 Error: duplicate object definition for 0: signed int2 Error: duplicate object definition for 0: const signed int3 Error: duplicate object definition for 1: signed int4 Error: duplicate object definition for 1: const signed int5 Error: duplicate object definition for 0: signed int6 Error: duplicate object definition for 1: signed int7 Error: duplicate object definition for 0: signed int8 Error: duplicate object definition for 1: signed int9 Error: duplicate object definition for 0: const signed int10 Error: duplicate object definition for 1: const signed int11 Error: duplicate object definition for 0: const signed int12 Error: duplicate object definition for 1: const signed int13 Error: duplicate object definition for 0: pointer to signed int14 Error: duplicate object definition for 1: pointer to signed int15 Error: duplicate object definition for 0: pointer to signed int16 Error: duplicate object definition for 1: pointer to signed int17 Error: duplicate object definition for 0: pointer to signed int18 Error: duplicate object definition for 1: pointer to signed int19 Error: duplicate object definition for 0: pointer to signed int20 Error: duplicate object definition for 1: pointer to signed int21 Error: duplicate object definition for 0: const pointer to signed int22 Error: duplicate object definition for 1: const pointer to signed int23 Error: duplicate object definition for 0: const pointer to signed int24 Error: duplicate object definition for 1: const pointer to signed int25 Error: duplicate object definition for 0: const pointer to signed int26 Error: duplicate object definition for 1: const pointer to signed int27 Error: duplicate object definition for x: const pointer to pointer to signed int28 Error: duplicate object definition for 0: pointer to pointer to signed int29 Error: duplicate object definition for x: const pointer to pointer to signed int30 Error: duplicate object definition for 0: pointer to pointer to signed int31 Error: duplicate object definition for x: const pointer to pointer to signed int32 Error: duplicate object definition for 0: pointer to pointer to signed int1 constant0-1.c:14 error: duplicate object definition for 0: signed int 2 constant0-1.c:15 error: duplicate object definition for 0: const signed int 3 constant0-1.c:16 error: duplicate object definition for 1: signed int 4 constant0-1.c:17 error: duplicate object definition for 1: const signed int 5 constant0-1.c:18 error: duplicate object definition for 0: signed int 6 constant0-1.c:18 error: duplicate object definition for 1: signed int 7 constant0-1.c:19 error: duplicate object definition for 0: signed int 8 constant0-1.c:19 error: duplicate object definition for 1: signed int 9 constant0-1.c:20 error: duplicate object definition for 0: const signed int 10 constant0-1.c:20 error: duplicate object definition for 1: const signed int 11 constant0-1.c:21 error: duplicate object definition for 0: const signed int 12 constant0-1.c:21 error: duplicate object definition for 1: const signed int 13 constant0-1.c:39 error: duplicate object definition for 0: pointer to signed int 14 constant0-1.c:39 error: duplicate object definition for 1: pointer to signed int 15 constant0-1.c:40 error: duplicate object definition for 0: pointer to signed int 16 constant0-1.c:40 error: duplicate object definition for 1: pointer to signed int 17 constant0-1.c:41 error: duplicate object definition for 0: pointer to signed int 18 constant0-1.c:41 error: duplicate object definition for 1: pointer to signed int 19 constant0-1.c:42 error: duplicate object definition for 0: pointer to signed int 20 constant0-1.c:42 error: duplicate object definition for 1: pointer to signed int 21 constant0-1.c:43 error: duplicate object definition for 0: const pointer to signed int 22 constant0-1.c:43 error: duplicate object definition for 1: const pointer to signed int 23 constant0-1.c:44 error: duplicate object definition for 0: const pointer to signed int 24 constant0-1.c:44 error: duplicate object definition for 1: const pointer to signed int 25 constant0-1.c:45 error: duplicate object definition for 0: const pointer to signed int 26 constant0-1.c:45 error: duplicate object definition for 1: const pointer to signed int 27 constant0-1.c:46 error: duplicate object definition for x: const pointer to pointer to signed int 28 constant0-1.c:46 error: duplicate object definition for 0: pointer to pointer to signed int 29 constant0-1.c:47 error: duplicate object definition for x: const pointer to pointer to signed int 30 constant0-1.c:47 error: duplicate object definition for 0: pointer to pointer to signed int 31 constant0-1.c:50 error: duplicate object definition for x: const pointer to pointer to signed int 32 constant0-1.c:50 error: duplicate object definition for 0: pointer to pointer to signed int 33 33 make: *** [constant0-1DP] Error 1 -
src/tests/.expect/constant0-1NDDP.txt
re58dfb9 r35cd219 1 Error: duplicate object definition for 0: signed int2 Error: duplicate object definition for 0: const signed int3 Error: duplicate object definition for 1: signed int4 Error: duplicate object definition for 1: const signed int5 Error: duplicate object definition for 0: signed int6 Error: duplicate object definition for 1: signed int7 Error: duplicate object definition for 0: signed int8 Error: duplicate object definition for 1: signed int9 Error: duplicate object definition for 0: const signed int10 Error: duplicate object definition for 1: const signed int11 Error: duplicate object definition for 0: const signed int12 Error: duplicate object definition for 1: const signed int13 Error: duplicate object definition for x: pointer to signed int14 Error: duplicate object definition for 0: pointer to signed int15 Error: duplicate object definition for x: const pointer to signed int16 Error: duplicate object definition for 0: const pointer to signed int1 constant0-1.c:14 error: duplicate object definition for 0: signed int 2 constant0-1.c:15 error: duplicate object definition for 0: const signed int 3 constant0-1.c:16 error: duplicate object definition for 1: signed int 4 constant0-1.c:17 error: duplicate object definition for 1: const signed int 5 constant0-1.c:18 error: duplicate object definition for 0: signed int 6 constant0-1.c:18 error: duplicate object definition for 1: signed int 7 constant0-1.c:19 error: duplicate object definition for 0: signed int 8 constant0-1.c:19 error: duplicate object definition for 1: signed int 9 constant0-1.c:20 error: duplicate object definition for 0: const signed int 10 constant0-1.c:20 error: duplicate object definition for 1: const signed int 11 constant0-1.c:21 error: duplicate object definition for 0: const signed int 12 constant0-1.c:21 error: duplicate object definition for 1: const signed int 13 constant0-1.c:66 error: duplicate object definition for x: pointer to signed int 14 constant0-1.c:66 error: duplicate object definition for 0: pointer to signed int 15 constant0-1.c:67 error: duplicate object definition for x: const pointer to signed int 16 constant0-1.c:67 error: duplicate object definition for 0: const pointer to signed int 17 17 make: *** [constant0-1NDDP] Error 1 -
src/tests/.expect/declarationErrors.txt
re58dfb9 r35cd219 1 Error: duplicate static in declaration of x1: static const volatile short int1 declarationErrors.c:16 error: duplicate static in declaration of x1: static const volatile short int 2 2 3 Error: conflicting extern & static in declaration of x2: extern const volatile short int3 declarationErrors.c:17 error: conflicting extern & static in declaration of x2: extern const volatile short int 4 4 5 Error: conflicting extern & auto, conflicting extern & static, conflicting extern & static, duplicate extern in declaration of x3: extern const volatile short int5 declarationErrors.c:18 error: conflicting extern & auto, conflicting extern & static, conflicting extern & static, duplicate extern in declaration of x3: extern const volatile short int 6 6 7 Error: duplicate static in declaration of x4: static const volatile instance of const volatile struct __anonymous07 declarationErrors.c:19 error: duplicate static in declaration of x4: static const volatile instance of const volatile struct __anonymous0 8 8 with members 9 9 with body 10 10 11 11 12 Error: duplicate const, duplicate static, duplicate volatile in declaration of x5: static const volatile instance of const volatile struct __anonymous112 declarationErrors.c:20 error: duplicate const, duplicate static, duplicate volatile in declaration of x5: static const volatile instance of const volatile struct __anonymous1 13 13 with members 14 14 with body 15 15 16 16 17 Error: duplicate static in declaration of x6: static const volatile instance of type Int17 declarationErrors.c:22 error: duplicate static in declaration of x6: static const volatile instance of type Int 18 18 19 Error: duplicate const in declaration of f01: static inline function19 declarationErrors.c:24 error: duplicate const in declaration of f01: static inline function 20 20 with no parameters 21 21 returning const volatile int 22 22 23 23 24 Error: duplicate volatile in declaration of f02: static inline function24 declarationErrors.c:25 error: duplicate volatile in declaration of f02: static inline function 25 25 with no parameters 26 26 returning const volatile int 27 27 28 28 29 Error: duplicate const in declaration of f03: static inline function29 declarationErrors.c:26 error: duplicate const in declaration of f03: static inline function 30 30 with no parameters 31 31 returning const volatile int 32 32 33 33 34 Error: duplicate volatile in declaration of f04: static inline function34 declarationErrors.c:27 error: duplicate volatile in declaration of f04: static inline function 35 35 with no parameters 36 36 returning const volatile int 37 37 38 38 39 Error: duplicate const in declaration of f05: static inline function39 declarationErrors.c:28 error: duplicate const in declaration of f05: static inline function 40 40 with no parameters 41 41 returning const volatile int 42 42 43 43 44 Error: duplicate volatile in declaration of f06: static inline function44 declarationErrors.c:29 error: duplicate volatile in declaration of f06: static inline function 45 45 with no parameters 46 46 returning const volatile int 47 47 48 48 49 Error: duplicate const in declaration of f07: static inline function49 declarationErrors.c:30 error: duplicate const in declaration of f07: static inline function 50 50 with no parameters 51 51 returning const volatile int 52 52 53 53 54 Error: duplicate const, duplicate volatile in declaration of f08: static inline function54 declarationErrors.c:31 error: duplicate const, duplicate volatile in declaration of f08: static inline function 55 55 with no parameters 56 56 returning const volatile int 57 57 58 58 59 Error: duplicate const, duplicate volatile in declaration of f09: static inline function59 declarationErrors.c:33 error: duplicate const, duplicate volatile in declaration of f09: static inline function 60 60 with no parameters 61 61 returning const volatile int 62 62 63 63 64 Error: duplicate const, duplicate _Atomic, duplicate _Atomic, duplicate const, duplicate restrict, duplicate volatile in declaration of f09: static inline function64 declarationErrors.c:34 error: duplicate const, duplicate _Atomic, duplicate _Atomic, duplicate const, duplicate restrict, duplicate volatile in declaration of f09: static inline function 65 65 with no parameters 66 66 returning const restrict volatile _Atomic int -
src/tests/.expect/dtor-early-exit-ERR1.txt
re58dfb9 r35cd219 1 Error: jump to label 'L1' crosses initialization of y Branch (Goto)1 dtor-early-exit.c:142 error: jump to label 'L1' crosses initialization of y Branch (Goto) 2 2 3 3 make: *** [dtor-early-exit-ERR1] Error 1 -
src/tests/.expect/dtor-early-exit-ERR2.txt
re58dfb9 r35cd219 1 Error: jump to label 'L2' crosses initialization of y Branch (Goto)1 dtor-early-exit.c:142 error: jump to label 'L2' crosses initialization of y Branch (Goto) 2 2 3 3 make: *** [dtor-early-exit-ERR2] Error 1 -
src/tests/.expect/memberCtors-ERR1.txt
re58dfb9 r35cd219 1 Error: in void ?{}(struct B *b), field a2 used before being constructed1 error: in void ?{}(struct B *b), field a2 used before being constructed 2 2 make: *** [memberCtors-ERR1] Error 1 -
src/tests/.expect/scopeErrors.txt
re58dfb9 r35cd219 1 Error: duplicate object definition for thisIsAnError: signed int2 Error: duplicate function definition for butThisIsAnError: function1 scopeErrors.c:2 error: duplicate object definition for thisIsAnError: signed int 2 scopeErrors.c:20 error: duplicate function definition for butThisIsAnError: function 3 3 with parameters 4 4 double
Note: See TracChangeset
for help on using the changeset viewer.