Changeset 294647b
- Timestamp:
- Feb 14, 2017, 2:54:51 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, 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:
- 138e29e
- Parents:
- eafb094
- Location:
- src
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/SemanticError.cc
reafb094 r294647b 34 34 35 35 void SemanticError::append( const std::string & msg ) { 36 errors.push_back( std::string( "Error: ") + msg ); 36 using std::to_string; 37 const std::string loc = location.linenumber >= 0 ? "At \"" + to_string(location) + "\" " : ""; 38 errors.push_back( loc + "Error: " + msg ); 37 39 } 38 40 … … 45 47 } 46 48 49 void SemanticError::set_location( const CodeLocation& location ) { 50 this->location = location; 51 using std::to_string; 52 const std::string loc = location.linenumber >= 0 ? "At \"" + to_string(location) + "\" " : ""; 53 auto& error = *errors.begin(); 54 error.insert( 0, loc.c_str()); 55 } 56 47 57 // Local Variables: // 48 58 // tab-width: 4 // -
src/Common/SemanticError.h
reafb094 r294647b 23 23 #include <iostream> 24 24 25 #include "utility.h" 26 25 27 class SemanticError : public std::exception { 26 28 public: … … 35 37 void print( std::ostream &os ); 36 38 39 void set_location( const CodeLocation& location ); 37 40 // constructs an exception using the given message and the printed 38 41 // representation of the obj (T must have a print method) 39 42 private: 40 43 std::list< std::string > errors; 44 CodeLocation location; 41 45 }; 42 46 -
src/Common/utility.h
reafb094 r294647b 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.filename + ":" + std::to_string(location.linenumber); 323 } 305 324 #endif // _UTILITY_H 306 325 -
src/Parser/DeclarationNode.cc
reafb094 r294647b 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 -
src/Parser/ParseNode.h
reafb094 r294647b 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/SynTree/Declaration.h
reafb094 r294647b 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
reafb094 r294647b 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
reafb094 r294647b 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/Statement.h
reafb094 r294647b 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 );
Note: See TracChangeset
for help on using the changeset viewer.