void ReduceArrayDim::handleOneArraySubscriptExpr( const ArraySubscriptExpr *ASE) { const Type *ASETy = ASE->getType().getTypePtr(); if (!ASETy->isScalarType() && !ASETy->isStructureType() && !ASETy->isUnionType()) return; ExprVector IdxExprs; const Expr *BaseE = getBaseExprAndIdxExprs(ASE, IdxExprs); TransAssert(BaseE && "Empty Base expression!"); if (IdxExprs.size() <= 1) return; const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(BaseE); if (!DRE) return; const ValueDecl *OrigDecl = DRE->getDecl(); const VarDecl *VD = dyn_cast<VarDecl>(OrigDecl); if (!VD) return; const VarDecl *CanonicalVD = VD->getCanonicalDecl(); if (CanonicalVD != TheVarDecl) return; rewriteSubscriptExpr(IdxExprs); }
ExprVector EntityBase::FaceGetNormalExprs(void) { ExprVector r; if(type == FACE_NORMAL_PT) { Vector v = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz); r = ExprVector::From(v.WithMagnitude(1)); } else if(type == FACE_XPROD) { ExprVector vc = ExprVector::From(param[0], param[1], param[2]); ExprVector vn = ExprVector::From(numNormal.vx, numNormal.vy, numNormal.vz); r = vc.Cross(vn); r = r.WithMagnitude(Expr::From(1.0)); } else if(type == FACE_N_ROT_TRANS) { // The numerical normal vector gets the rotation; the numerical // normal has magnitude one, and the rotation doesn't change that, // so there's no need to fix it up. r = ExprVector::From(numNormal.vx, numNormal.vy, numNormal.vz); ExprQuaternion q = ExprQuaternion::From(param[3], param[4], param[5], param[6]); r = q.Rotate(r); } else if(type == FACE_N_TRANS) { r = ExprVector::From(numNormal.vx, numNormal.vy, numNormal.vz); } else if(type == FACE_N_ROT_AA) { r = ExprVector::From(numNormal.vx, numNormal.vy, numNormal.vz); ExprQuaternion q = GetAxisAngleQuaternionExprs(3); r = q.Rotate(r); } else oops(); return r; }
void OpReplaceRepeated::Apply(Expression *expression, Calculator *calculator, int32 recursions) { if(expression->LeafCount() != 2) throw ArgumentException("ReplaceRepeated expects 2 arguments."); if(expression->LeafCount() != 2) throw ArgumentException("ReplaceRepeated expects 2 arguments."); string leafFunction = expression->Leaf(1)->FunctionName(); if(leafFunction != "Rule" && leafFunction != "RuleDelayed" && leafFunction != "List") throw ArgumentException("ReplaceRepeated expects its second argument to be a rule or a list of rules."); ExprVector rules; if(leafFunction == "List") { for(ExprVector::const_iterator item = expression->Leaf(1)->Leaves().begin(); item != expression->Leaf(1)->Leaves().end(); ++ item) if((*item)->FunctionName() != "Rule" && (*item)->FunctionName() != "RuleDelayed") throw ArgumentException("ReplaceRepeated expects its second argument to be a rule or a list of rules."); rules = expression->Leaf(1)->Leaves(); } else rules.push_back(expression->Leaf(1)); int32 iterations(0); Expression *result = expression->Leaf(0); while(true) { bool changed(false); if(!result->ReplaceAll(rules, calculator, &changed)) break; if(!changed) break; ++iterations; if(iterations >= Max_ReplaceRepeated_Iterations) throw LimitationException("Maximum number of iterations reached."); } expression->AssignLeaf(0); expression->Evaluate(calculator, recursions); }
Stmt *TransformVector::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) { unsigned NumElems = Node->getNumElements(); if (NumElems == 0) { // array subscripting syntax Expr *ExprBase = TransformExpr(Node->getBase()); ASTCtx.Deallocate(Node); return ExprBase; } else { DeclVector DeclVec; ExprVector ExprVec; MakeElementExprs(DeclVec, ExprVec, Node); assert((ExprVec.size() == NumElems) && "Wrong accessor?"); if (DeclVec.size() > 0) { PushBackDeclStmts(*CurStmtVec, DeclVec); } if (NumElems == 1) { return ExprVec[0]; } else { QualType NodeTy = Node->getType(); CallExpr *NewExpr = new (ASTCtx) CallExpr(ASTCtx, CLExprs.getVectorLiteralExpr(NodeTy), ExprVec.data(), NumElems, NodeTy, VK_RValue, SourceLocation()); return NewExpr; } } }
/** * @brief Converts the given LLVM call instruction @a inst into an expression in BIR. */ ShPtr<CallExpr> LLVMInstructionConverter::convertCallInstToCallExpr(llvm::CallInst &inst) { ExprVector args; for (auto &arg: inst.arg_operands()) { args.push_back(getConverter()->convertValueToExpression(arg)); } auto calledExpr = getConverter()->convertValueToExpression(inst.getCalledValue()); return CallExpr::create(calledExpr, args); }
bool Expression::ReplaceAll(const ExprVector &rules, Calculator *calculator, bool *changed) { for(ExprVector::const_iterator rule = rules.begin(); rule != rules.end(); ++rule) if(Replace(*rule, calculator, changed)) return true; for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf) if((*leaf)->ReplaceAll(rules, calculator, changed)) return true; return false; }
void Gradient::vector_bwd(const ExprVector& v, ExprLabel** compL, const ExprLabel& y) { if (v.dim.is_vector()) { for (int i=0; i<v.length(); i++) compL[i]->g->i()+=y.g->v()[i]; } else { if (v.row_vector()) for (int i=0; i<v.length(); i++) compL[i]->g->v()+=y.g->m()[i]; else for (int i=0; i<v.length(); i++) compL[i]->g->v()+=y.g->m().col(i); } }
ExprVector ConstraintBase::PointInThreeSpace(hEntity workplane, Expr *u, Expr *v) { EntityBase *w = SK.GetEntity(workplane); ExprVector ub = w->Normal()->NormalExprsU(); ExprVector vb = w->Normal()->NormalExprsV(); ExprVector ob = w->WorkplaneGetOffsetExprs(); return (ub.ScaledBy(u)).Plus(vb.ScaledBy(v)).Plus(ob); }
void ReduceArraySize::handleOneASE(const ArraySubscriptExpr *ASE) { const Type *ASETy = ASE->getType().getTypePtr(); if (!ASETy->isScalarType() && !ASETy->isStructureType() && !ASETy->isUnionType()) return; ExprVector IdxExprs; const Expr *BaseE = getBaseExprAndIdxExprs(ASE, IdxExprs); TransAssert(BaseE && "Empty Base expression!"); const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(BaseE); if (!DRE) return; const ValueDecl *OrigDecl = DRE->getDecl(); const VarDecl *VD = dyn_cast<VarDecl>(OrigDecl); if (!VD) return; const VarDecl *CanonicalVD = VD->getCanonicalDecl(); DimValueVector *DimVec = VarDeclToDim[CanonicalVD]; // It's possible DimVec is NULL, e.g., // int main(..., char *argv[]) { // ... argv[1] ... // } if (!DimVec) return; TransAssert((DimVec->size() >= IdxExprs.size()) && "More indices than it should be!"); unsigned int DimIdx = 0; for (ExprVector::reverse_iterator I = IdxExprs.rbegin(), E = IdxExprs.rend(); I != E; ++I) { int OldIdx = (*DimVec)[DimIdx]; if (OldIdx == -1) { DimIdx++; continue; } const Expr *IdxE = (*I); if (isIntegerExpr(IdxE)) { int Idx = getIndexAsInteger(IdxE); if (Idx > OldIdx) (*DimVec)[DimIdx] = Idx; } else { (*DimVec)[DimIdx] = -1; } DimIdx++; } }
/*************************************************************** * Function: RangeExpr::getSubExprs() * Purpose : Access sub-expressions * Initial : Maxime Chevalier-Boisvert on January 8, 2009 **************************************************************** Revisions and bug fixes: */ Expression::ExprVector RangeExpr::getSubExprs() const { // Create a list to store the sub-expression pointers ExprVector list; // Add the sub-expressions to the list list.push_back(m_pStartExpr); list.push_back(m_pStepExpr); list.push_back(m_pEndExpr); // Return the list return list; }
/*************************************************************** * Function: ParamExpr::copy() * Purpose : Copy this IIR node recursively * Initial : Maxime Chevalier-Boisvert on November 8, 2008 **************************************************************** Revisions and bug fixes: */ ParamExpr* ParamExpr::copy() const { // Create an argument vector to store the argument copies ExprVector arguments; // Copy each argument for (ExprVector::const_iterator itr = m_arguments.begin(); itr != m_arguments.end(); ++itr) arguments.push_back((Expression*)(*itr)->copy()); // Create and return a copy of this node return new ParamExpr( m_pSymbolExpr->copy(), arguments ); }
/*************************************************************** * Function: AssignStmt::copy() * Purpose : Copy this IIR node recursively * Initial : Maxime Chevalier-Boisvert on November 6, 2008 **************************************************************** Revisions and bug fixes: */ AssignStmt* AssignStmt::copy() const { // Create a vector for the left expression copies ExprVector leftExprs; // Copy each left expression for (ExprVector::const_iterator itr = m_leftExprs.begin(); itr != m_leftExprs.end(); ++itr) leftExprs.push_back((*itr)->copy()); // Create and return a copy of this node return new AssignStmt( leftExprs, m_pRightExpr->copy(), m_suppressOut ); }
void HC4Revise::vector_bwd(const ExprVector& v, ExprLabel** compL, const ExprLabel& y) { if (v.dim.is_vector()) { for (int i=0; i<v.length(); i++) if ((compL[i]->d->i() &= y.d->v()[i]).is_empty()) throw EmptyBoxException(); } else { if (v.row_vector()) for (int i=0; i<v.length(); i++) { if ((compL[i]->d->v()&=y.d->m().col(i)).is_empty()) throw EmptyBoxException(); } else for (int i=0; i<v.length(); i++) { if ((compL[i]->d->v()&=y.d->m().row(i)).is_empty()) throw EmptyBoxException(); } } }
// Return true if a comma (or closing brace) is necessary after the // __if_exists/if_not_exists statement. bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs, bool &InitExprsOk) { bool trailingComma = false; IfExistsCondition Result; if (ParseMicrosoftIfExistsCondition(Result)) return false; BalancedDelimiterTracker Braces(*this, tok::l_brace); if (Braces.consumeOpen()) { Diag(Tok, diag::err_expected) << tok::l_brace; return false; } switch (Result.Behavior) { case IEB_Parse: // Parse the declarations below. break; case IEB_Dependent: Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists) << Result.IsIfExists; // Fall through to skip. case IEB_Skip: Braces.skipToEnd(); return false; } while (!isEofOrEom()) { trailingComma = false; // If we know that this cannot be a designation, just parse the nested // initializer directly. ExprResult SubElt; if (MayBeDesignationStart()) SubElt = ParseInitializerWithPotentialDesignator(); else SubElt = ParseInitializer(); if (Tok.is(tok::ellipsis)) SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken()); // If we couldn't parse the subelement, bail out. if (!SubElt.isInvalid()) InitExprs.push_back(SubElt.release()); else InitExprsOk = false; if (Tok.is(tok::comma)) { ConsumeToken(); trailingComma = true; } if (Tok.is(tok::r_brace)) break; } Braces.consumeClose(); return !trailingComma; }
// Flatten out all expressions with a given head. void Expression::Flatten(const string head) { ExprVector newLeaves; newLeaves.reserve(leaves.size()); for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf) if((*leaf)->FunctionName() == head) { for(ExprVector::const_iterator subLeaf = (*leaf)->Leaves().begin(); subLeaf != (*leaf)->Leaves().end(); ++subLeaf) newLeaves.push_back(*subLeaf); (*leaf)->Leaves().clear(); delete *leaf; } else newLeaves.push_back(*leaf); leaves = newLeaves; }
void TransformVector::MakeElementExprs(DeclVector &DeclVec, ExprVector &ExprVec, ExtVectorElementExpr *E) { llvm::SmallVector<unsigned, 4> Indices; E->getEncodedElementAccess(Indices); Expr *BE = E->getBase(); // If E is an arrow expression, the base pointer expression needs to be // converted into a vector value expression. if (E->isArrow()) { QualType BaseTy = BE->getType(); const PointerType *PTy = BaseTy->getAs<PointerType>(); assert(PTy && "Not a pointer type"); BE = new (ASTCtx) UnaryOperator(BE, UO_Deref, PTy->getPointeeType(), VK_RValue, OK_Ordinary, SourceLocation()); BE = new (ASTCtx) ParenExpr(SourceLocation(), SourceLocation(), BE); } if (ExtVectorElementExpr *BP = dyn_cast<ExtVectorElementExpr>(BE)) { ExprVector BaseExprVec; MakeElementExprs(DeclVec, BaseExprVec, BP); for (unsigned i = 0, e = Indices.size(); i < e; i++) { ExprVec.push_back(BaseExprVec[Indices[i]]); } } else if (CompoundLiteralExpr *BP = dyn_cast<CompoundLiteralExpr>(BE)) { for (unsigned i = 0, e = Indices.size(); i < e; i++) { Expr *ElemE = GetSingleValueOfVecLiteral(DeclVec, BP, Indices[i]); ExprVec.push_back(ElemE); } } else { Expr *NewBE = ConvertVecLiteralInExpr(DeclVec, BE); const ExtVectorType *VecTy = NewBE->getType()->getAs<ExtVectorType>(); assert(VecTy && "The type of BaseExpr is not a vector type."); QualType ElemTy = VecTy->getElementType(); SourceLocation loc; for (unsigned i = 0, e = Indices.size(); i < e; i++) { unsigned Kind = CLExpressions::ZERO + Indices[i]; ArraySubscriptExpr *ElemE = new (ASTCtx) ArraySubscriptExpr( NewBE, CLExprs.getExpr((CLExpressions::ExprKind)(Kind)), ElemTy, VK_RValue, OK_Ordinary, loc); ExprVec.push_back(ElemE); } } }
ExprVector EntityBase::FaceGetPointExprs(void) { ExprVector r; if(type == FACE_NORMAL_PT) { r = SK.GetEntity(point[0])->PointGetExprs(); } else if(type == FACE_XPROD) { r = ExprVector::From(numPoint); } else if(type == FACE_N_ROT_TRANS) { // The numerical point gets the rotation and translation. ExprVector trans = ExprVector::From(param[0], param[1], param[2]); ExprQuaternion q = ExprQuaternion::From(param[3], param[4], param[5], param[6]); r = ExprVector::From(numPoint); r = q.Rotate(r); r = r.Plus(trans); } else if(type == FACE_N_TRANS) { ExprVector trans = ExprVector::From(param[0], param[1], param[2]); r = ExprVector::From(numPoint); r = r.Plus(trans.ScaledBy(Expr::From(timesApplied))); } else if(type == FACE_N_ROT_AA) { ExprVector trans = ExprVector::From(param[0], param[1], param[2]); ExprQuaternion q = GetAxisAngleQuaternionExprs(3); r = ExprVector::From(numPoint); r = r.Minus(trans); r = q.Rotate(r); r = r.Plus(trans); } else oops(); return r; }
/*************************************************************** * Function: ParamExpr::getSubExprs() * Purpose : Access sub-expressions * Initial : Maxime Chevalier-Boisvert on January 8, 2009 **************************************************************** Revisions and bug fixes: */ Expression::ExprVector ParamExpr::getSubExprs() const { // Create a list to store the sub-expression pointers ExprVector list; // Add the symbol to the list list.push_back(m_pSymbolExpr); // For each argument for (size_t i = 0; i < m_arguments.size(); ++i) { // Add the sub-expression to the list list.push_back(m_arguments[i]); } // Return the list return list; }
void ExprCopy::visit(const ExprVector& e) { for (int i=0; i<e.nb_args; i++) visit(e.arg(i)); if (fold) { int i=0; for (; i<e.nb_args; i++) { if (!dynamic_cast<const ExprConstant*>(&ARG(i))) break; } if (i==e.nb_args) { if (e.dim.is_vector()) { IntervalVector v(e.dim.vec_size()); for (i=0; i<e.nb_args; i++) { v[i]=((const ExprConstant&) ARG(i)).get_value(); } clone.insert(e, &ExprConstant::new_vector(v,e.row_vector())); } else if (e.dim.type()==Dim::MATRIX) { IntervalMatrix m(e.dim.dim2,e.dim.dim3); for (i=0; i<e.nb_args; i++) { m.set_row(i,((const ExprConstant&) ARG(i)).get_vector_value()); } clone.insert(e, &ExprConstant::new_matrix(m)); } else { assert(e.dim.type()==Dim::MATRIX_ARRAY); IntervalMatrixArray ma(e.dim.dim1,e.dim.dim2,e.dim.dim3); for (i=0; i<e.nb_args; i++) { ma[i]=((const ExprConstant&) ARG(i)).get_matrix_value(); } clone.insert(e, &ExprConstant::new_matrix_array(ma)); } return; } } Array<const ExprNode> args2(e.nb_args); for (int i=0; i<e.nb_args; i++) { args2.set_ref(i,ARG(i)); // don't remove this node even if it is a constant because // it is an element of this vector. mark(e.arg(i)); } clone.insert(e, &ExprVector::new_(args2,e.row_vector())); }
void ConstantGenerator::visit(const ExprVector& e) { // TODO: test Domain* d= new Domain(e.dim); // assert(d->dim.is_vector() || d->dim.type()==Dim::MATRIX); // we forbid a "vector operation" between constants // to yield an array of matrices for (int i=0; i<e.nb_args; i++) { visit(e.arg(i)); NOT_INF; const Domain* di=map[e.arg(i)]; if (d->dim.is_vector()) d->v()[i]=di->i(); else if (d->dim.type()==Dim::MATRIX) d->m()[i]=di->v(); else d->ma()[i]=di->m(); delete di; } map.insert(e, d); }
void Expression::SubstituteSlots(const ExprVector &slots) { string functionName = FunctionName(); if(functionName == "Slot") { IntegerType index; if(leaves.empty()) index = 1; else { //MachineInteger *indexInt = leaves.at(0)->MachineIntegerHead(); Integer *indexInt(dynamic_cast<Integer*>(leaves.at(0)->NumberHead())); if(indexInt) index = indexInt->IntValue(); else throw EvaluateException("Slot expected to have an Integer argument."); } Expression *slot; if(index > 0 && index-1 < slots.size()) slot = slots.at(static_cast<ExprVector::size_type>(index-1)); else throw EvaluateException("Slot not given."); AssignCloned(slot); } else if(functionName == "SlotSequence") { delete head; head = new Expression("Sequence"); DeleteLeaves(); leaves.reserve(slots.size()); for(ExprVector::const_iterator leaf = slots.begin(); leaf != slots.end(); ++leaf) AppendLeaf((*leaf)->Clone()); } else if(functionName != "Function") { if(head) head->SubstituteSlots(slots); for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf) (*leaf)->SubstituteSlots(slots); } }
void EntityBase::PointGetExprsInWorkplane(hEntity wrkpl, Expr **u, Expr **v) { if(type == POINT_IN_2D && workplane.v == wrkpl.v) { // They want our coordinates in the form that we've written them, // very nice. *u = Expr::From(param[0]); *v = Expr::From(param[1]); } else { // Get the offset and basis vectors for this weird exotic csys. EntityBase *w = SK.GetEntity(wrkpl); ExprVector wp = w->WorkplaneGetOffsetExprs(); ExprVector wu = w->Normal()->NormalExprsU(); ExprVector wv = w->Normal()->NormalExprsV(); // Get our coordinates in three-space, and project them into that // coordinate system. ExprVector ev = PointGetExprs(); ev = ev.Minus(wp); *u = ev.Dot(wu); *v = ev.Dot(wv); } }
void RecursiveCFGBuilder::visit(ShPtr<IfStmt> stmt) { ShPtr<CFG::Node> beforeIfNode(currNode); // Create a node for the if statement. ShPtr<CFG::Node> ifNode(new CFG::Node()); firstStmtNodeMapping[stmt] = ifNode; cfg->stmtNodeMapping[stmt] = ifNode; ifNode->stmts.push_back(stmt); cfg->addNode(ifNode); cfg->addEdge(beforeIfNode, ifNode); // Create a node for the bodies of the if statement. ExprVector conds; for (auto i = stmt->clause_begin(), e = stmt->clause_end(); i != e; ++i) { ShPtr<CFG::Node> clauseBody(addNode(i->second)); cfg->addEdge(ifNode, clauseBody, generateIfCondEdgeLabel(conds, i->first)); conds.push_back(i->first); } // Create a node for the else clause/statement's successor. If there is an // else clause, then we don't have to generate a node for the statement's // successor here. Indeed, if the else clause always ends with a return // statement, then the statement's successor is never entered. If the else // clause doesn't always ends with a return, the statement's successor will // be traversed when adding a node for the else clause. if (stmt->hasElseClause()) { ShPtr<CFG::Node> clauseBody(addNode(stmt->getElseClause())); cfg->addEdge(ifNode, clauseBody, generateIfCondEdgeLabel(conds)); return; } ShPtr<Expression> edgeCond(generateIfCondEdgeLabel(conds)); if (ShPtr<Statement> stmtSucc = stmt->getSuccessor()) { ShPtr<CFG::Node> afterIfNode(addNode(stmtSucc)); cfg->addEdge(ifNode, afterIfNode, edgeCond); return; } currNode = ifNode; addForwardOrBackwardEdge(stmt, edgeCond); }
void RemoveUnusedStructField::handleOneVarDecl(const VarDecl *VD) { const Type *Ty = VD->getType().getTypePtr(); const RecordDecl *RD = getBaseRecordDef(Ty); if (!RD) return; IndexVector *IdxVec = RecordDeclToField[RD]; if (!IdxVec) return; const Expr *InitE = VD->getInit(); TransAssert(InitE && "Need initializer!"); ExprVector InitExprs; getInitExprs(Ty, InitE, IdxVec, InitExprs); for (ExprVector::iterator I = InitExprs.begin(), E = InitExprs.end(); I != E; ++I) { removeOneInitExpr(*I); } }
void OpReplaceAll::Apply(Expression *expression, Calculator *calculator, int32 recursions) { if(expression->LeafCount() != 2) throw ArgumentException("ReplaceAll expects 2 arguments."); string leafFunction = expression->Leaf(1)->FunctionName(); if(leafFunction != "Rule" && leafFunction != "RuleDelayed" && leafFunction != "List") throw ArgumentException("ReplaceAll expects its second argument to be a rule or a list of rules."); if(leafFunction == "List") { for(ExprVector::const_iterator item = expression->Leaf(1)->Leaves().begin(); item != expression->Leaf(1)->Leaves().end(); ++ item) if((*item)->FunctionName() != "Rule" && (*item)->FunctionName() != "RuleDelayed") throw ArgumentException("ReplaceAll expects its second argument to be a rule or a list of rules."); expression->Leaf(0)->ReplaceAll(expression->Leaf(1)->Leaves(), calculator); } else { ExprVector rules; rules.push_back(expression->Leaf(1)); expression->Leaf(0)->ReplaceAll(rules, calculator); } expression->AssignLeaf(0); expression->Evaluate(calculator, recursions); }
Stmt *TransformVector::VisitInitListExpr(InitListExpr *Node) { // For conventional vector literals such as '{1, 2, 3, 4}' QualType ETy = Node->getType(); if (ETy->isExtVectorType()) { CompoundLiteralExpr *CLE = new (ASTCtx) CompoundLiteralExpr( SourceLocation(), ASTCtx.getTrivialTypeSourceInfo(ETy), ETy, Node->getValueKind(), Node, false); return VisitCompoundLiteralExpr(CLE); } if (NeedFlattening) { ExprVector InitExprs; ExprVector *PrvInitExprs = CurInitExprs; CurInitExprs = &InitExprs; for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) { assert(Node->getInit(i) && "NULL InitExpr?"); Expr *InitExpr = TransformExpr(Node->getInit(i)); InitExprs.push_back(InitExpr); } for (unsigned i =0, e = InitExprs.size(); i < e; ++i) { Node->updateInit(ASTCtx, i, InitExprs[i]); } CurInitExprs = PrvInitExprs; } else { for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) { if (Node->getInit(i)) { Node->setInit(i, TransformExpr(Node->getInit(i))); } } } return Node; }
void Affine2Eval::vector_fwd(const ExprVector& v, const ExprLabel** compL, ExprLabel& y) { assert(v.type()!=Dim::SCALAR); assert(v.type()!=Dim::MATRIX_ARRAY); if (v.dim.is_vector()) { for (int i=0; i<v.length(); i++) { y.af2->v()[i]=compL[i]->af2->i(); y.d->v()[i]=compL[i]->d->i(); } } else { if (v.row_vector()) for (int i=0; i<v.length(); i++) { y.af2->m().set_col(i,compL[i]->af2->v()); y.d->m().set_col(i,compL[i]->d->v()); } else for (int i=0; i<v.length(); i++) { y.af2->m().set_row(i,compL[i]->af2->v()); y.d->m().set_row(i,compL[i]->d->v()); } } }
void Group::GenerateEquations(IdList<Equation,hEquation> *l) { Equation eq; ZERO(&eq); if(type == IMPORTED) { // Normalize the quaternion ExprQuaternion q = { Expr::From(h.param(3)), Expr::From(h.param(4)), Expr::From(h.param(5)), Expr::From(h.param(6)) }; AddEq(l, (q.Magnitude())->Minus(Expr::From(1)), 0); } else if(type == ROTATE) { // The axis and center of rotation are specified numerically #define EC(x) (Expr::From(x)) #define EP(x) (Expr::From(h.param(x))) ExprVector orig = SK.GetEntity(predef.origin)->PointGetExprs(); AddEq(l, (orig.x)->Minus(EP(0)), 0); AddEq(l, (orig.y)->Minus(EP(1)), 1); AddEq(l, (orig.z)->Minus(EP(2)), 2); // param 3 is the angle, which is free Vector axis = SK.GetEntity(predef.entityB)->VectorGetNum(); axis = axis.WithMagnitude(1); AddEq(l, (EC(axis.x))->Minus(EP(4)), 3); AddEq(l, (EC(axis.y))->Minus(EP(5)), 4); AddEq(l, (EC(axis.z))->Minus(EP(6)), 5); #undef EC #undef EP } else if(type == EXTRUDE) { if(predef.entityB.v != Entity::FREE_IN_3D.v) { // The extrusion path is locked along a line, normal to the // specified workplane. Entity *w = SK.GetEntity(predef.entityB); ExprVector u = w->Normal()->NormalExprsU(); ExprVector v = w->Normal()->NormalExprsV(); ExprVector extruden = { Expr::From(h.param(0)), Expr::From(h.param(1)), Expr::From(h.param(2)) }; AddEq(l, u.Dot(extruden), 0); AddEq(l, v.Dot(extruden), 1); } } else if(type == TRANSLATE) { if(predef.entityB.v != Entity::FREE_IN_3D.v) { Entity *w = SK.GetEntity(predef.entityB); ExprVector n = w->Normal()->NormalExprsN(); ExprVector trans; trans = ExprVector::From(h.param(0), h.param(1), h.param(2)); // The translation vector is parallel to the workplane AddEq(l, trans.Dot(n), 0); } } }
ExprQuaternion ExprQuaternion::Times(ExprQuaternion b) { Expr *sa = w, *sb = b.w; ExprVector va = { vx, vy, vz }; ExprVector vb = { b.vx, b.vy, b.vz }; ExprQuaternion r; r.w = (sa->Times(sb))->Minus(va.Dot(vb)); ExprVector vr = vb.ScaledBy(sa).Plus( va.ScaledBy(sb).Plus( va.Cross(vb))); r.vx = vr.x; r.vy = vr.y; r.vz = vr.z; return r; }
void ReduceArrayDim::rewriteSubscriptExpr(const ExprVector &IdxExprs) { ExprVector::const_iterator I = IdxExprs.begin(); const Expr *LastE = (*I); ++I; const Expr *SecE = (*I); RewriteHelper->removeArraySubscriptExpr(LastE); int LastIdx = -1; int SecIdx = -1; if (isIntegerExpr(LastE)) LastIdx = getIndexAsInteger(LastE); if (isIntegerExpr(SecE)) SecIdx = getIndexAsInteger(SecE); if ((LastIdx >= 0) && (SecIdx >= 0)) { int NewIdx = (SecIdx * ArraySz + LastIdx); std::stringstream TmpSS; TmpSS << NewIdx; RewriteHelper->replaceExpr(SecE, TmpSS.str()); return; } std::string LastStr, SecStr, newStr; RewriteHelper->getExprString(LastE, LastStr); RewriteHelper->getExprString(SecE, SecStr); std::stringstream TmpSS; if (ArraySz == 1) { TmpSS << SecStr << "+" << LastStr; } else if (SecIdx == 1) { TmpSS << ArraySz << "+" << LastStr; } else { TmpSS << "(" << SecStr << ")*" << ArraySz << "+" << LastStr; } RewriteHelper->replaceExpr(SecE, TmpSS.str()); }