Changeset 138e29e


Ignore:
Timestamp:
Feb 14, 2017, 3:53:52 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
9bb90a86
Parents:
294647b
Message:

Implemented filename and linenumber errors in most cases, only missing constructor errors apparently

Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/Common/SemanticError.cc

    r294647b r138e29e  
    2222#include "SemanticError.h"
    2323
     24#include <unistd.h>
     25
     26inline const std::string& error_str() {
     27        static std::string str = isatty( fileno(stderr) ) ? "\e[31merror:\e[39m " : "error: ";
     28        return str;
     29}
     30
    2431SemanticError::SemanticError() {
    2532}
    2633
    2734SemanticError::SemanticError( std::string error ) {
    28   append( error );
     35        append( error );
    2936}
    3037
    3138void SemanticError::append( SemanticError &other ) {
    32   errors.splice( errors.end(), other.errors );
     39        errors.splice( errors.end(), other.errors );
    3340}
    3441
    3542void SemanticError::append( const std::string & 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 );
     43        errors.emplace_back( error_str() + msg );
    3944}
    4045
     
    4449
    4550void SemanticError::print( std::ostream &os ) {
    46         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        }
    4755}
    4856
    4957void 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());
     58        errors.begin()->maybeSet( location );
    5559}
    5660
  • src/Common/SemanticError.h

    r294647b r138e29e  
    2525#include "utility.h"
    2626
     27struct 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
    2741class SemanticError : public std::exception {
    2842  public:
     
    4155        // representation of the obj (T must have a print method)
    4256  private:
    43         std::list< std::string > errors;
    44         CodeLocation location;
     57        std::list< error > errors;
    4558};
    4659
  • src/Common/utility.h

    r294647b r138e29e  
    320320
    321321inline std::string to_string( const CodeLocation& location ) {
    322         return location.filename + ":" + std::to_string(location.linenumber);
     322        return location.linenumber >= 0 ? location.filename + ":" + std::to_string(location.linenumber) + " " : "";
    323323}
    324324#endif // _UTILITY_H
  • src/GenPoly/Box.cc

    r294647b r138e29e  
    236236                                } // if
    237237                        } catch( SemanticError &e ) {
     238                                e.set_location( (*i)->location );
    238239                                errors.append( e );
    239240                        } // try
  • src/InitTweak/FixInit.cc

    r294647b r138e29e  
    313313                                        translationUnit.splice( i, fixer.staticDtorDecls );
    314314                                } catch( SemanticError &e ) {
     315                                        e.set_location( (*i)->location );
    315316                                        errors.append( e );
    316317                                } // try
  • src/Parser/DeclarationNode.cc

    r294647b r138e29e  
    988988                        * out++ = cur->buildType();
    989989                } catch( SemanticError &e ) {
     990                        e.set_location( cur->location );
    990991                        errors.append( e );
    991992                } // try
  • src/ResolvExpr/Resolver.cc

    r294647b r138e29e  
    8686                Resolver resolver;
    8787                acceptAll( translationUnit, resolver );
    88 #if 0
    89                 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                 } // for
    94 #endif
    9588        }
    9689
  • src/SynTree/Mutator.h

    r294647b r138e29e  
    139139                        } // if
    140140                } catch( SemanticError &e ) {
     141                        e.set_location( (*i)->location );
    141142                        errors.append( e );
    142143                } // try
  • src/SynTree/Type.h

    r294647b r138e29e  
    1717#define TYPE_H
    1818
     19#include "BaseSyntaxNode.h"
     20#include "Mutator.h"
    1921#include "SynTree.h"
    2022#include "Visitor.h"
    21 #include "Mutator.h"
    2223#include "Common/utility.h"
    2324
    24 class Type {
     25class Type : public BaseSyntaxNode {
    2526  public:
    2627        struct Qualifiers {
  • src/SynTree/Visitor.h

    r294647b r138e29e  
    133133                        }
    134134                } catch( SemanticError &e ) {
     135                        e.set_location( (*i)->location );
    135136                        errors.append( e );
    136137                }
     
    159160                        } // if
    160161                } catch( SemanticError &e ) {
     162                        e.set_location( (*i)->location );                       
    161163                        errors.append( e );
    162164                } // try
Note: See TracChangeset for help on using the changeset viewer.