Ignore:
Timestamp:
Aug 30, 2017, 8:08:01 AM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
e5fccf4
Parents:
fc1ef62
Message:

update error message printing and add column to parsing errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/SemanticError.h

    rfc1ef62 r9ed4f94  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 14:01:00 2017
    13 // Update Count     : 7
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Aug 29 22:03:36 2017
     13// Update Count     : 17
    1414//
    1515
    1616#pragma once
    1717
    18 #include <exception>  // for exception
    19 #include <iostream>   // for ostream
    20 #include <list>       // for list
    21 #include <string>     // for string
     18#include <exception>                                                                    // for exception
     19#include <iostream>                                                                             // for ostream
     20#include <list>                                                                                 // for list
     21#include <string>                                                                               // for string
     22#include <unistd.h>                                                                             // for isatty
    2223
    23 #include "CodeLocation.h"  // for CodeLocation, toString
     24#include "CodeLocation.h"                                                               // for CodeLocation, toString
    2425
    2526struct error {
     
    2829
    2930        error() = default;
    30         error( const std::string& str ) : description( str ) {}
     31        error( const std::string & str ) : description( str ) {}
    3132
    32         void maybeSet( const CodeLocation& location ) {
     33        void maybeSet( const CodeLocation & location ) {
    3334                if( this->location.linenumber < 0 ) {
    3435                        this->location = location;
     
    4142        SemanticError();
    4243        SemanticError( std::string error );
    43         template< typename T > SemanticError( const std::string &error, const T *obj );
     44        template< typename T > SemanticError( const std::string & error, const T * obj );
    4445        ~SemanticError() throw() {}
    4546
    46         void append( SemanticError &other );
     47        static inline const std::string & error_str() {
     48                static std::string str = isatty( STDERR_FILENO ) ? "\e[31merror:\e[39m " : "error: ";
     49                return str;
     50        }
     51
     52        void append( SemanticError & other );
    4753        void append( const std::string & );
    4854        bool isEmpty() const;
    49         void print( std::ostream &os );
     55        void print( std::ostream & os );
    5056
    51         void set_location( const CodeLocation& location );
    52         // constructs an exception using the given message and the printed
    53         // representation of the obj (T must have a print method)
     57        void set_location( const CodeLocation & location );
     58        // constructs an exception using the given message and the printed representation of the obj (T must have a print
     59        // method)
    5460  private:
    5561        std::list< error > errors;
     
    5763
    5864template< typename T >
    59 SemanticError::SemanticError( const std::string &error, const T *obj ) {
     65SemanticError::SemanticError( const std::string & error, const T * obj ) {
    6066        append( toString( error, obj ) );
    6167}
Note: See TracChangeset for help on using the changeset viewer.