Skip to content
Snippets Groups Projects
Select Git revision
  • 31cae0533ba47503c0427433ffca819e77f69b44
  • master default protected
  • tut_ring_allen
  • docs_furo
  • docs_reorder_cable_cell
  • docs_graphviz
  • docs_rtd_dev
  • ebrains_mirror
  • doc_recat
  • docs_spike_source
  • docs_sim_sample_clar
  • docs_pip_warn
  • github_template_updates
  • docs_fix_link
  • cv_default_and_doc_clarification
  • docs_add_numpy_req
  • readme_zenodo_05
  • install_python_fix
  • install_require_numpy
  • typofix_propetries
  • docs_recipe_lookup
  • v0.10.0
  • v0.10.1
  • v0.10.0-rc5
  • v0.10.0-rc4
  • v0.10.0-rc3
  • v0.10.0-rc2
  • v0.10.0-rc
  • v0.9.0
  • v0.9.0-rc
  • v0.8.1
  • v0.8
  • v0.8-rc
  • v0.7
  • v0.6
  • v0.5.2
  • v0.5.1
  • v0.5
  • v0.4
  • v0.3
  • v0.2.2
41 results

errorvisitor.hpp

Blame
  • Ben Cumming's avatar
    Benjamin Cumming authored
    * update the out of date version of modparser was added to the repository
    * fix some warnings about unused static functions in a modcc test header
    * move modcc/src path contents to modcc, because there was little point having
      the additional sub directory.
    dfc43806
    History
    errorvisitor.hpp 1.52 KiB
    #pragma once
    
    #include <iostream>
    #include "visitor.hpp"
    #include "expression.hpp"
    
    class ErrorVisitor : public Visitor {
    public:
        ErrorVisitor(std::string const& m)
            : module_name_(m)
        {}
    
        void visit(Expression *e)           override;
        void visit(ProcedureExpression *e)  override;
        void visit(FunctionExpression *e)   override;
        void visit(UnaryExpression *e)      override;
        void visit(BinaryExpression *e)     override;
        void visit(CallExpression *e)       override;
    
        void visit(BlockExpression *e)      override;
        void visit(InitialBlock *e)         override;
        void visit(IfExpression *e)         override;
    
        int num_errors()   {return num_errors_;}
        int num_warnings() {return num_warnings_;}
    private:
        template <typename ExpressionType>
        void print_error(ExpressionType *e) {
            if(e->has_error()) {
                auto header = red("error: ")
                            + white(pprintf("% % ", module_name_, e->location()));
                std::cout << header << "\n  "
                          << e->error_message()
                          << std::endl;
                num_errors_++;
            }
            if(e->has_warning()) {
                auto header = purple("warning: ")
                            + white(pprintf("% % ", module_name_, e->location()));
                std::cout << header << "\n  "
                          << e->warning_message()
                          << std::endl;
                num_warnings_++;
            }
        }
    
        std::string module_name_;
        int num_errors_ = 0;
        int num_warnings_ = 0;
    };