Commit a466bebe authored by hrchilds's avatar hrchilds
Browse files

Update from June 13, 2005

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@483 18c085ea-50e0-402c-830e-de6fd14e8384
parent 22ca50e1
......@@ -11,19 +11,59 @@ using std::vector;
// Made expression language specific tokens have a more specific
// base class. Renamed GrammarNode to ParseTreeNode.
//
// Jeremy Meredith, Mon Jun 13 15:46:22 PDT 2005
// Made ConstExpr abstract and split it into multiple concrete
// base classes. Made FunctionExpr and MachExpr use names
// instead of Identifier tokens. These two changes were to
// remove Token references from the parse tree node classes.
// Also added some destructors.
//
// class ConstExpr
ConstExpr::ConstExpr(const Pos &p, ExprToken *t) : ExprNode(p)
ConstExpr::ConstExpr(const Pos &p, ConstType ct) : ExprNode(p)
{
token = t;
constType = ct;
}
void
ConstExpr::PrintNode(ostream &o)
IntegerConstExpr::PrintNode(ostream &o)
{
o << "IntegerConstant: "<<value << endl;
}
IntegerConstExpr::~IntegerConstExpr()
{
}
void
FloatConstExpr::PrintNode(ostream &o)
{
o << "FloatConstant: "<<value << endl;
}
FloatConstExpr::~FloatConstExpr()
{
}
void
StringConstExpr::PrintNode(ostream &o)
{
o << "StringConstant: "<<value << endl;
}
StringConstExpr::~StringConstExpr()
{
}
void
BooleanConstExpr::PrintNode(ostream &o)
{
o << "BooleanConstant: "<<value << endl;
}
BooleanConstExpr::~BooleanConstExpr()
{
o << "Constant ";
token->PrintNode(o);
}
void
......@@ -126,6 +166,15 @@ ListExpr::ListExpr(const Pos &p, ListElemExpr *e) : ExprParseTreeNode(p)
elems->push_back(e);
}
ListExpr::~ListExpr()
{
for (int i=0; i<elems->size(); i++)
{
delete (*elems)[i];
}
delete elems;
}
void
ListExpr::AddListElem(ListElemExpr *e)
{
......@@ -156,9 +205,9 @@ ListExpr::GetVarLeaves()
void
ArgExpr::PrintNode(ostream &o)
{
if (id)
if (identifier != "")
{
o << "name='" << id->GetVal().c_str() << "':";
o << "name='" << identifier << "':";
}
o << endl;
expr->Print(o);
......@@ -171,6 +220,15 @@ ArgsExpr::ArgsExpr(const Pos &p, ArgExpr *e) : ExprParseTreeNode(p)
args->push_back(e);
}
ArgsExpr::~ArgsExpr()
{
for (int i=0; i<args->size(); i++)
{
delete (*args)[i];
}
delete args;
}
void
ArgsExpr::AddArg(ArgExpr *e)
{
......@@ -192,7 +250,7 @@ ArgsExpr::PrintNode(ostream &o)
void
FunctionExpr::PrintNode(ostream &o)
{
o << "Function '" << name->GetVal().c_str() << "' with ";
o << "Function '" << name << "' with ";
if (args)
args->PrintNode(o);
else
......@@ -254,7 +312,7 @@ PathExpr::PrintNode(ostream &o)
void
MachExpr::PrintNode(ostream &o)
{
o << "Machine="<<host->GetVal().c_str()<<endl;
o << "Machine="<<host<<endl;
}
void
......
......@@ -6,9 +6,7 @@
#include <set>
#include <string>
#include <ExprParseTreeNode.h>
#include <ExprToken.h>
class Identifier;
class Pos;
// ****************************************************************************
......@@ -42,6 +40,13 @@ class Pos;
// Added the original text for an argument to ArgExpr because it is
// useful for implementing macros.
//
// Jeremy Meredith, Mon Jun 13 15:46:22 PDT 2005
// Made ConstExpr abstract and split it into multiple concrete
// base classes. Made FunctionExpr and MachExpr use names
// instead of Identifier tokens. These two changes were to
// remove Token references from the parse tree node classes.
// Also added some destructors.
//
// ****************************************************************************
class EXPR_API ExprNode : public ExprParseTreeNode
{
......@@ -56,14 +61,66 @@ class EXPR_API ExprNode : public ExprParseTreeNode
class EXPR_API ConstExpr : public virtual ExprNode
{
public:
ConstExpr(const Pos &p, ExprToken *t);
enum ConstType { Integer, Float, String, Boolean };
ConstExpr(const Pos &p, ConstType ct);
virtual ~ConstExpr() { }
virtual std::set<std::string> GetVarLeaves()
{ return std::set<std::string>(); }
virtual ConstType GetConstantType() { return constType; }
protected:
ConstType constType;
};
class EXPR_API IntegerConstExpr : public ConstExpr
{
public:
IntegerConstExpr(const Pos &p, int v)
: ConstExpr(p, ConstExpr::Integer), ExprNode(p), value(v) {}
virtual ~IntegerConstExpr();
virtual const std::string GetTypeName() { return "IntegerConst"; }
virtual void PrintNode(ostream &o);
int GetValue() { return value; }
protected:
int value;
};
class EXPR_API FloatConstExpr : public ConstExpr
{
public:
FloatConstExpr(const Pos &p, float v)
: ConstExpr(p, ConstExpr::Float), ExprNode(p), value(v) {}
virtual ~FloatConstExpr();
virtual const std::string GetTypeName() { return "FloatConst"; }
virtual void PrintNode(ostream &o);
float GetValue() { return value; }
protected:
float value;
};
class EXPR_API StringConstExpr : public ConstExpr
{
public:
StringConstExpr(const Pos &p, std::string v)
: ConstExpr(p, ConstExpr::String), ExprNode(p), value(v) {}
virtual ~StringConstExpr();
virtual const std::string GetTypeName() { return "StringConst"; }
virtual void PrintNode(ostream &o);
std::string GetValue() { return value; }
protected:
std::string value;
};
class EXPR_API BooleanConstExpr : public ConstExpr
{
public:
BooleanConstExpr(const Pos &p, bool v)
: ConstExpr(p, ConstExpr::Boolean), ExprNode(p), value(v) {}
virtual ~BooleanConstExpr();
virtual const std::string GetTypeName() { return "BooleanConst"; }
virtual void PrintNode(ostream &o);
virtual std::set<std::string> GetVarLeaves() {return std::set<std::string>();}
virtual const std::string GetTypeName() { return "Const"; }
ExprToken * GetToken() { return token; }
bool GetValue() { return value; }
protected:
ExprToken *token;
bool value;
};
class EXPR_API MathExpr : public virtual ExprNode
......@@ -82,7 +139,7 @@ class EXPR_API UnaryExpr : public MathExpr
public:
UnaryExpr(const Pos &p, char o, ExprNode *e)
: MathExpr(p, o), ExprNode(p), expr(e) {}
virtual ~UnaryExpr() { }
virtual ~UnaryExpr() { delete expr; }
virtual void PrintNode(ostream &o);
virtual std::set<std::string> GetVarLeaves()
{return expr->GetVarLeaves();}
......@@ -96,7 +153,7 @@ class EXPR_API BinaryExpr : public MathExpr
public:
BinaryExpr(const Pos &p, char o, ExprNode *l, ExprNode *r)
: MathExpr(p, o), ExprNode(p), left(l), right(r) {}
virtual ~BinaryExpr() { }
virtual ~BinaryExpr() { delete left; delete right; }
virtual void PrintNode(ostream &o);
virtual std::set<std::string> GetVarLeaves();
virtual const std::string GetTypeName() { return "Binary"; }
......@@ -110,7 +167,7 @@ class EXPR_API IndexExpr : public virtual ExprNode
public:
IndexExpr(const Pos &p, ExprNode *e, int i)
: ExprNode(p), expr(e), ind(i) {}
virtual ~IndexExpr() { }
virtual ~IndexExpr() { delete expr; }
virtual void PrintNode(ostream &o);
virtual std::set<std::string> GetVarLeaves()
{return expr->GetVarLeaves();}
......@@ -125,7 +182,7 @@ class EXPR_API VectorExpr : public virtual ExprNode
public:
VectorExpr(const Pos &p, ExprNode *xi, ExprNode *yi, ExprNode *zi=NULL)
: ExprNode(p), x(xi), y(yi), z(zi) {}
virtual ~VectorExpr() { }
virtual ~VectorExpr() { delete x; delete y; delete z; }
virtual void PrintNode(ostream &o);
virtual std::set<std::string> GetVarLeaves();
virtual const std::string GetTypeName() { return "Vector"; }
......@@ -138,7 +195,7 @@ class EXPR_API ListElemExpr : public ExprParseTreeNode
public:
ListElemExpr(const Pos &p, ExprNode *b, ExprNode *e=NULL, ExprNode *s=NULL)
: ExprParseTreeNode(p), beg(b), end(e), skip(s) {}
virtual ~ListElemExpr() { }
virtual ~ListElemExpr() { delete beg; delete end; delete skip; }
virtual void PrintNode(ostream &o);
virtual const std::string GetTypeName() { return "ListElem"; }
ExprNode *GetItem(void) { return beg; }
......@@ -155,7 +212,7 @@ class EXPR_API ListExpr : public ExprParseTreeNode
{
public:
ListExpr(const Pos &p, ListElemExpr *e);
virtual ~ListExpr() { }
virtual ~ListExpr();
void AddListElem(ListElemExpr *e);
virtual void PrintNode(ostream &o);
virtual const std::string GetTypeName() { return "List"; }
......@@ -169,18 +226,17 @@ class EXPR_API ArgExpr : public ExprParseTreeNode
{
public:
ArgExpr(const Pos &p, ExprParseTreeNode *e, const std::string &t)
: ExprParseTreeNode(p), id(NULL), expr(e), text(t) {}
virtual ~ArgExpr() { }
ArgExpr(const Pos &p, Identifier *i, ExprParseTreeNode *e,
: ExprParseTreeNode(p), identifier(""), expr(e), text(t) {}
virtual ~ArgExpr() { delete expr; }
ArgExpr(const Pos &p, std::string id, ExprParseTreeNode *e,
const std::string &t)
: ExprParseTreeNode(p), id(i), expr(e), text(t) {}
: ExprParseTreeNode(p), identifier(id), expr(e), text(t) {}
virtual void PrintNode(ostream &o);
Identifier *GetId(void) {return id;};
ExprParseTreeNode *GetExpr(void) {return expr;};
virtual const std::string GetTypeName() { return "Arg"; }
const std::string &GetText(void) const { return text; };
protected:
Identifier *id;
std::string identifier;
ExprParseTreeNode *expr;
std::string text;
};
......@@ -189,7 +245,7 @@ class EXPR_API ArgsExpr : public ExprParseTreeNode
{
public:
ArgsExpr(const Pos &p, ArgExpr *e);
virtual ~ArgsExpr() { }
virtual ~ArgsExpr();
void AddArg(ArgExpr *e);
virtual void PrintNode(ostream &o);
std::vector<ArgExpr*>* GetArgs(void) {return args;};
......@@ -201,14 +257,14 @@ class EXPR_API ArgsExpr : public ExprParseTreeNode
class EXPR_API FunctionExpr : public virtual ExprNode
{
public:
FunctionExpr(const Pos &p, Identifier *i, ArgsExpr *e=NULL)
: ExprNode(p), name(i), args(e) {}
virtual ~FunctionExpr() { }
FunctionExpr(const Pos &p, std::string n, ArgsExpr *e=NULL)
: ExprNode(p), name(n), args(e) {}
virtual ~FunctionExpr() { delete args; }
virtual void PrintNode(ostream &o);
virtual std::set<std::string> GetVarLeaves();
virtual const std::string GetTypeName() { return "Function"; }
protected:
Identifier *name;
std::string name;
ArgsExpr *args;
};
......@@ -233,13 +289,13 @@ class EXPR_API PathExpr : public ExprParseTreeNode
class EXPR_API MachExpr : public ExprParseTreeNode
{
public:
MachExpr(const Pos &p, Identifier *i)
: ExprParseTreeNode(p), host(i) {}
MachExpr(const Pos &p, std::string h)
: ExprParseTreeNode(p), host(h) {}
virtual ~MachExpr() { }
virtual void PrintNode(ostream &o);
virtual const std::string GetTypeName() { return "Mach"; }
protected:
Identifier *host;
std::string host;
};
class EXPR_API TimeExpr : public ExprParseTreeNode
......@@ -248,7 +304,7 @@ class EXPR_API TimeExpr : public ExprParseTreeNode
enum Type { Cycle, Time, Index, Unknown };
TimeExpr(const Pos &p, ListExpr *l, Type t=Unknown)
: ExprParseTreeNode(p), type(t), list(l) {}
virtual ~TimeExpr() { }
virtual ~TimeExpr() { delete list; }
virtual void PrintNode(ostream &o);
virtual const std::string GetTypeName() { return "Time"; }
protected:
......@@ -261,7 +317,7 @@ class EXPR_API DBExpr : public ExprParseTreeNode
public:
DBExpr(const Pos &p, PathExpr *f, MachExpr *m, TimeExpr *t)
: ExprParseTreeNode(p), file(f), mach(m), time(t) {}
virtual ~DBExpr() { }
virtual ~DBExpr() { delete file; delete mach; delete time; }
virtual void PrintNode(ostream &o);
virtual const std::string GetTypeName() { return "DBExpr"; }
protected:
......@@ -275,7 +331,7 @@ class EXPR_API VarExpr : public virtual ExprNode
public:
VarExpr(const Pos &p, DBExpr *d, PathExpr *v, bool exp)
: ExprNode(p), db(d), var(v), canexpand(exp) {}
virtual ~VarExpr() { }
virtual ~VarExpr() { delete db; delete var; }
virtual void PrintNode(ostream &o);
virtual std::set<std::string> GetVarLeaves();
virtual const std::string GetTypeName() { return "Var"; }
......
......@@ -5,13 +5,16 @@
#include <ExprNode.h>
#include <Pos.h>
class Token;
// Modifications:
// Jeremy Meredith, Wed Nov 24 12:22:32 PST 2004
// Expression-language specific tokens are in a new,
// more specific base class.
//
// Jeremy Meredith, Mon Jun 13 15:46:22 PDT 2005
// Made ConstExpr abstract and split it into multiple concrete
// base classes. Made FunctionExpr and MachExpr use names
// instead of Identifier tokens. These two changes were to
// remove Token references from the parse tree node classes.
class EXPR_API ExprNodeFactory
......@@ -21,8 +24,20 @@ public:
virtual ~ExprNodeFactory() {}
virtual ConstExpr*
CreateConstExpr(const Pos & p, ExprToken * t)
{ return new ConstExpr(p, t); }
CreateIntegerConstExpr(const Pos & p, int v)
{ return new IntegerConstExpr(p, v); }
virtual ConstExpr*
CreateFloatConstExpr(const Pos & p, float v)
{ return new FloatConstExpr(p, v); }
virtual ConstExpr*
CreateStringConstExpr(const Pos & p, std::string v)
{ return new StringConstExpr(p, v); }
virtual ConstExpr*
CreateBooleanConstExpr(const Pos & p, bool v)
{ return new BooleanConstExpr(p, v); }
virtual UnaryExpr*
CreateUnaryExpr(const Pos & p, char op, ExprNode * e)
......@@ -43,9 +58,9 @@ public:
{ return new VectorExpr(p, x, y, z); }
virtual FunctionExpr*
CreateFunctionExpr(const Pos & p, Identifier * i,
CreateFunctionExpr(const Pos & p, std::string n,
ArgsExpr * e = NULL)
{ return new FunctionExpr(p, i, e); }
{ return new FunctionExpr(p, n, e); }
virtual VarExpr*
CreateVarExpr(const Pos & p, DBExpr * d, PathExpr * v,
......
......@@ -91,6 +91,12 @@ ExprParser::ExprParser(ExprNodeFactory *f) : Parser(), factory(f)
// Hank Childs, Fri Jan 28 14:07:18 PST 2005
// Use exception macros.
//
// Jeremy Meredith, Mon Jun 13 15:46:22 PDT 2005
// Split ConstExpr into multiple concrete base classes.
// Made FunctionExpr, MachExpr, and ArgsExpr use names
// instead of Identifier tokens. These two changes were to
// remove Token references from the parse tree node classes.
//
// ****************************************************************************
ParseTreeNode*
ExprParser::ApplyRule(const Symbol &sym,
......@@ -111,7 +117,6 @@ ExprParser::ApplyRule(const Symbol &sym,
(ExprNode*)(E[2]));
break;
case 1:
node = factory->CreateBinaryExpr(p,
((Character*)T[1])->GetVal(),
......@@ -192,16 +197,20 @@ ExprParser::ApplyRule(const Symbol &sym,
switch (rule->GetID())
{
case 0:
node = factory->CreateConstExpr(p, (ExprToken *)T[0]);
node = factory->CreateIntegerConstExpr(p,
((IntegerConst *)T[0])->GetValue());
break;
case 1:
node = factory->CreateConstExpr(p, (ExprToken *)T[0]);
node = factory->CreateFloatConstExpr(p,
((FloatConst *)T[0])->GetValue());
break;
case 2:
node = factory->CreateConstExpr(p, (ExprToken *)T[0]);
node = factory->CreateStringConstExpr(p,
((StringConst *)T[0])->GetValue());
break;
case 3:
node = factory->CreateConstExpr(p, (ExprToken *)T[0]);
node = factory->CreateBooleanConstExpr(p,
((BoolConst *)T[0])->GetValue());
break;
}
} else if (sym == Vector)
......@@ -261,12 +270,13 @@ ExprParser::ApplyRule(const Symbol &sym,
switch (rule->GetID())
{
case 0:
node = factory->CreateFunctionExpr(p, ((Identifier*)T[0]));
node = factory->CreateFunctionExpr(p,
((Identifier*)T[0])->GetVal());
break;
case 1:
node = factory->CreateFunctionExpr(p,
((Identifier*)T[0]),
(ArgsExpr*)(E[2]));
((Identifier*)T[0])->GetVal(),
(ArgsExpr*)(E[2]));
break;
}
} else if (sym == Args)
......@@ -288,7 +298,8 @@ ExprParser::ApplyRule(const Symbol &sym,
node = new ArgExpr(p, (ExprParseTreeNode*)E[0], p.GetText(text));
break;
case 1:
node = new ArgExpr(p, ((Identifier*)T[0]),(ExprParseTreeNode*)E[2],
node = new ArgExpr(p, ((Identifier*)T[0])->GetVal(),
(ExprParseTreeNode*)E[2],
p.GetText(text));
break;
case 2:
......@@ -304,15 +315,15 @@ ExprParser::ApplyRule(const Symbol &sym,
((PathExpr *) node)->Append("/");
((PathExpr *) node)->Append(((Identifier*)T[2])->GetVal());
delete E[1];
delete E[1];
break;
case 1:
node = new PathExpr(p, "/");
((PathExpr *) node)->Append(((Identifier*)T[1])->GetVal());
delete E[0];
delete E[0];
break;
case 2:
node = new PathExpr(p, ((Identifier*)T[0])->GetVal());
node = new PathExpr(p, ((Identifier*)T[0])->GetVal());
break;
}
} else if (sym == MultiSlash)
......@@ -384,7 +395,7 @@ ExprParser::ApplyRule(const Symbol &sym,
switch (rule->GetID())
{
case 0:
node = new MachExpr(p, ((Identifier*)T[1]));
node = new MachExpr(p, ((Identifier*)T[1])->GetVal());
break;
}
} else if (sym == TimeSpec)
......@@ -463,6 +474,10 @@ ExprParser::ApplyRule(const Symbol &sym,
// Hank Childs, Fri Jan 28 14:07:18 PST 2005
// Use exception macros.
//
// Jeremy Meredith, Mon Jun 13 16:17:14 PDT 2005
// Delete the tokens that have not taken part in a rule reduction -- in
// this case that means Space tokens and the final EOF token.
//
// ****************************************************************************
ParseTreeNode*
ExprParser::Parse(const std::string &s)
......@@ -484,7 +499,10 @@ ExprParser::Parse(const std::string &s)
token = scanner.ScanOneToken();
if (token->GetType() != TT_Space)
ParseOneToken(token);
else
delete token;
}
delete token;
}
CATCH2(UnhandledReductionException, e)
{
......
......@@ -309,6 +309,9 @@ ParsingExprList::GetExpressionTree(Expression *expr)
// a vector of strings because the vector constructor was not taking
// the set container's iterators successfully on MSVC 6.0.
//
// Jeremy Meredith, Mon Jun 13 15:51:50 PDT 2005
// Delete the parse tree when we're done with it. This fixes leaks.
//
// ****************************************************************************
static string
......@@ -343,7 +346,10 @@ GetRealVariableHelper(const string &var, set<string> expandedVars)
// Get the leaves for this expression
const set<string> &varLeaves = tree->GetVarLeaves();
if (varLeaves.empty())
{
delete tree;
return "";
}
// For each leaf, look for a real variable
#if defined(_WIN32) && defined(USING_MSVC6)
......@@ -359,10 +365,14 @@ GetRealVariableHelper(const string &var, set<string> expandedVars)
// If we found a real variable, return it!
if (!realvar.empty())
{
delete tree;
return realvar;
}
}
// Didn't find any real variables
delete tree;
return "";
}
......
......@@ -35,9 +35,15 @@ Grammar::Grammar(Dictionary &d)
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Mon Jun 13 15:52:32 PDT 2005
// Free the rules.
//
// ****************************************************************************
Grammar::~Grammar()
{
for (int i=1; i<rules.size(); i++)
delete rules[i];
}
// ****************************************************************************
......
......@@ -62,6 +62,9 @@
# Jeremy Meredith, Wed Jun 8 11:27:24 PDT 2005
# Added Dictionary.
#
# Jeremy Meredith, Mon Jun 13 15:53:10 PDT 2005
# Added purify target for parser test. Removed TokenParseTreeNode.
#
##############################################################################
##
......@@ -89,8 +92,7 @@ COMMONSRC = \
Scanner.C \
Sequence.C \
Symbol.C \
Token.C \
TokenParseTreeNode.C
Token.C
LIBSRC =
SRC=${LIBSRC} ${COMMONSRC}
OBJ=$(SRC:.C=.o)
......@@ -117,6 +119,9 @@ clean:
$(TESTPROG1) test: $(TESTOBJ1) $(LIBSHARED)
$(CXX) -o $(TESTPROG1) $(LDFLAGS) -lparser $(TESTOBJ1) -lmisc @LIBS@