本文整理汇总了C++中ExprNode类的典型用法代码示例。如果您正苦于以下问题:C++ ExprNode类的具体用法?C++ ExprNode怎么用?C++ ExprNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExprNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compile
// Evaluate
// Tokenizes the string, converts to post-fix order, and evaluates that
// Parameters:
// str (input char array) - string to evaluate
// Pre-condition: str must be a valid integer arithmetic expression including matching parentheses.
void compile(const char str[], VarTree &vars, FunctionDef& funs, Instruction *prog[],
int& pBegin, int& pEnd)
{
TokenList list(str);
ListIterator iter = list.begin();
int tempCounter = 0;
if (tokenText(iter,list) == "deffn")
{
//cout << list << endl;
makeFunction(iter, list, funs);
//return 0;
}
else
{
ExprNode* root = assignmentToTree(iter,list,funs);
#ifdef DEBUG
cout << *root << endl;
#endif
//return root->evaluate(vars, funs);
int tempCounter = 0;
int answerReg = root->toInstruction(prog, pEnd, tempCounter, vars);
pBegin = 0;
prog[pEnd++] = new Print(answerReg);
}
//cout << root->makedc() << endl
//cout << *root << endl;
}
示例2: compileSubObject
U32 ObjectDeclNode::compileSubObject(U32 *codeStream, U32 ip, bool root)
{
U32 start = ip;
codeStream[ip++] = OP_PUSH_FRAME;
ip = classNameExpr->compile(codeStream, ip, TypeReqString);
codeStream[ip++] = OP_PUSH;
ip = objectNameExpr->compile(codeStream, ip, TypeReqString);
codeStream[ip++] = OP_PUSH;
for(ExprNode *exprWalk = argList; exprWalk; exprWalk = (ExprNode *) exprWalk->getNext())
{
ip = exprWalk->compile(codeStream, ip, TypeReqString);
codeStream[ip++] = OP_PUSH;
}
codeStream[ip++] = OP_CREATE_OBJECT;
codeStream[ip] = STEtoU32(parentObject, ip);
ip++;
codeStream[ip++] = isDatablock;
codeStream[ip++] = isClassNameInternal;
codeStream[ip++] = isSingleton;
codeStream[ip++] = dbgLineNumber;
codeStream[ip++] = start + failOffset;
for(SlotAssignNode *slotWalk = slotDecls; slotWalk; slotWalk = (SlotAssignNode *) slotWalk->getNext())
ip = slotWalk->compile(codeStream, ip, TypeReqNone);
codeStream[ip++] = OP_ADD_OBJECT;
codeStream[ip++] = root;
for(ObjectDeclNode *objectWalk = subObjects; objectWalk; objectWalk = (ObjectDeclNode *) objectWalk->getNext())
ip = objectWalk->compileSubObject(codeStream, ip, false);
codeStream[ip++] = OP_END_OBJECT;
codeStream[ip++] = root || isDatablock;
// Added to fix the object creation issue [7/9/2007 Black]
codeStream[ip++] = OP_FINISH_OBJECT;
return ip;
}
示例3: evaluate
int evaluate(const char str[], VarTree &vars, FunctionDef &fmap)
{
TokenList l(str); // Declare and construct our linked list
ExprNode *root;
static int ans = 0; // For handling previous answers
ListIterator i = l.begin();
if((!i.token().isInteger()) && (i.token().isOperator()))
{
Token newHead(ans);
l.push_front(newHead);
i = l.begin();
}
if(i.token().tokenChar() == "deffn")
{
doDefine(i, fmap);
root = new Value(0);
}
else
doCompare(i, root); // Here begins the Conversion
cout << *root << endl;
return root->evaluate(vars, fmap);
}
示例4: GetElems
bool
ListExpr::ExtractNumericElements(vector<double> &output)
{
bool all_numeric = true;
double val = 0.0;
output.clear();
std::vector<ListElemExpr*> *elems = GetElems();
for (int i = 0 ; i < elems->size() ; i++)
{
ExprNode *item = (*elems)[i]->GetItem();
if (item->GetTypeName() == "FloatConst")
{
ConstExpr *c = dynamic_cast<ConstExpr*>(item);
val = (double) dynamic_cast<FloatConstExpr*>(c)->GetValue();
output.push_back(val);
}
else if (item->GetTypeName() == "IntegerConst")
{
ConstExpr *c = dynamic_cast<ConstExpr*>(item);
val = (double) dynamic_cast<IntegerConstExpr*>(c)->GetValue();
output.push_back(val);
}
else
{
all_numeric = false;
}
}
return all_numeric;
}
示例5: EXCEPTION2
void
avtApplyEnumerationExpression::ProcessArguments(ArgsExpr *args,
ExprPipelineState *state)
{
// Check the number of arguments
std::vector<ArgExpr*> *arguments = args->GetArgs();
if (arguments->size() != 2)
{
EXCEPTION2(ExpressionException, outputVariableName,
"the enumerate expression accepts only two arguments");
}
ArgExpr *listarg = (*arguments)[1];
ExprParseTreeNode *listTree = listarg->GetExpr();
if (listTree->GetTypeName() != "List")
{
debug1 << "avtApplyEnumerationExpression: second arg is not a list: "
<< listTree->GetTypeName() << endl;
EXCEPTION2(ExpressionException, outputVariableName,
"the last argument to enumerate "
"must be a list");
}
ListExpr *list = dynamic_cast<ListExpr*>(listTree);
std::vector<ListElemExpr*> *elems = list->GetElems();
enumeratedValues.resize(elems->size());
for (int i = 0 ; i < elems->size() ; i++)
{
if ((*elems)[i]->GetEnd())
{
EXCEPTION2(ExpressionException, outputVariableName,
"the list for the enumerate "
"expression cannot contain ranges.");
}
ExprNode *item = (*elems)[i]->GetItem();
if (item->GetTypeName() == "FloatConst")
{
ConstExpr *c = dynamic_cast<ConstExpr*>(item);
enumeratedValues[i] = dynamic_cast<FloatConstExpr*>(c)->GetValue();
}
else if (item->GetTypeName() == "IntegerConst")
{
ConstExpr *c = dynamic_cast<ConstExpr*>(item);
enumeratedValues[i] = dynamic_cast<IntegerConstExpr*>(c)->GetValue();
}
else
{
EXCEPTION2(ExpressionException, outputVariableName,
"the list for the enumerate "
"expression may contain only numbers.");
}
}
// Let the base class do this processing. We only had to over-ride this
// function to determine the number of arguments.
avtMultipleInputExpressionFilter::ProcessArguments(args, state);
}
示例6: ExprEvaluate
void* ExprCaseWhen::ExprEvaluate(void* tuple, Schema* schema) {
ExprNode* then = case_then_[case_then_.size() - 1];
void* result;
for (int i = 0; i < case_when_.size(); i++) {
if (*static_cast<bool*>(case_when_[i]->ExprEvaluate(tuple, schema)) ==
true) {
then = case_then_[i];
break;
}
} // case_then_ shouldn't be NULL, checked before
result = then->ExprEvaluate(tuple, schema);
return type_cast_func_(result, value_);
}
示例7: findComment
//! Checks if there is whitespace in the range specified in the string
inline std::string findComment(const ExprNode& node) {
const Expression& expr = *node.expr();
typedef std::vector<std::pair<int, int> > Comments;
const Comments& comments = expr.getComments();
const std::string& s = expr.getExpr();
// TODO: user lower_bound to make this O(lg n) instead of O(n)
for (Comments::const_iterator i = comments.begin(); i != comments.end(); ++i) {
if (i->first >= node.endPos() && isWS(s.c_str(), node.endPos(), i->first))
return s.substr(i->first, i->second - i->first + 1);
}
return "";
}
示例8: addArgs
void ExprPrototypeNode::addArgs(ExprNode* surrogate) {
ExprNode::addChildren(surrogate);
#if 0
ExprNode * child;
ExprType type;
for(int i = 0; i < numChildren(); i++) {
child = this->child(i);
type = child->type();
_argTypes.push_back(type);
_env.add(((ExprVarNode*)child)->name(), new ExprLocalVar(type));
}
#endif
}
示例9: precompileIdent
U32 ObjectDeclNode::precompileSubObject(bool)
{
// goes
// OP_PUSHFRAME 1
// name expr
// OP_PUSH 1
// args... PUSH
// OP_CREATE_OBJECT 1
// parentObject 1
// isDatablock 1
// internalName 1
// isSingleton 1
// lineNumber 1
// fail point 1
// for each field, eval
// OP_ADD_OBJECT (to UINT[0]) 1
// root? 1
// add all the sub objects.
// OP_END_OBJECT 1
// root? 1
// To fix the stack issue [7/9/2007 Black]
// OP_FINISH_OBJECT <-- fail point jumps to this opcode
U32 argSize = 0;
precompileIdent(parentObject);
for(ExprNode *exprWalk = argList; exprWalk; exprWalk = (ExprNode *) exprWalk->getNext())
argSize += exprWalk->precompile(TypeReqString) + 1;
argSize += classNameExpr->precompile(TypeReqString) + 1;
U32 nameSize = objectNameExpr->precompile(TypeReqString) + 1;
U32 slotSize = 0;
for(SlotAssignNode *slotWalk = slotDecls; slotWalk; slotWalk = (SlotAssignNode *) slotWalk->getNext())
slotSize += slotWalk->precompile(TypeReqNone);
// OP_ADD_OBJECT
U32 subObjSize = 0;
for(ObjectDeclNode *objectWalk = subObjects; objectWalk; objectWalk = (ObjectDeclNode *) objectWalk->getNext())
subObjSize += objectWalk->precompileSubObject(false);
failOffset = 12 + nameSize + argSize + slotSize + subObjSize;
// +1 because the failOffset should jump to OP_FINISH_OBJECT [7/9/2007 Black]
return failOffset + 1;
}
示例10: cleanup
void cleanup(const ExprNode& expr, bool delete_symbols) {
const ExprNode** nodes=expr.subnodes();
int size=expr.size; // (warning: expr will be deleted in the loop)
for (int i=0; i<size; i++)
if (delete_symbols || (!dynamic_cast<const ExprSymbol*>(nodes[i])))
delete (ExprNode*) nodes[i];
delete[] nodes;
}
示例11: child
ExprType ExprLocalFunctionNode::prep(bool wantScalar, ExprVarEnvBuilder& envBuilder) {
#if 0 // TODO: no local functions for now
bool error = false;
// prep prototype and check for errors
ExprPrototypeNode* prototype = (ExprPrototypeNode*)child(0);
ExprVarEnv functionEnv;
functionEnv.resetAndSetParent(&env);
if (!prototype->prep(false, functionEnv).isValid()) error = true;
// decide what return type we want
bool returnWantsScalar = false;
if (!error && prototype->isReturnTypeSet()) returnWantsScalar = prototype->returnType().isFP(1);
// prep block and check for errors
ExprNode* block = child(1);
ExprType blockType = block->prep(returnWantsScalar, functionEnv);
if (!error && blockType.isValid()) {
if (prototype->isReturnTypeSet()) {
if (blockType != prototype->returnType()) {
checkCondition(false,
"In function result of block '" + blockType.toString() +
"' does not match given return type " + prototype->returnType().toString(),
error);
}
} else
prototype->setReturnType(blockType);
// register the function in the symbol table
env.addFunction(prototype->name(), this);
} else {
checkCondition(false, "Invalid type for blockType is " + blockType.toString(), error);
error = true;
}
return _type = error ? ExprType().Error() : ExprType().None().Varying();
#else
bool error=false;
checkCondition(false,"Local functions are currently not supported.",error);
return ExprType().Error();
#endif
}
示例12: compile
U32 FuncCallExprNode::compile(U32 *codeStream, U32 ip, TypeReq type)
{
codeStream[ip++] = OP_PUSH_FRAME;
for(ExprNode *walk = args; walk; walk = (ExprNode *) walk->getNext())
{
ip = walk->compile(codeStream, ip, TypeReqString);
codeStream[ip++] = OP_PUSH;
}
if(callType == MethodCall || callType == ParentCall)
codeStream[ip++] = OP_CALLFUNC;
else
codeStream[ip++] = OP_CALLFUNC_RESOLVE;
codeStream[ip] = STEtoU32(funcName, ip);
ip++;
codeStream[ip] = STEtoU32(nameSpace, ip);
ip++;
codeStream[ip++] = callType;
if(type != TypeReqString)
codeStream[ip++] = conversionOp(TypeReqString, type);
return ip;
}
示例13: main
// ****************************************************************************
// Function: main
//
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Mon Jul 28 16:53:15 PDT 2003
// Made the expression parser print error messages to the console.
// (Another simultaneous change made the default be the viewer error
// reporting mechanism.)
//
// Jeremy Meredith, Wed Nov 24 12:13:20 PST 2004
// Refactored the parser into generic and VisIt Expression specific pieces.
//
// ****************************************************************************
int
main(int argc, char *argv[])
{
if (argc<2) {cerr<<"needs an argument\n"; exit(-1);}
Parser *parser = new ExprParser(new ExprNodeFactory());
ExprParser::SetErrorMessageTarget(ExprParser::EMT_CONSOLE);
for (int i=1; i<argc; i++)
{
cout << "\n----\n";
cout << "PARSING '"<<argv[i]<<"'"<<endl;
cout << "----\n\n";
ExprNode *node = (ExprNode*)parser->Parse(argv[i]);
if (node)
node->Print(cout);
else
cout << "ERROR\n";
}
return 0;
}
示例14: visit
void CompiledFunction::visit(const ExprNode& e) {
e.acceptVisitor(*this);
}
示例15: rule2string
void RuleOptimizer::checkStetRule(ExprNode *node, const Area *area)
{
Logger::trace << "checking for STET rule " << rule2string(db, cube, node) << endl;
if (!node->isValid()) {
Logger::trace << "rule is invalid, stopping STET rule check" << endl;
return;
}
// the rule should be "[] = IF(...,STET(),...)" or "[] = IF(...,...,STET())"
Node::NodeType t = node->getNodeType();
if (t != Node::NODE_FUNCTION_IF) {
Logger::trace << "no IF clause, stopping STET rule check" << endl;
return;
}
FunctionNode * ifNode = dynamic_cast<FunctionNode*>(node);
ExprNode* clause = dynamic_cast<ExprNode*>(ifNode->getParameters()->at(0));
if (clause == 0) {
Logger::warning << "something is wrong, corrupted rule " << rule2string(db, cube, node) << endl;
return;
}
Node* trueNode = ifNode->getParameters()->at(1);
Node* falseNode = ifNode->getParameters()->at(2);
// either true or false node must be STET
Node* nonStetNode = 0;
bool isInclusive = false;
if (trueNode->getNodeType() == Node::NODE_FUNCTION_STET) {
nonStetNode = falseNode;
isInclusive = false; // use complementary clause-set
} else if (falseNode->getNodeType() == Node::NODE_FUNCTION_STET) {
nonStetNode = trueNode;
isInclusive = true; // use clause-set
} else {
Logger::trace << "no STET as true or false value, stopping STET rule check" << endl;
return;
}
// check if clause is a dimension restriction
Logger::trace << "checking if-clause " << rule2string(db, cube, clause) << endl;
IdentifierType dimensionId;
bool restriction = clause->isDimensionRestriction(cube, &dimensionId);
if (!restriction) {
Logger::trace << "if-clause is no dimension restriction, stopping STET rule check" << endl;
return;
}
CPDimension dimension = db->lookupDimension(dimensionId, false);
if (dimension == 0) {
Logger::trace << "restricted dimension cannot be found, id: " << dimensionId << endl;
return;
}
// ok find the dimension restriction
set<Element*> elements = clause->computeDimensionRestriction(db, cube);
// find dimension position
int pos = 0;
const IdentifiersType *dimensionIds = cube->getDimensions();
for (IdentifiersType::const_iterator iter = dimensionIds->begin(); iter != dimensionIds->end(); ++iter, pos++) {
if (*iter == dimensionId) {
break;
}
}
Logger::trace << "dimension restriction for dimension '" << dimensionId << "', position " << pos << endl;
// find existing restriction
set<IdentifierType> computedRestriction;
// intersect with computed restriction
if (isInclusive) {
// no given restriction
if (!area->elemCount(pos)) {
for (set<Element*>::iterator iter = elements.begin(); iter != elements.end(); ++iter) {
Element* element = *iter;
IdentifierType id = element->getIdentifier();
computedRestriction.insert(id);
Logger::trace << "dimension element " << element->getName(dimension->getElemNamesVector()) << endl;
}
} else {
// restriction given in rule
for (set<Element*>::iterator iter = elements.begin(); iter != elements.end(); ++iter) {
Element* element = *iter;
IdentifierType id = element->getIdentifier();
if (area->find(pos, id) != area->elemEnd(pos)) {
computedRestriction.insert(id);
Logger::trace << "dimension element " << element->getName(dimension->getElemNamesVector()) << endl;
}
//.........这里部分代码省略.........