Skip to content

Commit

Permalink
Update local HIT copy (idaholab#17989)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Jun 8, 2021
1 parent baa58b6 commit 8fbec11
Show file tree
Hide file tree
Showing 11 changed files with 10,054 additions and 7,444 deletions.
9 changes: 3 additions & 6 deletions framework/contrib/hit/Makefile
Expand Up @@ -9,7 +9,7 @@ endif
ifeq ($(UNAME), Darwin)
DYNAMIC_LOOKUP := -undefined dynamic_lookup
else
DYNAMIC_LOOKUP := ""
DYNAMIC_LOOKUP :=
endif

$(info Building hit for python with $(pyconfig))
Expand All @@ -21,13 +21,10 @@ HITCPP := hit.cpp
hit: main.cc parse.cc lex.cc braceexpr.cc braceexpr.h lex.h parse.h
$(CXX) -std=c++11 -g $(CXXFLAGS) $< parse.cc lex.cc braceexpr.cc -o $@

rewrite: rewrite.cc parse.cc lex.cc lex.h parse.h
$(CXX) -std=c++11 -g $(CXXFLAGS) $< parse.cc lex.cc -o $@

bindings: hit.so

hit.so: parse.cc lex.cc braceexpr.cc $(HITCPP)
$(CXX) -std=c++11 -w -fPIC -lstdc++ -shared -L$(PYTHONPREFIX)/lib $(PYTHONCFLAGS) $(DYNAMIC_LOOKUP) $^ -o $@
hit.so: parse.cc lex.cc braceexpr.cc
$(CXX) -std=c++11 -w -fPIC -lstdc++ -shared -L$(PYTHONPREFIX)/lib $(PYTHONCFLAGS) $(DYNAMIC_LOOKUP) $^ $(HITCPP) -o $@

$(HITCPP): hit.pyx chit.pxd
cython -3 -o $@ --cplus $<
Expand Down
5 changes: 2 additions & 3 deletions framework/contrib/hit/braceexpr.cc
Expand Up @@ -70,8 +70,7 @@ ReplaceEvaler::eval(Field * n, const std::list<std::string> & args, BraceExpande
}
}

exp.errors.push_back(
errormsg(exp.fname, n, "no variable '", var, "' found for substitution expression"));
exp.errors.push_back(errormsg(n, "no variable '", var, "' found for substitution expression"));
return n->val();
}

Expand Down Expand Up @@ -108,7 +107,7 @@ BraceExpander::walk(const std::string & /*fullpath*/, const std::string & /*node
}
catch (Error & err)
{
errors.push_back(errormsg(fname, f, err.what()));
errors.push_back(errormsg(f, err.what()));
return;
}
}
Expand Down
21 changes: 19 additions & 2 deletions framework/contrib/hit/braceexpr.h
Expand Up @@ -32,6 +32,24 @@ errormsg(std::string fname, Node * n, T arg, Args... args)
return ss.str();
}

inline std::string
errormsg(Node * /*n*/)
{
return "";
}

template <typename T, typename... Args>
std::string
errormsg(Node * n, T arg, Args... args)
{
std::stringstream ss;
if (n)
ss << n->filename() << ":" << n->line() << ": ";
ss << arg;
ss << errormsg(nullptr, args...);
return ss.str();
}

class BraceNode
{
public:
Expand Down Expand Up @@ -83,14 +101,13 @@ class ReplaceEvaler : public Evaler
class BraceExpander : public Walker
{
public:
BraceExpander(const std::string & fname = "") : fname(fname) {}
BraceExpander() {}
void registerEvaler(const std::string & name, Evaler & ev);
virtual void walk(const std::string & /*fullpath*/, const std::string & /*nodepath*/, Node * n);
std::string expand(Field * n, const std::string & input);

std::vector<std::string> used;
std::vector<std::string> errors;
std::string fname;

private:
std::string expand(Field * n, BraceNode & expr);
Expand Down
4 changes: 3 additions & 1 deletion framework/contrib/hit/chit.pxd
Expand Up @@ -21,6 +21,7 @@ cdef extern from "parse.h" namespace "hit":
string path()
string fullpath()
int line()
const string & filename()
string render(int indent, const string & indent_text, int maxlen)

string strVal() except +
Expand Down Expand Up @@ -116,10 +117,11 @@ cdef extern from "lex.h" namespace "hit::TokType":

cdef extern from "lex.h" namespace "hit":
cdef cppclass Token:
Token(TokType t, const string & val, size_t offset, line)
Token(TokType t, const string & val, const string & name, size_t offset, line)
string str()
TokType type
string val
string name
size_t offset
int line

Expand Down

0 comments on commit 8fbec11

Please sign in to comment.