Ignore:
Timestamp:
Feb 14, 2017, 3:53:52 PM (8 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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.