void testQuickSort(){ cout<<"***********************"<<endl; cout<<"******quick sort*******"<<endl; Deque<int> deque; deque.push_front(10); deque.push_back(3); deque.push_back(2); deque.push_front(4); deque.output(); hds::quickSort(deque.begin(),deque.end()); deque.output(); hds::quickSort(deque.begin(),deque.end(),hds::Greater<int>()); deque.output(); deque.clear(); for(int i=0;i < 20;++i){ deque.push_back(i+10); } deque.insert(deque.begin()+10,2); deque.insert(deque.begin()+2,34); deque.insert(deque.begin()+16,6); deque.insert(deque.begin()+13,78); deque.output(); hds::quickSort(deque.begin(),deque.end(),hds::Greater<int>()); deque.output(); cout<<"***********************"<<endl; }
int main () { typedef std::deque<int, std::allocator<int> > Deque; typedef std::vector<int, std::allocator<int> > Vector; typedef std::ostream_iterator<int, char, std::char_traits<char> > Iter; // Initialize a deque with an array of integers. const Deque::value_type a[] = { 1, 2, 3, 4, 5, 6, 7 }; Deque d (a + 0, a + sizeof a / sizeof *a); // Create an empty vector to store the factorials. Vector v (Vector::size_type (7)); // Compute factorials of the contents of `d' store results in `v'. std::transform (d.begin (), d.end (), v.begin (), std::ptr_fun (factorial)); // Print the results. std::cout << "The following numbers: \n "; std::copy (d.begin (), d.end (), Iter (std::cout," ")); std::cout << "\n\nHave the factorials: \n "; std::copy (v.begin (), v.end (), Iter (std::cout, " ")); std::cout << std::endl; return 0; }
int main(){ int n; cin>>n; string s; getline(cin,s); Deque dteams; Map mteams; bool first=true; for(int i=0;i<n;i++){ dteams.clear(); mteams.clear(); if(first) first=false; else cout<<endl; getline(cin,s); cout<<s<<endl; int numTeam,numMatch; cin>>numTeam; getline(cin,s); for(int j=0;j<numTeam;j++){ getline(cin,s); dteams.push_back(Team(s)); mteams.insert(make_pair(s,&(dteams.back()))); } cin>>numMatch; getline(cin,s); for(int j=0;j<numMatch;j++){ Team* t1,*t2; int score1,score2; getline(cin,s,'#'); t1=mteams.find(s)->second; cin>>score1; getline(cin,s,'@'); cin>>score2; getline(cin,s,'#'); getline(cin,s); t2=mteams.find(s)->second; t1->goalScored+=score1; t1->goalAgainst+=score2; t2->goalScored+=score2; t2->goalAgainst+=score1; if(score1>score2){t1->win++;t2->lose++;} else if(score1<score2){t1->lose++;t2->win++;} else {t1->tie++;t2->tie++;} } sort(dteams.begin(),dteams.end()); int rank=1; for(Deque::iterator it=dteams.begin();it!=dteams.end();it++,rank++){ cout<<rank<<") "<<it->name<<" "<<it->point()<<"p, "<<it->total()<< "g ("<<it->win<<"-"<<it->tie<<"-"<<it->lose<<"), "<< it->goalDiff()<<"gd ("<<it->goalScored<<"-"<<it->goalAgainst<<")"<<endl; } //cout<<endl; } }
void testShellSort(){ cout<<"***********************"<<endl; cout<<"******shell sort*******"<<endl; Deque<int> deque; deque.push_front(10); deque.push_back(3); deque.push_back(2); deque.push_front(4); deque.output(); hds::shellSort(deque.begin(),deque.end()); deque.output(); hds::shellSort(deque.begin(),deque.end(),hds::Greater<int>()); deque.output(); cout<<"***********************"<<endl; }
void testMergeSortBU(){ cout<<"***********************"<<endl; cout<<"****merge sort BU******"<<endl; Deque<int> deque; deque.push_front(10); deque.push_back(3); deque.push_back(2); deque.push_front(4); deque.output(); hds::mergeSortBU(deque.begin(),deque.end()); deque.output(); hds::mergeSortBU(deque.begin(),deque.end(),hds::Greater<int>()); deque.output(); cout<<"***********************"<<endl; }
void testInsertionSort(){ cout<<"***********************"<<endl; cout<<"*****insertion sort****"<<endl; Deque<int> deque; deque.push_front(10); deque.push_back(3); deque.push_back(2); deque.push_front(4); deque.output(); hds::insertionSort(deque.begin(),deque.end()); deque.output(); hds::insertionSort(deque.begin(),deque.end(),hds::Greater<int>()); deque.output(); cout<<"***********************"<<endl; }
bool HarfBuzzShaper::collectFallbackHintChars( const Deque<HolesQueueItem>& holesQueue, Vector<UChar32>& hint) const { if (!holesQueue.size()) return false; hint.clear(); size_t numCharsAdded = 0; for (auto it = holesQueue.begin(); it != holesQueue.end(); ++it) { if (it->m_action == HolesQueueNextFont) break; UChar32 hintChar; RELEASE_ASSERT(it->m_startIndex + it->m_numCharacters <= m_normalizedBufferLength); UTF16TextIterator iterator(m_normalizedBuffer + it->m_startIndex, it->m_numCharacters); while (iterator.consume(hintChar)) { hint.append(hintChar); numCharsAdded++; iterator.advance(); } } return numCharsAdded > 0; }
void ExecutionContext::notifyContextDestroyed() { Deque<OwnPtr<SuspendableTask>> suspendedTasks; suspendedTasks.swap(m_suspendedTasks); for (Deque<OwnPtr<SuspendableTask>>::iterator it = suspendedTasks.begin(); it != suspendedTasks.end(); ++it) (*it)->contextDestroyed(); ContextLifecycleNotifier::notifyContextDestroyed(); }
int main () { play_poker (); print_current_hand (current_hand.begin (), current_hand.end ()); return 0; }
int main () { // Typedefs for convenience. typedef std::deque<int, std::allocator<int> > Deque; typedef std::ostream_iterator<int, char, std::char_traits<char> > os_iter; // Initialize a deque using an array. Deque::value_type arr[] = { 3, 4, 7, 8 }; Deque d (arr, arr + sizeof arr / sizeof *arr); // Output the original deque. std::cout << "Start with a deque: \n "; std::copy (d.begin (), d.end (), os_iter (std::cout, " ")); // Insert into the middle. std::insert_iterator<Deque> ins (d, d.begin () + 2); *ins = 5; *ins = 6; // Output the new deque. std::cout << "\n\nUse an insert_iterator: \n "; std::copy (d.begin (), d.end (), os_iter (std::cout, " ")); // A deque of four 1s. Deque d2 (4, 1); // Insert d2 at front of d. std::copy (d2.begin (), d2.end (), std::front_inserter (d)); // Output the new deque. std::cout << "\n\nUse a front_inserter: \n "; std::copy (d.begin (), d.end (), os_iter (std::cout, " ")); // Insert d2 at back of d. std::copy (d2.begin (), d2.end (), std::back_inserter (d)); // Output the new deque. std::cout << "\n\nUse a back_inserter: \n "; std::copy (d.begin (), d.end (), os_iter (std::cout, " ")); std::cout << std::endl; return 0; }
void testAssign() { Deque<int> a; a.push_back(1); a.push_back(2); a.push_back(3); vector<int> b; b.assign(a.begin(), a.end()); SINVARIANT(b.size() == 3); for(int32_t i = 0; i < 3; ++i) { SINVARIANT(b[i] == i+1); } }
void testPushBack() { Deque<int> deque; SINVARIANT(deque.empty()); deque.reserve(8); SINVARIANT(deque.empty() && deque.capacity() == 8); for(int i = 0; i < 5; ++i) { deque.push_back(i); SINVARIANT(deque.back() == i); SINVARIANT(deque.size() == static_cast<size_t>(i + 1)); } for(int i = 0; i < 5; ++i) { SINVARIANT(deque.at(i) == i); } for(int i = 0; i < 5; ++i) { SINVARIANT(deque.front() == i); deque.pop_front(); deque.push_back(i); SINVARIANT(deque.back() == i); SINVARIANT(deque.size() == 5); } for(int i = 0; i < 5; ++i) { SINVARIANT(deque.at(i) == i); } { Deque<int>::iterator i = deque.begin(); int j = 0; while(i != deque.end()) { INVARIANT(*i == j, format("%d != %d") % *i % j); ++i; ++j; } } vector<int> avec; for(int i = 5; i < 10; ++i) { avec.push_back(i); } deque.push_back(avec); for(int i = 0; i < 10; ++i) { SINVARIANT(deque.front() == i); deque.pop_front(); } SINVARIANT(deque.empty()); }
int main () { // Typedefs for convenience. typedef short Value; typedef std::deque<Value, std::allocator<Value> > Deque; typedef std::char_traits<char> Traits; typedef std::ostream_iterator<Value, char, Traits> Iterator; const Value arr[] = { 0, 1, 2, 2, 3, 4, 2, 2, 6, 7 }; // Populate and sort the container. Deque d (arr + 0, arr + sizeof arr / sizeof *arr); std::sort (d.begin (), d.end ()); // Arbitrary values to search for. const Value val_1 = 3; const Value val_2 = 11; // Try binary_search variants. const bool found_1 = std::binary_search (d.begin (), d.end (), val_1); const bool found_2 = std::binary_search (d.begin (), d.end (), val_2, std::less<Value>()); // Output the sorted sequence. std::cout << "Container contents: "; std::copy (d.begin (), d.end (), Iterator (std::cout, " ")); // Output the results of the algorithms. std::cout << "\nThe number " << val_1 << " was " << (found_1 ? "" : "NOT ") << "found"; std::cout << "\nThe number " << val_2 << " was " << (found_2 ? "" : "NOT ") << "found\n"; return 0; }
TEST(WTF_Deque, InitializerList) { Deque<int> deque = { 1, 2, 3, 4 }; EXPECT_EQ(4u, deque.size()); auto it = deque.begin(); auto end = deque.end(); EXPECT_TRUE(end != it); EXPECT_EQ(1, *it); ++it; EXPECT_EQ(2, *it); ++it; EXPECT_EQ(3, *it); ++it; EXPECT_EQ(4, *it); ++it; EXPECT_TRUE(end == it); }
TEST(WTF_Deque, Iterator) { Deque<int> deque; deque.append(11); deque.prepend(10); deque.append(12); deque.append(13); Deque<int>::iterator it = deque.begin(); Deque<int>::iterator end = deque.end(); EXPECT_TRUE(end != it); EXPECT_EQ(10, *it); ++it; EXPECT_EQ(11, *it); ++it; EXPECT_EQ(12, *it); ++it; EXPECT_EQ(13, *it); ++it; EXPECT_TRUE(end == it); }
void FullscreenElementStack::webkitExitFullscreen() { // The exitFullscreen() method must run these steps: // 1. Let doc be the context object. (i.e. "this") Document* currentDoc = document(); // 2. If doc's fullscreen element stack is empty, terminate these steps. if (m_fullScreenElementStack.isEmpty()) return; // 3. Let descendants be all the doc's descendant browsing context's documents with a non-empty fullscreen // element stack (if any), ordered so that the child of the doc is last and the document furthest // away from the doc is first. Deque<RefPtr<Document> > descendants; for (Frame* descendant = document()->frame() ? document()->frame()->tree()->traverseNext() : 0; descendant; descendant = descendant->tree()->traverseNext()) { if (fullscreenElementFrom(descendant->document())) descendants.prepend(descendant->document()); } // 4. For each descendant in descendants, empty descendant's fullscreen element stack, and queue a // task to fire an event named fullscreenchange with its bubbles attribute set to true on descendant. for (Deque<RefPtr<Document> >::iterator i = descendants.begin(); i != descendants.end(); ++i) { from(i->get())->clearFullscreenElementStack(); addDocumentToFullScreenChangeEventQueue(i->get()); } // 5. While doc is not null, run these substeps: Element* newTop = 0; while (currentDoc) { // 1. Pop the top element of doc's fullscreen element stack. from(currentDoc)->popFullscreenElementStack(); // If doc's fullscreen element stack is non-empty and the element now at the top is either // not in a document or its node document is not doc, repeat this substep. newTop = fullscreenElementFrom(currentDoc); if (newTop && (!newTop->inDocument() || &newTop->document() != currentDoc)) continue; // 2. Queue a task to fire an event named fullscreenchange with its bubbles attribute set to true // on doc. addDocumentToFullScreenChangeEventQueue(currentDoc); // 3. If doc's fullscreen element stack is empty and doc's browsing context has a browsing context // container, set doc to that browsing context container's node document. if (!newTop && currentDoc->ownerElement()) { currentDoc = ¤tDoc->ownerElement()->document(); continue; } // 4. Otherwise, set doc to null. currentDoc = 0; } // 6. Return, and run the remaining steps asynchronously. // 7. Optionally, perform some animation. if (!document()->page()) return; // Only exit out of full screen window mode if there are no remaining elements in the // full screen stack. if (!newTop) { document()->page()->chrome().client().exitFullScreenForElement(m_fullScreenElement.get()); return; } // Otherwise, notify the chrome of the new full screen element. document()->page()->chrome().client().enterFullScreenForElement(newTop); }
void FullscreenElementStack::requestFullScreenForElement(Element* element, unsigned short flags, FullScreenCheckType checkType) { // The Mozilla Full Screen API <https://wiki.mozilla.org/Gecko:FullScreenAPI> has different requirements // for full screen mode, and do not have the concept of a full screen element stack. bool inLegacyMozillaMode = (flags & Element::LEGACY_MOZILLA_REQUEST); do { if (!element) element = document()->documentElement(); // 1. If any of the following conditions are true, terminate these steps and queue a task to fire // an event named fullscreenerror with its bubbles attribute set to true on the context object's // node document: // The context object is not in a document. if (!element->inDocument()) break; // The context object's node document, or an ancestor browsing context's document does not have // the fullscreen enabled flag set. if (checkType == EnforceIFrameAllowFullScreenRequirement && !fullScreenIsAllowedForElement(element)) break; // The context object's node document fullscreen element stack is not empty and its top element // is not an ancestor of the context object. (NOTE: Ignore this requirement if the request was // made via the legacy Mozilla-style API.) if (!m_fullScreenElementStack.isEmpty() && !inLegacyMozillaMode) { Element* lastElementOnStack = m_fullScreenElementStack.last().get(); if (lastElementOnStack == element || !lastElementOnStack->contains(element)) break; } // A descendant browsing context's document has a non-empty fullscreen element stack. bool descendentHasNonEmptyStack = false; for (Frame* descendant = document()->frame() ? document()->frame()->tree()->traverseNext() : 0; descendant; descendant = descendant->tree()->traverseNext()) { if (fullscreenElementFrom(descendant->document())) { descendentHasNonEmptyStack = true; break; } } if (descendentHasNonEmptyStack && !inLegacyMozillaMode) break; // This algorithm is not allowed to show a pop-up: // An algorithm is allowed to show a pop-up if, in the task in which the algorithm is running, either: // - an activation behavior is currently being processed whose click event was trusted, or // - the event listener for a trusted click event is being handled. if (!ScriptController::processingUserGesture()) break; UserGestureIndicator::consumeUserGesture(); // There is a previously-established user preference, security risk, or platform limitation. if (!document()->page() || !document()->page()->settings().fullScreenEnabled()) break; // 2. Let doc be element's node document. (i.e. "this") Document* currentDoc = document(); // 3. Let docs be all doc's ancestor browsing context's documents (if any) and doc. Deque<Document*> docs; do { docs.prepend(currentDoc); currentDoc = currentDoc->ownerElement() ? ¤tDoc->ownerElement()->document() : 0; } while (currentDoc); // 4. For each document in docs, run these substeps: Deque<Document*>::iterator current = docs.begin(), following = docs.begin(); do { ++following; // 1. Let following document be the document after document in docs, or null if there is no // such document. Document* currentDoc = *current; Document* followingDoc = following != docs.end() ? *following : 0; // 2. If following document is null, push context object on document's fullscreen element // stack, and queue a task to fire an event named fullscreenchange with its bubbles attribute // set to true on the document. if (!followingDoc) { from(currentDoc)->pushFullscreenElementStack(element); addDocumentToFullScreenChangeEventQueue(currentDoc); continue; } // 3. Otherwise, if document's fullscreen element stack is either empty or its top element // is not following document's browsing context container, Element* topElement = fullscreenElementFrom(currentDoc); if (!topElement || topElement != followingDoc->ownerElement()) { // ...push following document's browsing context container on document's fullscreen element // stack, and queue a task to fire an event named fullscreenchange with its bubbles attribute // set to true on document. from(currentDoc)->pushFullscreenElementStack(followingDoc->ownerElement()); addDocumentToFullScreenChangeEventQueue(currentDoc); continue; } // 4. Otherwise, do nothing for this document. It stays the same. } while (++current != docs.end()); // 5. Return, and run the remaining steps asynchronously. // 6. Optionally, perform some animation. m_areKeysEnabledInFullScreen = flags & Element::ALLOW_KEYBOARD_INPUT; document()->page()->chrome().client().enterFullScreenForElement(element); // 7. Optionally, display a message indicating how the user can exit displaying the context object fullscreen. return; } while (0); m_fullScreenErrorEventTargetQueue.append(element ? element : document()->documentElement()); m_fullScreenChangeDelayTimer.startOneShot(0); }
int main(int argc, char *argv[]) { std::set_new_handler(&mem_error); if (!ParseArguments(argc, argv)) { Usage(); exit(-1); } // Disable core dump struct rlimit r_core; r_core.rlim_cur = 0; r_core.rlim_max = 0; setrlimit(RLIMIT_CORE, &r_core); // Set demo limits if (options.demo) { struct rlimit r_cpu, r_as; memlimit = true; r_cpu.rlim_cur = 30; // max 30 secs. r_cpu.rlim_max = 30; setrlimit(RLIMIT_CPU, &r_cpu); r_as.rlim_cur = 20971520; // max 20MB r_as.rlim_max = 20971520; setrlimit(RLIMIT_DATA, &r_as); signal(SIGXCPU, &cpuLimit); } initTimer(); Timer timer_total; timer_total.start(); ///////// PARSING //////////////////////////////////////////////////////// if (options.printProgress) cout << "MONA v" << VERSION << "-" << RELEASE << " for WS1S/WS2S\n" "Copyright (C) 1997-2008 BRICS\n\n" "PARSING\n"; Timer timer_parsing; timer_parsing.start(); loadFile(inputFileName); yyparse(); MonaAST *ast = untypedAST->typeCheck(); lastPosVar = ast->lastPosVar; allPosVar = ast->allPosVar; timer_parsing.stop(); if (options.printProgress) { cout << "Time: "; timer_parsing.print(); } delete untypedAST; if (options.dump) { // Dump AST for main formula, verify formulas, and assertion cout << "Main formula:\n"; (ast->formula)->dump(); Deque<ASTForm *>::iterator vf; Deque<char *>::iterator vt; for (vf = ast->verifyformlist.begin(), vt = ast->verifytitlelist.begin(); vf != ast->verifyformlist.end(); vf++, vt++) { cout << "\n\nFormula " << *vt << ":\n"; (*vf)->dump(); } cout << "\n\nAssertions:\n"; (ast->assertion)->dump(); cout << "\n"; if (lastPosVar != -1) cout << "\nLastPos variable: " << symbolTable.lookupSymbol(lastPosVar) << "\n"; if (allPosVar != -1) cout << "\nAllPos variable: " << symbolTable.lookupSymbol(allPosVar) << "\n"; // Dump ASTs for predicates and macros PredLibEntry *pred = predicateLib.first(); while (pred != NULL) { if (pred->isMacro) cout << "\nMacro '"; else cout << "\nPredicate '"; cout << symbolTable.lookupSymbol(pred->name) << "':\n"; (pred->ast)->dump(); cout << "\n"; pred = predicateLib.next(); } // Dump restrictions if (symbolTable.defaultRestriction1) { cout << "\nDefault first-order restriction (" << symbolTable.lookupSymbol(symbolTable.defaultIdent1) << "):\n"; symbolTable.defaultRestriction1->dump(); cout << "\n"; } if (symbolTable.defaultRestriction2) { cout << "\nDefault second-order restriction (" << symbolTable.lookupSymbol(symbolTable.defaultIdent2) << "):\n"; symbolTable.defaultRestriction2->dump(); cout << "\n"; } Ident id; for (id = 0; id < (Ident) symbolTable.noIdents; id++) { Ident t; ASTForm *f = symbolTable.getRestriction(id, &t); if (f) { cout << "\nRestriction for #" << id << " (" << symbolTable.lookupSymbol(id) << "):"; if (t != -1) cout << " default\n"; else { cout << "\n"; f->dump(); cout << "\n"; } } } } if (options.mode != TREE && (options.graphvizSatisfyingEx || options.graphvizCounterEx || options.inheritedAcceptance)) cout << "Warning: options -gc, -gs, and -h are only used in tree mode\n"; if (options.mode == TREE && options.graphvizDFA) cout << "Warning: option -gw is only used in linear mode\n"; if (options.mode == TREE && (options.dump || options.whole) && !options.externalWhole) printGuide(); ///////// CODE GENERATION //////////////////////////////////////////////// if (options.printProgress) cout << "\nCODE GENERATION\n"; Timer timer_gencode; timer_gencode.start(); // Generate code codeTable = new CodeTable; VarCode formulaCode = ast->formula->makeCode(); VarCode assertionCode = ast->assertion->makeCode(); Deque<VarCode> verifyCode; /* #warning NEW: 'VERIFY' */ for (Deque<ASTForm *>::iterator i = ast->verifyformlist.begin(); i != ast->verifyformlist.end(); i++) verifyCode.push_back((*i)->makeCode()); // Implicitly assert restrictions for all global variables for (IdentList::iterator i = ast->globals.begin(); i != ast->globals.end(); i++) assertionCode = andList(assertionCode, getRestriction(*i, NULL)); // Restrict assertion if not trivial if (assertionCode.code->kind != cTrue) assertionCode = codeTable->insert (new Code_Restrict(assertionCode, assertionCode.code->pos)); // Add assertion to main formula and to all verify formulas for (Deque<VarCode>::iterator i = verifyCode.begin(); i != verifyCode.end(); i++) { assertionCode.code->refs++; *i = andList(*i, VarCode(copy(assertionCode.vars), assertionCode.code)); } formulaCode = andList(formulaCode, assertionCode); timer_gencode.stop(); if (options.printProgress) { codeTable->print_statistics(); /* if (options.dump && options.statistics) codeTable->print_sizes(); */ cout << "Time: "; timer_gencode.print(); } ///////// REORDER BDD OFFSETS //////////////////////////////////////////// if (options.reorder >= 1) { Timer timer_reorder; timer_reorder.start(); if (options.printProgress) cout << "\nREORDERING\n"; // reorder using heuristics offsets.reorder(); // regenerate DAG in new codetable CodeTable *oldCodeTable = codeTable, *newCodeTable = new CodeTable; IdentList emptylist; codeTable = newCodeTable; regenerate = true; // force making new nodes VarCode newcode = formulaCode.substCopy(&emptylist, &emptylist); Deque<VarCode> newverifycode; for (Deque<VarCode>::iterator i = verifyCode.begin(); i != verifyCode.end(); i++) newverifycode.push_back((*i).substCopy(&emptylist, &emptylist)); codeTable->clearSCTable(); regenerate = false; codeTable = oldCodeTable; formulaCode.remove(); for (Deque<VarCode>::iterator i = verifyCode.begin(); i != verifyCode.end(); i++) (*i).remove(); formulaCode = newcode; verifyCode.reset(); for (Deque<VarCode>::iterator i = newverifycode.begin(); i != newverifycode.end(); i++) verifyCode.push_back(*i); delete oldCodeTable; codeTable = newCodeTable; if (options.printProgress) { codeTable->print_statistics2(); cout << "Time: "; timer_reorder.print(); } } ///////// REDUCTION AND CODE DUMPING ///////////////////////////////////// if (options.optimize >= 1) { if (options.printProgress) cout << "\nREDUCTION\n"; Timer timer_reduction; timer_reduction.start(); // Reduce formulaCode.reduceAll(&verifyCode); timer_reduction.stop(); if (options.printProgress) { codeTable->print_reduction_statistics(); /* if (options.dump && options.statistics) codeTable->print_sizes(); */ cout << "Time: "; timer_reduction.print(); } } if (options.dump) { // Dump symboltable symbolTable.dump(); // Dump code cout << "\nMain formula:\n"; formulaCode.dump(); cout << "\n\n"; Deque<VarCode>::iterator i; Deque<char *>::iterator j; for (i = verifyCode.begin(), j = ast->verifytitlelist.begin(); i != verifyCode.end(); i++, j++) { cout << "Formula " << *j << ":\n"; (*i).dump(); cout << "\n\n"; } } if (options.graphvizDAG) { printf("digraph MONA_CODE_DAG {\n" " size = \"7.5,10.5\";\n" " main [shape = plaintext];\n" " main -> L%lx;\n", (unsigned long) formulaCode.code); formulaCode.code->viz(); Deque<VarCode>::iterator i; Deque<char *>::iterator j; for (i = verifyCode.begin(), j = ast->verifytitlelist.begin(); i != verifyCode.end(); i++, j++) { printf(" \"%s\" [shape = plaintext];\n" " \"%s\" -> L%lx;\n", *j, *j, (unsigned long) (*i).code); (*i).code->viz(); } formulaCode.unmark(); for (Deque<VarCode>::iterator i = verifyCode.begin(); i != verifyCode.end(); i++) (*i).unmark(); cout << "}\n"; } ///////// AUTOMATON CONSTRUCTION ///////////////////////////////////////// // Make variable lists Deque<char *> *verifytitlelist = ast->verifytitlelist.copy(); if (lastPosVar != -1) ast->globals.remove(lastPosVar); if (allPosVar != -1) ast->globals.remove(allPosVar); ast->globals.sort(); // sort by id (= index) int numVars = ast->globals.size(); int ix = 0; char **vnames = new char*[numVars]; unsigned *offs = new unsigned[numVars]; char *types = new char[numVars]; int **univs = new int*[numVars]; int *trees = new int[numVars]; SSSet *statespaces = new SSSet[numVars]; IdentList sign, freeVars; IdentList::iterator id; for (id = ast->globals.begin(); id != ast->globals.end(); id++, ix++) { statespaces[ix] = stateSpaces(*id); vnames[ix] = symbolTable.lookupSymbol(*id); offs[ix] = offsets.off(*id); sign.push_back(ix); freeVars.push_back(*id); switch (symbolTable.lookupType(*id)) { case VarnameTree: trees[ix] = 1; break; default: trees[ix] = 0; } IdentList *uu = symbolTable.lookupUnivs(*id); if (uu) { unsigned j; univs[ix] = new int[uu->size()+1]; for (j = 0; j < uu->size(); j++) univs[ix][j] = symbolTable.lookupUnivNumber(uu->get(j)); univs[ix][j] = -1; } else univs[ix] = 0; switch (symbolTable.lookupType(*id)) { case Varname0: types[ix] = 0; break; case Varname1: types[ix] = 1; break; default: types[ix] = 2; break; } } if (options.printProgress) cout << "\nAUTOMATON CONSTRUCTION\n"; Timer timer_automaton; timer_automaton.start(); DFA *dfa = 0; Deque<DFA *> dfalist; GTA *gta = 0; Deque<GTA *> gtalist; // Initialize bdd_init(); codeTable->init_print_progress(); if (options.mode != TREE) { // Generate DFAs dfa = formulaCode.DFATranslate(); if (lastPosVar != -1) dfa = st_dfa_lastpos(dfa, lastPosVar); if (allPosVar != -1) dfa = st_dfa_allpos(dfa, allPosVar); for (Deque<VarCode>::iterator i = verifyCode.begin(); i != verifyCode.end(); i++) { DFA *d = (*i).DFATranslate(); if (lastPosVar != -1) d = st_dfa_lastpos(d, lastPosVar); if (allPosVar != -1) d = st_dfa_allpos(d, allPosVar); dfalist.push_back(d); } } else { // Generate GTAs gta = formulaCode.GTATranslate(); if (allPosVar != -1) gta = st_gta_allpos(gta, allPosVar); for (Deque<VarCode>::iterator i = verifyCode.begin(); i != verifyCode.end(); i++) { GTA *g = (*i).GTATranslate(); if (allPosVar != -1) g = st_gta_allpos(g, allPosVar); gtalist.push_back(g); } } formulaCode.remove(); for (Deque<VarCode>::iterator i = verifyCode.begin(); i != verifyCode.end(); i++) (*i).remove(); timer_automaton.stop(); if (options.printProgress) { if (options.statistics) cout << "Total automaton construction time: "; else cout << "Time: "; timer_automaton.print(); } delete ast; delete codeTable; ///////// PRINT AUTOMATON //////////////////////////////////////////////// DFA *dfa2 = dfa; GTA *gta2 = gta; Deque<DFA *> *dfalist2 = &dfalist; Deque<GTA *> *gtalist2 = >alist; if (options.whole && !options.externalWhole) cout << "\n"; if (options.unrestrict) { // Unrestrict automata if (options.mode != TREE) { DFA *t = dfaCopy(dfa2); dfaUnrestrict(t); dfa2 = dfaMinimize(t); dfaFree(t); dfalist2 = new Deque<DFA *>; for (Deque<DFA *>::iterator i = dfalist.begin(); i != dfalist.end(); i++) { t = dfaCopy(*i); dfaUnrestrict(t); dfalist2->push_back(dfaMinimize(t)); dfaFree(t); } } else { GTA *t = gtaCopy(gta2); gtaUnrestrict(t); gta2 = gtaMinimize(t); gtaFree(t); gtalist2 = new Deque<GTA *>; for (Deque<GTA *>::iterator i = gtalist.begin(); i != gtalist.end(); i++) { t = gtaCopy(*i); gtaUnrestrict(t); gtalist2->push_back(gtaMinimize(t)); gtaFree(t); } } } if (options.whole) // Print whole automaton if (options.mode != TREE) { if (options.externalWhole) { if (!dfalist.empty()) cout << "Main formula:\n"; DFA *t = dfaCopy(dfa2); st_dfa_replace_indices(t, &sign, &freeVars, false, true); dfaExport(t, 0, numVars, vnames, types); dfaFree(t); Deque<DFA *>::iterator i; Deque<char *>::iterator j; for (i = dfalist2->begin(), j = verifytitlelist->begin(); i != dfalist2->end(); i++, j++) { cout << "\nFormula " << *j << ":\n"; t = dfaCopy(*i); st_dfa_replace_indices(t, &sign, &freeVars, false, true); dfaExport(t, 0, numVars, vnames, types); dfaFree(t); } } else if (options.graphvizDFA) { dfaPrintGraphviz(dfa2, numVars, offs); for (Deque<DFA *>::iterator i = dfalist2->begin(); i != dfalist2->end(); i++) dfaPrintGraphviz(*i, numVars, offs); } else { if (!dfalist.empty()) cout << "Main formula:\n"; dfaPrint(dfa2, numVars, vnames, offs); Deque<DFA *>::iterator i; Deque<char *>::iterator j; for (i = dfalist2->begin(), j = verifytitlelist->begin(); i != dfalist2->end(); i++, j++) { cout << "\nFormula " << *j << ":\n"; dfaPrint(*i, numVars, vnames, offs); } } } else { if (options.externalWhole) { if (!gtalist.empty()) cout << "Main formula:\n"; GTA *t = gtaCopy(gta2); st_gta_replace_indices(t, &sign, &freeVars, false, true); gtaExport(t, 0, numVars, vnames, types, statespaces, options.inheritedAcceptance); gtaFree(t); Deque<GTA *>::iterator i; Deque<char *>::iterator j; for (i = gtalist2->begin(), j = verifytitlelist->begin(); i != gtalist2->end(); i++, j++) { cout << "\nFormula " << *j << ":\n"; t = gtaCopy(*i); st_gta_replace_indices(t, &sign, &freeVars, false, true); gtaExport(t, 0, numVars, vnames, types, statespaces, options.inheritedAcceptance); gtaFree(t); } } else { if (!gtalist.empty()) cout << "Main formula:\n"; gtaPrint(gta2, offs, numVars, vnames, options.inheritedAcceptance); Deque<GTA *>::iterator i; Deque<char *>::iterator j; for (i = gtalist2->begin(), j = verifytitlelist->begin(); i != gtalist2->end(); i++, j++) { cout << "\nFormula " << *j << ":\n"; gtaPrint(*i, offs, numVars, vnames, options.inheritedAcceptance); } } } else if (options.analysis && !options.graphvizSatisfyingEx && !options.graphvizCounterEx && options.printProgress) { // Print summary only if (options.mode != TREE) { if (!dfalist.empty()) cout << "Main formula:"; dfaPrintVitals(dfa2); Deque<DFA *>::iterator i; Deque<char *>::iterator j; for (i = dfalist2->begin(), j = verifytitlelist->begin(); i != dfalist2->end(); i++, j++) { cout << "\nFormula " << *j << ":"; dfaPrintVitals(*i); } } else { if (!gtalist.empty()) cout << "Main formula:"; gtaPrintTotalSize(gta2); Deque<GTA *>::iterator i; Deque<char *>::iterator j; for (i = gtalist2->begin(), j = verifytitlelist->begin(); i != gtalist2->end(); i++, j++) { cout << "\nFormula " << *j << ":"; gtaPrintTotalSize(*i); } } } if (dfa2 != dfa) { dfaFree(dfa2); for (Deque<DFA *>::iterator i = dfalist2->begin(); i != dfalist2->end(); i++) dfaFree(*i); delete dfalist2; } if (gta2 != gta) { gtaFree(gta2); for (Deque<GTA *>::iterator i = gtalist2->begin(); i != gtalist2->end(); i++) gtaFree(*i); delete gtalist2; } ///////// AUTOMATON ANALYSIS ///////////////////////////////////////////// if (options.analysis) { if (options.printProgress) cout << "\nANALYSIS\n"; if (options.mode != TREE) { if (!dfalist.empty()) cout << "Main formula:\n"; dfaAnalyze(dfa, numVars, vnames, offs, types, options.treemodeOutput); Deque<DFA *>::iterator i; Deque<char *>::iterator j; for (i = dfalist.begin(), j = verifytitlelist->begin(); i != dfalist.end(); i++, j++) { cout << "\nFormula " << *j << ":\n"; dfaAnalyze(*i, numVars, vnames, offs, types, options.treemodeOutput); } } else { if (numTypes == 0 || options.treemodeOutput) { if (!gtalist.empty()) cout << "Main formula:\n"; gtaAnalyze(gta, numVars, vnames, offs, options.graphvizSatisfyingEx, options.graphvizCounterEx); Deque<GTA *>::iterator i; Deque<char *>::iterator j; for (i = gtalist.begin(), j = verifytitlelist->begin(); i != gtalist.end(); i++, j++) { cout << "\nFormula " << *j << ":\n"; gtaAnalyze(*i, numVars, vnames, offs, options.graphvizSatisfyingEx, options.graphvizCounterEx); } } else { if (options.graphvizSatisfyingEx || options.graphvizCounterEx) cout << "Graphviz output of typed trees not implemented.\n"; if (!gtalist.empty()) cout << "Main formula:\n"; gtaTypeAnalyze(gta, numVars, vnames, types, offs, univs, trees); Deque<GTA *>::iterator i; Deque<char *>::iterator j; for (i = gtalist.begin(), j = verifytitlelist->begin(); i != gtalist.end(); i++, j++) { cout << "\nFormula " << *j << ":\n"; gtaTypeAnalyze(*i, numVars, vnames, types, offs, univs, trees); } } } } ///////// CLEAN UP /////////////////////////////////////////////////////// if (options.mode != TREE) { dfaFree(dfa); for (Deque<DFA *>::iterator i = dfalist.begin(); i != dfalist.end(); i++) dfaFree(*i); } else { gtaFree(gta); for (Deque<GTA *>::iterator i = gtalist.begin(); i != gtalist.end(); i++) gtaFree(*i); freeGuide(); } delete verifytitlelist; Deque<FileSource *>::iterator i; for (i = source.begin(); i != source.end(); i++) delete *i; for (ix = 0; ix < numVars; ix++) { delete[] univs[ix]; mem_free(statespaces[ix]); } delete[] statespaces; delete[] vnames; delete[] offs; delete[] types; delete[] univs; delete[] trees; freeTreetypes(); if (options.statistics) print_statistics(); if (options.time) { timer_total.stop(); cout << "\nTotal time: "; timer_total.print(); print_timing(); } else if (options.printProgress) { timer_total.stop(); cout << "\nTotal time: "; timer_total.print(); } #ifdef MAXALLOCATED cout << "Maximum space allocated: " << (maxallocated+524288)/1048576 << " MB\n"; #endif }
void exception_loop (int line /* line number in caller*/, MemberFunction mfun /* deque member function */, const char *fcall /* function call string */, int exceptions /* enabled exceptions */, Deque &deq /* container to call function on */, const Deque::iterator &it /* iterator into container */, int n /* number of elements or offset */, const UserClass *x /* pointer to an element or 0 */, const Iterator &first /* beginning of range */, const Iterator &last /* end of range to insert */, int *n_copy /* number of copy ctors */, int *n_asgn /* number of assignments */) { std::size_t throw_after = 0; // get the initial size of the container and its begin() iterator // to detect illegal changes after an exception (i.e., violations // if the strong exception guarantee) const std::size_t size = deq.size (); const Deque::const_iterator begin = deq.begin (); const Deque::const_iterator end = deq.end (); #ifdef DEFINE_REPLACEMENT_NEW_AND_DELETE rwt_free_store* const pst = rwt_get_free_store (0); #endif // DEFINE_REPLACEMENT_NEW_AND_DELETE // repeatedly call the specified member function until it returns // without throwing an exception for ( ; ; ) { // detect objects constructed but not destroyed after an exception std::size_t x_count = UserClass::count_; _RWSTD_ASSERT (n_copy); _RWSTD_ASSERT (n_asgn); *n_copy = UserClass::n_total_copy_ctor_; *n_asgn = UserClass::n_total_op_assign_; #ifndef _RWSTD_NO_EXCEPTIONS // iterate for `n=throw_after' starting at the next call to operator // new, forcing each call to throw an exception, until the insertion // finally succeeds (i.e, no exception is thrown) # ifdef DEFINE_REPLACEMENT_NEW_AND_DELETE if (exceptions & NewThrows) { *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_after + 1; } # endif // DEFINE_REPLACEMENT_NEW_AND_DELETE if (exceptions & CopyCtorThrows) { UserClass::copy_ctor_throw_count_ = UserClass::n_total_copy_ctor_ + throw_after; } if (exceptions & AssignmentThrows) { UserClass::op_assign_throw_count_ = UserClass::n_total_op_assign_ + throw_after; } #endif // _RWSTD_NO_EXCEPTIONS _TRY { switch (mfun) { case Assign_n: _RWSTD_ASSERT (x); deq.assign (n, *x); break; case AssignRange: deq.assign (first, last); break; case Erase_1: deq.erase (it); break; case EraseRange: { const Deque::iterator erase_end (it + n); deq.erase (it, erase_end); break; } case Insert_1: _RWSTD_ASSERT (x); deq.insert (it, *x); break; case Insert_n: _RWSTD_ASSERT (x); deq.insert (it, n, *x); break; case InsertRange: deq.insert (it, first, last); break; } } _CATCH (...) { // verify that an exception thrown from the member function // didn't cause a change in the state of the container rw_assert (deq.size () == size, 0, line, "line %d: %s: size unexpectedly changed " "from %zu to %zu after an exception", __LINE__, fcall, size, deq.size ()); rw_assert (deq.begin () == begin, 0, line, "line %d: %s: begin() unexpectedly " "changed after an exception by %td", __LINE__, fcall, deq.begin () - begin); rw_assert (deq.end () == end, 0, line, "line %d: %s: end() unexpectedly " "changed after an exception by %td", __LINE__, fcall, deq.end () - end); // count the number of objects to detect leaks x_count = UserClass::count_ - x_count; rw_assert (x_count == deq.size () - size, 0, line, "line %d: %s: leaked %zu objects after an exception", __LINE__, fcall, x_count - (deq.size () - size)); if (exceptions) { // increment to allow this call to operator new to succeed // and force the next one to fail, and try to insert again ++throw_after; } else break; continue; } // count the number of objects to detect leaks x_count = UserClass::count_ - x_count; rw_assert (x_count == deq.size () - size, 0, line, "line %d: %s: leaked %zu objects " "after a successful insertion", __LINE__, fcall, x_count - (deq.size () - size)); break; }
void Fullscreen::requestFullscreen(Element& element, RequestType requestType) { // Ignore this request if the document is not in a live frame. if (!document()->isActive()) return; // If |element| is on top of |doc|'s fullscreen element stack, terminate these substeps. if (&element == fullscreenElement()) return; do { // 1. If any of the following conditions are true, terminate these steps and queue a task to fire // an event named fullscreenerror with its bubbles attribute set to true on the context object's // node document: // The fullscreen element ready check returns false. if (!fullscreenElementReady(element, requestType)) break; // This algorithm is not allowed to show a pop-up: // An algorithm is allowed to show a pop-up if, in the task in which the algorithm is running, either: // - an activation behavior is currently being processed whose click event was trusted, or // - the event listener for a trusted click event is being handled. if (!UserGestureIndicator::processingUserGesture() && !document()->frame()->isNodeJS()) { String message = ExceptionMessages::failedToExecute("requestFullScreen", "Element", "API can only be initiated by a user gesture."); document()->executionContext()->addConsoleMessage( ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); break; } // Fullscreen is not supported. if (!fullscreenIsSupported(element.document())) break; // 2. Let doc be element's node document. (i.e. "this") Document* currentDoc = document(); // 3. Let docs be all doc's ancestor browsing context's documents (if any) and doc. Deque<Document*> docs; do { docs.prepend(currentDoc); currentDoc = currentDoc->ownerElement() ? ¤tDoc->ownerElement()->document() : 0; } while (currentDoc); // 4. For each document in docs, run these substeps: Deque<Document*>::iterator current = docs.begin(), following = docs.begin(); do { ++following; // 1. Let following document be the document after document in docs, or null if there is no // such document. Document* currentDoc = *current; Document* followingDoc = following != docs.end() ? *following : 0; // 2. If following document is null, push context object on document's fullscreen element // stack, and queue a task to fire an event named fullscreenchange with its bubbles attribute // set to true on the document. if (!followingDoc) { from(*currentDoc).pushFullscreenElementStack(element, requestType); enqueueChangeEvent(*currentDoc, requestType); continue; } // 3. Otherwise, if document's fullscreen element stack is either empty or its top element // is not following document's browsing context container, Element* topElement = fullscreenElementFrom(*currentDoc); if (!topElement || topElement != followingDoc->ownerElement()) { // ...push following document's browsing context container on document's fullscreen element // stack, and queue a task to fire an event named fullscreenchange with its bubbles attribute // set to true on document. from(*currentDoc).pushFullscreenElementStack(*followingDoc->ownerElement(), requestType); enqueueChangeEvent(*currentDoc, requestType); continue; } // 4. Otherwise, do nothing for this document. It stays the same. } while (++current != docs.end()); // 5. Return, and run the remaining steps asynchronously. // 6. Optionally, perform some animation. document()->frameHost()->chrome().client().enterFullScreenForElement(&element); // 7. Optionally, display a message indicating how the user can exit displaying the context object fullscreen. return; } while (0); enqueueErrorEvent(element, requestType); }
void test_swap (const T *lhs_seq, std::size_t lhs_seq_len, const T *rhs_seq, std::size_t rhs_seq_len, std::deque<T, Allocator>*, const char *tname) { typedef std::deque<T, Allocator> Deque; typedef typename Deque::iterator Iterator; typedef typename Deque::size_type SizeType; // create two containers from the provided sequences Deque lhs (lhs_seq, lhs_seq + lhs_seq_len); Deque rhs (rhs_seq, rhs_seq + rhs_seq_len); // save the begin and and iterators and the size // of each container before swapping the objects const Iterator lhs_begin_0 = lhs.begin (); const Iterator lhs_end_0 = lhs.end (); const SizeType lhs_size_0 = lhs.size (); const Iterator rhs_begin_0 = rhs.begin (); const Iterator rhs_end_0 = rhs.end (); const SizeType rhs_size_0 = rhs.size (); // swap the two containers lhs.swap (rhs); // compute the begin and and iterators and the size // of each container after swapping the objects const Iterator lhs_begin_1 = lhs.begin (); const Iterator lhs_end_1 = lhs.end (); const SizeType lhs_size_1 = lhs.size (); const Iterator rhs_begin_1 = rhs.begin (); const Iterator rhs_end_1 = rhs.end (); const SizeType rhs_size_1 = rhs.size (); static const int cwidth = sizeof (T); // verify that the iterators and sizes // of the two objects were swapped rw_assert (lhs_begin_0 == rhs_begin_1 && lhs_begin_1 == rhs_begin_0, 0, __LINE__, "begin() not swapped for \"%{X=*.*}\" and \"%{X=*.*}\"", cwidth, int (lhs_seq_len), -1, lhs_seq, cwidth, int (rhs_seq_len), -1, rhs_seq); rw_assert (lhs_end_0 == rhs_end_1 && lhs_end_1 == rhs_end_0, 0, __LINE__, "end() not swapped for \"%{X=*.*}\" and \"%{X=*.*}\"", cwidth, int (lhs_seq_len), -1, lhs_seq, cwidth, int (rhs_seq_len), -1, rhs_seq); rw_assert (lhs_size_0 == rhs_size_1 && lhs_size_1 == rhs_size_0, 0, __LINE__, "size() not swapped for \"%{X=*.*}\" and \"%{X=*.*}\"", cwidth, int (lhs_seq_len), -1, lhs_seq, cwidth, int (rhs_seq_len), -1, rhs_seq); // swap one of the containers with an empty unnamed temporary // container and verify that the object is empty { Deque ().swap (lhs); } const Iterator lhs_begin_2 = lhs.begin (); const Iterator lhs_end_2 = lhs.end (); const SizeType lhs_size_2 = lhs.size (); rw_assert (lhs_begin_2 == lhs_end_2, 0, __LINE__, "deque<%s>().begin() not swapped for \"%{X=*.*}\"", tname, cwidth, int (rhs_seq_len), -1, rhs_seq); rw_assert (0 == lhs_size_2, 0, __LINE__, "deque<%s>().size() not swapped for \"%{X=*.*}\"", tname, cwidth, int (rhs_seq_len), -1, rhs_seq); }
void testIteratorOperations() { Deque<int> deque; MersenneTwisterRandom rng; int n_ops = rng.randInt(100); for (int i = 0; i < n_ops; ++i) { if (rng.randInt(10) < 3 && !deque.empty()) { deque.pop_front(); } else { deque.push_back(rng.randInt()); } } // Test iterator unary operators { for (Deque<int>::iterator it = deque.begin(); it != deque.end(); ) { Deque<int>::iterator it1 = it; Deque<int>::iterator it2 = it; SINVARIANT(it1 == it2); Deque<int>::iterator it3 = it1++; INVARIANT(it3 == it && it3 != it1 && it1 != it2, "return unchanged && return different from iterator && iterator changed"); Deque<int>::iterator it4 = ++it2; INVARIANT(it4 != it && it4 == it1 && it2 == it1, "return changed && return == updated && two updates same"); it = it4; } } // Test distance operators Deque<int>::iterator it_forward = deque.begin(); Deque<int>::iterator it_backward = deque.end(); ptrdiff_t dist_from_start = 0; // start can be .begin() or .end() ptrdiff_t dist_from_finish = deque.end() - deque.begin(); // finish can be .end() or .begin() for (; it_forward != deque.end(); ++dist_from_start, --dist_from_finish) { SINVARIANT(it_backward - it_forward == dist_from_finish - dist_from_start); SINVARIANT(it_forward + dist_from_finish == deque.end()); SINVARIANT(it_backward - dist_from_finish == deque.begin()); SINVARIANT((it_forward < it_backward) == (dist_from_start < dist_from_finish)); SINVARIANT((it_forward <= it_backward) == (dist_from_start <= dist_from_finish)); SINVARIANT((it_forward > it_backward) == (dist_from_start > dist_from_finish)); SINVARIANT((it_forward >= it_backward) == (dist_from_start >= dist_from_finish)); Deque<int>::iterator temp_a(it_forward); Deque<int>::iterator temp_b; temp_b = it_backward; SINVARIANT(temp_b - temp_a == dist_from_finish - dist_from_start); temp_a += dist_from_finish; SINVARIANT(temp_a == deque.end()); temp_b -= dist_from_finish; SINVARIANT(temp_b == deque.begin()); if (rng.randBool()) { // Exercise both variants of the increment/decrement operators ++it_forward; --it_backward; } else { it_forward++; it_backward--; } } SINVARIANT(it_backward == deque.begin()); SINVARIANT(static_cast<size_t>(dist_from_start) == deque.size()); SINVARIANT(dist_from_finish == 0); }