bool Expression::operator==(const Expression &expr) const { if (GetType()!=expr.GetType()) return false; return Equals(expr); }
void MacroExpChecker::Do(const Expression& Exp, const vector<const ESFixedTypeBase*>& DomainTypes, const ESFixedTypeBase* RangeType, vector<Expression>& FormalParamExps) { if (Exp->GetType() != RangeType) { throw TypeException((string)"Macro Expression has mismatched type"); } MacroExpChecker Checker; Exp->Accept(&Checker); // Check if the formal param expressions obtained have the same type as expected // Also, ALL formal params MUST be used for (uint32 i = 0; i < DomainTypes.size(); ++i) { auto it = Checker.FormalParamExpressions.find(i); if (it == Checker.FormalParamExpressions.end()) { throw TypeException((string)"Formal parameter " + to_string(i) + " unused in macro. " + "Please eliminate unused parameters from macro definitions."); } if (it->second->GetType() != DomainTypes[i]) { throw TypeException((string)"Formal parameter type mismatch at position " + to_string(i) + " in macro definition"); } FormalParamExps.push_back(it->second); } }
Expression ESolver::CreateExpression(const string& OperatorName, const Expression& Exp1, const Expression& Exp2, const Expression& Exp3) { // special case for bv extract if (OperatorName == "bvextract") { if (Exp2->As<UserConstExpression>() == nullptr || Exp3->As<UserConstExpression>() == nullptr) { throw TypeException((string)"bvextract can only be applied to constant indices"); } if (Exp2->GetType() != IntType || Exp3->GetType() != IntType) { throw TypeException((string)"bvextract can only be applied to constant integer indices"); } auto OpName = BVLogic::GetExtractOpName(Exp1->GetType(), Exp2->GetOp()->As<ConstOperator>()->GetConstantValue()->GetValue(), Exp3->GetOp()->As<ConstOperator>()->GetConstantValue()->GetValue()); // recurse with new name auto Op = LookupOperator(OpName); if (Op == nullptr) { LoadedBVLogic->InstantiateExtractOperator(Exp1->GetType(), Exp2->GetOp()->As<ConstOperator>()->GetConstantValue()->GetValue(), Exp3->GetOp()->As<ConstOperator>()->GetConstantValue()->GetValue()); Op = LookupOperator(OpName); } vector<Expression> Children = { Exp1 }; return CreateExpression(Op, Children); } vector<Expression> Children(3); Children[0] = Exp1; Children[1] = Exp2; Children[2] = Exp3; return CreateExpression(OperatorName, Children); }
/* * command-def := 'command' ident stmt */ CommandDef* Parser::commanddef() { // save the line containing the "command" keyword int line = last.line; //if(expect(identifier)) { expect(identifier); CommandDef* cmd = new CommandDef(line, last.sval, error); // Read argument definitions, if any if(accept(leftparen)) { // Initial argument if(sym != rightparen) { expect(identifier); cmd->AddArg(last.sval); } // Subsequent arguments must be preceded by a comma while(sym != rightparen && sym != finished) { if(!expect(comma)) break; if(!expect(identifier)) break; cmd->AddArg(last.sval); } // Don't forget the closing parenthesis! expect(rightparen); } Expression* body = expression(); // DUCT TAPE: if(body->GetType() == blockexpr) { (dynamic_cast<BlockExpr*>(body))->NoLocalScope(true); } cmd->SetBody(body); return cmd; //} //return new ErrorExpr(line, "invalid command def"); }
void ParallelCoordinatesViewerPluginInfo::InitializePlotAtts( AttributeSubject *atts, ViewerPlot *plot) { // If we had scalar names, we can just copy the default atts // and return. if (defaultAtts->GetScalarAxisNames().size() != 0) { // One helpful thing we can do: make sure the user set the // visual axis names. They really should have, but since // we can blindly copy them from the scalar axis names in // this case, no harm doing it for them. if (defaultAtts->GetVisualAxisNames().size() == 0) defaultAtts->SetVisualAxisNames(defaultAtts->GetScalarAxisNames()); *(ParallelCoordinatesAttributes*)atts = *defaultAtts; return; } // Otherwise, we must be an array variable; try to get // some names for its components.... const avtDatabaseMetaData *md = plot->GetMetaData(); const std::string &var = plot->GetVariableName(); const avtArrayMetaData *array = md->GetArray(var); stringVector subNames; if (array) { subNames = array->compNames; } else { Expression *exp = ParsingExprList::GetExpression(plot->GetVariableName()); if (exp == NULL || exp->GetType() != Expression::ArrayMeshVar) { debug3 << "ParallelCoordinatesAttributes::InitializePlotAtts: " << "variable wasn't an array database variable, an " << "array expression, or a list of scalars. This can " << "happen if the user attempts to create this plot " << "without the use off a wizard, e.g. in the case of " << "the cli. Assuming this is the case and continuing " << "without error.\n"; return; } // If we have any problems walking the expression tree, just return; // the worst case scenario if we don't populate the visual axis // name list is that the GUI window is temporarily blank. ExprNode *root = ParsingExprList::GetExpressionTree(exp); if (root->GetTypeName() != "Function") return; FunctionExpr *fn = dynamic_cast<FunctionExpr*>(root); if (fn->GetName() != "array_compose" && fn->GetName() != "array_compose_with_bins") return; ArgsExpr *argsExpr = fn->GetArgsExpr(); std::vector<ArgExpr*> *args = argsExpr ? argsExpr->GetArgs() : NULL; if (!args) return; for (size_t i=0; i<args->size(); i++) { ExprNode *arg = (ExprNode*)((*args)[i]->GetExpr()); if (arg->GetTypeName() == "List") break; subNames.push_back(arg->GetPos().GetText(exp->GetDefinition())); } } doubleVector extMin(subNames.size(), -1e+37); doubleVector extMax(subNames.size(), +1e+37); // Set up the default attributes to contain these values, so // if the user hits reset, the axis names are retained. defaultAtts->SetVisualAxisNames(subNames); defaultAtts->SetExtentMinima(extMin); defaultAtts->SetExtentMaxima(extMax); *(ParallelCoordinatesAttributes*)atts = *defaultAtts; }
void Emit(const Expression& expr, int _backtrackIndex) { switch (expr.GetType()) { case ExpressionType_Empty: { Line("r = true;"); break; } case ExpressionType_Choice: { const Expression::Group& group = expr.GetGroup(); bool mayUndoVisit = !group.first.isLeaf; DefineBacktrack(_backtrackIndex, mayUndoVisit); Emit(group.first, _backtrackIndex); If("!r"); OpenBlock(); Backtrack(_backtrackIndex, mayUndoVisit); Emit(group.second, _backtrackIndex); CloseBlock(); break; } case ExpressionType_Sequence: { const Expression::Group& group = expr.GetGroup(); Emit(group.first, _backtrackIndex); If("r"); OpenBlock(); Emit(group.second, -1); CloseBlock(); break; } case ExpressionType_Not: { bool traverse = mTraverse; mTraverse = false; DefineBacktrack(_backtrackIndex, false); Emit(expr.GetChild(), _backtrackIndex); Line("r = !r;"); Line(format("p = %1%;") % BacktrackVar(_backtrackIndex)); mTraverse = traverse; break; } case ExpressionType_ZeroOrMore: { _backtrackIndex = -1; Line("for (;;)"); OpenBlock(); const Expression& child = expr.GetChild(); bool mayUndoVisit = !child.isLeaf; DefineBacktrack(_backtrackIndex, mayUndoVisit); Emit(child, _backtrackIndex); If("!r"); OpenBlock(); Backtrack(_backtrackIndex, mayUndoVisit); Line("break;"); CloseBlock(); CloseBlock(); Line("r = true;"); break; } case ExpressionType_NonTerminal: { const string& nonTerminal = expr.GetNonTerminal(); const Def& def = *mGrammar.defs.find(nonTerminal); const DefValue& defval = def.second; if (mTraverse) { if (defval.isNode) Line(format("r = Visit(_ctx, SymbolType_%1%, p, v);") % nonTerminal); else if (defval.isMemoized) Line(format("r = TraverseSkip(_ctx, SkipType_%1%, p, v);") % nonTerminal); else Line(format("r = Traverse_%1%(_ctx, p, v);") % nonTerminal); } else { if (defval.isNode) Line(format("r = ParseSymbol(_ctx, SymbolType_%1%, p);") % nonTerminal); else if (defval.isMemoized) Line(format("r = ParseSkip(_ctx, SkipType_%1%, p);") % nonTerminal); else Line(format("r = Parse_%1%(_ctx, p);") % nonTerminal); } break; } case ExpressionType_Range: { int charIndex = mNextCharIndex++; Line(format("Char c%1% = *p++;") % charIndex); Line(format("r = (c%1% >= \'%2%\' && c%1% <= \'%3%\');") % charIndex % EscapeChar(expr.GetFirst()) % EscapeChar(expr.GetLast())); break; } case ExpressionType_Char: { int charIndex = mNextCharIndex++; Line(format("Char c%1% = *p++;") % charIndex); Line(format("r = (c%1% == \'%2%\');") % charIndex % EscapeChar(expr.GetChar())); break; } case ExpressionType_Dot: { int charIndex = mNextCharIndex++; Line(format("Char c%1% = *p++;") % charIndex); Line(format("r = (c%1% != 0);") % charIndex); break; } default: { assert(false); } } }