void CG3DGraphicsGL::ApplyStencil(CG3DStencilSet* set) { GLenum face; switch (set->m_Face) { case CG3DStencilSet::FRONT: face = GL_FRONT; break; case CG3DStencilSet::BACK: face = GL_BACK; break; case CG3DStencilSet::FRONT_AND_BACK: face = GL_FRONT_AND_BACK; break; } glStencilMaskSeparate(face, set->m_Mask); switch (set->m_Func) { case CG3DStencilSet::ALWAYS: glDisable(GL_STENCIL_TEST); break; case CG3DStencilSet::NEVER: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_NEVER, set->m_FuncRef, set->m_FuncMask); break; case CG3DStencilSet::LESS: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_LESS, set->m_FuncRef, set->m_FuncMask); break; case CG3DStencilSet::LEQUAL: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_LEQUAL, set->m_FuncRef, set->m_FuncMask); break; case CG3DStencilSet::EQUAL: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_EQUAL, set->m_FuncRef, set->m_FuncMask); break; case CG3DStencilSet::GREATER: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_GREATER, set->m_FuncRef, set->m_FuncMask); break; case CG3DStencilSet::GEQUAL: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_GEQUAL, set->m_FuncRef, set->m_FuncMask); break; case CG3DStencilSet::NOTEQUAL: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_NOTEQUAL, set->m_FuncRef, set->m_FuncMask); break; } glStencilOpSeparate(face, GetOp(set->m_StencilFail), GetOp(set->m_DepthFail), GetOp(set->m_DepthPass)); if (set->m_OtherFace != NULL) ApplyStencil(set->m_OtherFace); }
bool GrammarConst::operator == (const GrammarNode& Other) const { auto OtherPtr = Other.As<GrammarConst>(); if (OtherPtr == nullptr) { return false; } return (OtherPtr->GetOp()->GetID() == GetOp()->GetID()); }
void AccessDependenceChecker::Initialize(const SubExprTable &sub_expr_table, Identifier *loop_index_tmp) { for (auto subscript : access1_) { op1_.push_back(GetOp(subscript, sub_expr_table, loop_index_tmp)); } for (auto subscript : access2_) { op2_.push_back(GetOp(subscript, sub_expr_table, loop_index_tmp)); } }
int main() { int N, Sn, X; Stack S; int done = 0; scanf("%d", &N); S = CreateStack(N); while ( !done ) { switch( GetOp() ) { case push: scanf("%d %d", &Sn, &X); if (!Push(X, S, Sn)) printf("Stack %d is Full!\n", Sn); break; case pop: scanf("%d", &Sn); X = Top_Pop(S, Sn); if ( X==ERROR ) printf("Stack %d is Empty!\n", Sn); break; case end: PrintStack(S, 1); PrintStack(S, 2); done = 1; break; } } return 0; }
SMTExpr UserFormalParamExpression::ToSMT(TheoremProver* TP, ExpSubstMap SubstExps, const vector<SMTExpr>& BaseExprs, vector<SMTExpr>& Assumptions) const { return BaseExprs[GetOp()->GetPosition()]; }
int main() { ElementType X; Deque D; int done = 0; D = CreateDeque(); while (!done) { switch (GetOp()) { case push: scanf("%d", &X); if (!Push(X, D)) printf("Memory is Full!\n"); break; case pop: X = Pop(D); if ( X == ERROR ) printf("Deque is Empty!\n"); break; case inject: scanf("%d", &X); if (!Inject(X, D)) printf("Memory is Full!\n"); break; case eject: X = Eject(D); if ( X == ERROR ) printf("Deque is Empty!\n"); break; case end: PrintDeque(D); done = 1; break; } } system("pause"); return 0; }
void ExprPointer::Visit(BinaryExpr* node) { //TODO node->first->Accept(this); string firstResult{result}; node->second->Accept(this); result = '(' + string() + GetOp(node->op) + string(" ") + firstResult + string(" ") + result + ')'; }
SMTExpr UserSynthFuncExpression::ToSMT(TheoremProver* TP, ExpSubstMap SubstExps, const vector<SMTExpr>& BaseExprs, vector<SMTExpr>& Assumptions) const { auto MyID = GetOp()->GetPosition(); return GenExpressionBase::ToSMT(SubstExps[MyID], TP, ParameterMap, BaseExprs, Assumptions); }
void UserSynthFuncExpression::Evaluate(ExpSubstMap SubstExps, VariableMap VarMap, ConcreteValueBase* Result) const { auto MyID = GetOp()->GetPosition(); GenExpressionBase::Evaluate(const_cast<GenExpressionBase*>(SubstExps[MyID]), VarMap, ParameterMap, Result); }
string UserConstExpression::ToString() const { auto Op = GetOp(); if (Op->IsAnon()) { return Op->GetConstantValue()->ToString(); } else { return Op->GetName(); } }
bool GrammarFunc::operator == (const GrammarNode& Other) const { auto OtherPtr = Other.As<GrammarFunc>(); if (OtherPtr == nullptr) { return false; } if (OtherPtr->GetOp()->GetID() != GetOp()->GetID()) { return false; } const uint32 NumChildren = Children.size(); for (uint32 i = 0; i < NumChildren; ++i) { if (Children[i] != OtherPtr->Children[i]) { return false; } } return true; }
bool CScript::HasValidOps() const { CScript::const_iterator it = begin(); while (it < end()) { opcodetype opcode; std::vector<unsigned char> item; if (!GetOp(it, opcode, item) || opcode > MAX_OPCODE || item.size() > MAX_SCRIPT_ELEMENT_SIZE) { return false; } } return true; }
bool CScript::IsPushOnly(const_iterator pc) const { while (pc < end()) { opcodetype opcode; if (!GetOp(pc, opcode)) return false; // Note that IsPushOnly() *does* consider OP_RESERVED to be a // push-type opcode, however execution of OP_RESERVED fails, so // it's not relevant to P2SH/BIP62 as the scriptSig would fail prior to // the P2SH special validation code being executed. if (opcode > OP_16) return false; } return true; }
bool Grammar::InstantiateDFS(GrammarNode* GNode, const set<string>& CurVars, CEMapType& CanonExpansions) { auto FuncNode = GNode->As<GrammarFunc>(); if (FuncNode != nullptr) { return InstantiateDFSFunc(FuncExtNode(FuncNode, CurVars), CanonExpansions); } auto NTNode = GNode->As<GrammarNonTerminal>(); if (NTNode != nullptr) { auto it = CanonExpansions.find(NTExtNode(NTNode, CurVars)); if (it == CanonExpansions.end()) { return InstantiateDFSNT(NTExtNode(NTNode, CurVars), CanonExpansions); } else { return true; } } auto LetVarNode = GNode->As<GrammarLetVar>(); if (LetVarNode != nullptr) { // Check if we can instantiate if (CurVars.find(LetVarNode->GetOp()->GetName()) != CurVars.end()) { return true; } else { return false; } } auto LetNode = GNode->As<GrammarLet>(); if (LetNode != nullptr) { // Check if the bindings can be done successfully for (auto const& KV : LetNode->GetBindings()) { if (!InstantiateDFS(const_cast<GrammarNode*>(KV.second), CurVars, CanonExpansions)) { return false; } } // Bindings okay. // Recurse with new set of vars set<string> NewVars = CurVars; for (auto const& KV : LetNode->GetBindings()) { NewVars.insert(KV.first->GetOp()->GetName()); } return InstantiateDFS(const_cast<GrammarNode*>(LetNode->GetBoundExpression()), NewVars, CanonExpansions); } // return true for everything else return true; }
bool UserSynthFuncExpression::Equals(const UserExpressionBase& Other) const { auto OtherPtr = Other.As<UserSynthFuncExpression>(); if (OtherPtr == nullptr) { return false; } if (OtherPtr->GetOp()->GetID() != Op->GetID()) { return false; } const uint32 NumChildren = Children.size(); for (uint32 i = 0; i < NumChildren; ++i) { if (OtherPtr->Children[i] != Children[i]) { return false; } } return true; }
//passed as parameters are our input and output files, //read data from the input file and write our instructions to the output file void RWInput(char in[], char out[]) { int i = 0, x = 0; fp = fopen(in, "r"); if(fp == NULL) { printf("ERROR OPENING FILE %s!!\n", in); } //read in our initial instruction fscanf(fp, "%d%d%d", &code[i].op, &code[i].l, &code[i].m); //read in all additional instructions while(!feof(fp)) { i++; fscanf(fp, "%d%d%d", &code[i].op, &code[i].l, &code[i].m); } fclose(fp); fp = fopen(out, "w"); if(fp == NULL) { printf("ERROR OPENING FILE %s!!\n", out); } //format and output line headers fprintf(fp, "%-5s %-5s%-5s%-5s\n", "Line", "OP", "L", "M"); //print out our correctly formatted instructions for(x = 0; x < i; x++) { char op[4]; strcpy(op, GetOp(code[x])); fprintf(fp, "%4d %-5s %-5d%-5d\n", x, op, code[x].l, code[x].m); } fprintf(fp, "\n\n"); fprintf(fp," %-5s%-5s%-5s%s\n", "pc", "bp", "sp", "stack"); }
void ExpressionPointer::Visit(BinaryExpression* node) { stack_bo.push(node->Op); // push current operator //check the left child node->First->IsLeft = true; auto left = dynamic_cast<BinaryExpression*>(node->First.get()); if (left == nullptr) Visit(dynamic_cast<NumberExpression*>(node->First.get())); else Visit(left); string leftResult = result + GetOp(node->Op); // check the right child auto right = dynamic_cast<BinaryExpression*>(node->Second.get()); if (right == nullptr) Visit(dynamic_cast<NumberExpression*>(node->Second.get())); else Visit(right); stack_bo.pop(); // pop current operator result = leftResult + result; // check current according the isleft flag and top of stack(parent) if (stack_bo.size() != 0) { // not the root, so we should check BinaryOperator parentOp = stack_bo.top(); if (node->IsLeft) { // current is left child if ((node->Op == BinaryOperator::Plus || node->Op == BinaryOperator::Minus) && (parentOp == BinaryOperator::Multiply || parentOp == BinaryOperator::Divide)) { result = "(" + result + ")"; } } else { // is right child if ((parentOp == BinaryOperator::Divide) || ((parentOp == BinaryOperator::Minus || parentOp == BinaryOperator::Multiply) && (node->Op == BinaryOperator::Plus || node->Op == BinaryOperator::Minus))) { result = "(" + result + ")"; } } } }
unsigned int CScript::GetSigOpCount(bool fAccurate) const { unsigned int n = 0; const_iterator pc = begin(); opcodetype lastOpcode = OP_INVALIDOPCODE; while (pc < end()) { opcodetype opcode; if (!GetOp(pc, opcode)) break; if (opcode == OP_CHECKSIG || opcode == OP_CHECKSIGVERIFY) n++; else if (opcode == OP_CHECKMULTISIG || opcode == OP_CHECKMULTISIGVERIFY) { if (fAccurate && lastOpcode >= OP_1 && lastOpcode <= OP_16) n += DecodeOP_N(lastOpcode); else n += MAX_PUBKEYS_PER_MULTISIG; } lastOpcode = opcode; } return n; }
bool XQNode_t::IsEqualTo ( const XQNode_t * pNode ) { if ( !pNode || pNode->GetHash()!=GetHash() || pNode->GetOp()!=GetOp() ) return false; if ( m_dWords.GetLength() ) { // two plain nodes. let's compare the keywords if ( pNode->m_dWords.GetLength()!=m_dWords.GetLength() ) return false; if ( !m_dWords.GetLength() ) return true; SmallStringHash_T<int> hSortedWords; ARRAY_FOREACH ( i, pNode->m_dWords ) hSortedWords.Add ( 0, pNode->m_dWords[i].m_sWord ); ARRAY_FOREACH ( i, m_dWords ) if ( !hSortedWords.Exists ( m_dWords[i].m_sWord ) ) return false; return true; } // two non-plain nodes. let's compare the children if ( pNode->m_dChildren.GetLength()!=m_dChildren.GetLength() ) return false; if ( !m_dChildren.GetLength() ) return true; ARRAY_FOREACH ( i, m_dChildren ) if ( !pNode->m_dChildren[i]->IsEqualTo ( m_dChildren[i] ) ) return false; return true; }
//write results to output //status indicates if we are writing out the pointers, stack, or the instruction void WriteToOutput(int status) { int i=0, numAr = 0; char op[4]; strcpy(op, GetOp(ir)); //determine what we need to write switch(status) { //write the instruction case 1: fprintf(fp,"%2d %-5s%-5d%-5d", pcprev, op, ir.l, ir.m); break; //write the pointers case 2: fprintf(fp,"%-5d%-5d%-5d", pc, bp, sp); break; //write our formatted stack case 3: for(i = 0; i <= sp; i++) { //dertermine if we need to print an activation record bar if(numAr < ars && i == arBreak[numAr] && i != 0) { numAr++; fprintf(fp, "| "); } //print our stack content fprintf(fp, "%d ", stack[i]); } fprintf(fp,"\n"); break; } }
bool Cursor::First(size_t *ksz, void **key, size_t *dsz, void **data){ return GetOp(ksz,key,dsz,data,MDB_FIRST); }
GenExpTLVec* CFGEnumeratorSingle::PopulateExpsOfGNCost(const GrammarNode* GN, uint32 Cost, bool Complete) { auto Retval = new GenExpTLVec(); GNCostPair Key(GN, Cost); Done = false; auto Type = GN->GetType(); PushExpansion(GN->ToString()); auto const ExpansionTypeID = GetExpansionTypeID(); auto FPVar = GN->As<GrammarFPVar>(); // The base cases if (FPVar != nullptr) { return MakeBaseExpression<GenFPExpression>(Retval, FPVar->GetOp(), Type, ExpansionTypeID, Cost, Key, Complete); } auto LetVar = GN->As<GrammarLetVar>(); if (LetVar != nullptr) { return MakeBaseExpression<GenLetVarExpression>(Retval, LetVar->GetOp(), Type, ExpansionTypeID, Cost, Key, Complete); } auto Const = GN->As<GrammarConst>(); if (Const != nullptr) { return MakeBaseExpression<GenConstExpression>(Retval, Const->GetOp(), Type, ExpansionTypeID, Cost, Key, Complete); } auto Func = GN->As<GrammarFunc>(); if (Func != nullptr) { auto const& Args = Func->GetChildren(); auto Op = Func->GetOp(); const uint32 OpCost = Op->GetCost(); const uint32 Arity = Op->GetArity(); if (Cost < Arity + OpCost) { Retval->Freeze(); ExpRepository[Key] = Retval; PopExpansion(); return Retval; } PartitionGenerator* PG; if (Op->IsSymmetric() && Args[0] == Args[1]) { PG = new SymPartitionGenerator(Cost - OpCost); } else { PG = new PartitionGenerator(Cost - OpCost, Arity); } const uint32 NumPartitions = PG->Size(); for (uint32 i = 0; i < NumPartitions; ++i) { auto Feasible = true; vector<const GenExpTLVec*> ArgExpVecs(Arity, nullptr); auto CurPartition = (*PG)[i]; vector<GenExpTLVec::ConstIterator> Begins(Arity); vector<GenExpTLVec::ConstIterator> Ends(Arity); for (uint32 j = 0; j < Arity; ++j) { auto CurVec = GetVecForGNCost(Args[j], CurPartition[j]); if (CurVec == nullptr) { CurVec = PopulateExpsOfGNCost(Args[j], CurPartition[j], false); } if (CurVec->Size() == 0) { Feasible = false; break; } else { ArgExpVecs[j] = CurVec; Begins[j] = CurVec->Begin(); Ends[j] = CurVec->End(); } } if (!Feasible) { continue; } // Iterate over the cross product auto CPGen = new CrossProductGenerator(Begins, Ends, GetPoolForSize(Arity)); for (auto CurArgs = CPGen->GetNext(); CurArgs != nullptr; CurArgs = CPGen->GetNext()) { auto CurExp = new (FuncExpPool->malloc()) GenFuncExpression(static_cast<const InterpretedFuncOperator*>(Op), CurArgs); auto Status = (Complete ? Solver->ExpressionCallBack(CurExp, Type, ExpansionTypeID, Index) : Solver->SubExpressionCallBack(CurExp, Type, ExpansionTypeID)); if ((Status & DELETE_EXPRESSION) == 0) { CPGen->RelinquishOwnerShip(); Retval->PushBack(CurExp); NumExpsCached++; } else { FuncExpPool->free(CurExp); } if ((Status & STOP_ENUMERATION) != 0) { Done = true; break; } } delete CPGen; if (Done) { break; } } delete PG; Retval->Freeze(); ExpRepository[Key] = Retval; PopExpansion(); return Retval; } auto Let = GN->As<GrammarLet>(); // We handle this in similar spirit as functions if (Let != nullptr) { auto const& Bindings = Let->GetBindings(); const uint32 NumBindings = Bindings.size(); const uint32 Arity = NumBindings + 1; auto BoundNode = Let->GetBoundExpression(); const uint32 NumLetBoundVars = TheGrammar->GetNumLetBoundVars(); if (Cost < Arity + 1) { Retval->Freeze(); ExpRepository[Key] = Retval; PopExpansion(); return Retval; } // Making a let binding incurs a cost of 1! auto PG = new PartitionGenerator(Cost - 1, Arity); const uint32 NumPartitions = PG->Size(); for (uint32 i = 0; i < NumPartitions; ++i) { auto Feasible = true; vector<const GenExpTLVec*> ArgExpVecs(Arity, nullptr); auto CurPartition = (*PG)[i]; vector<GenExpTLVec::ConstIterator> Begins(Arity); vector<GenExpTLVec::ConstIterator> Ends(Arity); uint32 j = 0; uint32* Positions = new uint32[NumBindings]; for (auto it = Bindings.begin(); it != Bindings.end(); ++it) { auto CurVec = GetVecForGNCost(it->second, CurPartition[j]); if (CurVec == nullptr) { CurVec = PopulateExpsOfGNCost(it->second, CurPartition[j], false); } if (CurVec->Size() == 0) { Feasible = false; break; } else { ArgExpVecs[j] = CurVec; Begins[j] = CurVec->Begin(); Ends[j] = CurVec->End(); } Positions[j] = it->first->GetOp()->GetPosition(); ++j; } if (!Feasible) { delete[] Positions; continue; } // Finally, the expression set for the bound expression auto BoundVec = GetVecForGNCost(BoundNode, CurPartition[j]); if (BoundVec == nullptr) { BoundVec = PopulateExpsOfGNCost(BoundNode, CurPartition[j], false); } if (BoundVec->Size() == 0) { // cross product is empty not feasible delete[] Positions; continue; } else { ArgExpVecs[NumBindings] = BoundVec; Begins[NumBindings] = BoundVec->Begin(); Ends[NumBindings] = BoundVec->End(); } // Iterate over the cross product of expressions // The bindings object will be of size of the NUMBER // of let bound vars for the whole grammar auto CPGen = new CrossProductGenerator(Begins, Ends, GetPoolForSize(Arity)); GenExpressionBase const** BindVec = nullptr; auto BindVecPool = GetPoolForSize(NumLetBoundVars); for (auto CurArgs = CPGen->GetNext(); CurArgs != nullptr; CurArgs = CPGen->GetNext()) { // We need to build the binding vector based on the position if (BindVec == nullptr) { BindVec = (GenExpressionBase const**)BindVecPool->malloc(); memset(BindVec, 0, sizeof(GenExpressionBase const*) * NumLetBoundVars); } for (uint32 k = 0; k < NumBindings; ++k) { BindVec[Positions[k]] = CurArgs[k]; } auto CurExp = new (LetExpPool->malloc()) GenLetExpression(BindVec, CurArgs[NumBindings], NumLetBoundVars); auto Status = (Complete ? Solver->ExpressionCallBack(CurExp, Type, ExpansionTypeID, Index) : Solver->SubExpressionCallBack(CurExp, Type, ExpansionTypeID)); if ((Status & DELETE_EXPRESSION) == 0) { BindVec = nullptr; Retval->PushBack(CurExp); NumExpsCached++; } else { LetExpPool->free(CurExp); } if ((Status & STOP_ENUMERATION) != 0) { Done = true; break; } } delete CPGen; delete[] Positions; if (Done) { break; } } delete PG; Retval->Freeze(); ExpRepository[Key] = Retval; PopExpansion(); return Retval; } auto NT = GN->As<GrammarNonTerminal>(); if (NT != nullptr) { const vector<GrammarNode*>& Expansions = TheGrammar->GetExpansions(NT); for (auto const& Expansion : Expansions) { auto CurVec = GetVecForGNCost(Expansion, Cost); if (CurVec == nullptr) { CurVec = PopulateExpsOfGNCost(Expansion, Cost, Complete); } Retval->Merge(*CurVec); if (Done) { break; } } Retval->Freeze(); ExpRepository[Key] = Retval; PopExpansion(); return Retval; } // Should NEVER get here throw InternalError((string)"You probably subclassed GrammarNode and forgot to change " + "CFGEnumerator.cpp.\nAt: " + __FILE__ + ":" + to_string(__LINE__)); }
void UserFormalParamExpression::Evaluate(ExpSubstMap SubstExps, VariableMap VarMap, ConcreteValueBase* Result) const { new (Result) ConcreteValueBase(*(VarMap[GetOp()->GetPosition()])); }
bool Cursor::Next(size_t *ksz, void **key, size_t *dsz, void **data){ return GetOp(ksz,key,dsz,data,MDB_NEXT); }
bool Cursor::Set(size_t *ksz, void **key, size_t *dsz, void **data){ return GetOp(ksz,key,dsz,data,MDB_SET); }