Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: src/utils.h

Issue 2457393003: Thread decls-list through Declaration (Closed)
Patch Set: rename Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_UTILS_H_ 5 #ifndef V8_UTILS_H_
6 #define V8_UTILS_H_ 6 #define V8_UTILS_H_
7 7
8 #include <limits.h> 8 #include <limits.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 #if defined(V8_TARGET_LITTLE_ENDIAN) 1590 #if defined(V8_TARGET_LITTLE_ENDIAN)
1591 WriteUnalignedValue<V>(p, value); 1591 WriteUnalignedValue<V>(p, value);
1592 #elif defined(V8_TARGET_BIG_ENDIAN) 1592 #elif defined(V8_TARGET_BIG_ENDIAN)
1593 byte* src = reinterpret_cast<byte*>(&value); 1593 byte* src = reinterpret_cast<byte*>(&value);
1594 byte* dst = reinterpret_cast<byte*>(p); 1594 byte* dst = reinterpret_cast<byte*>(p);
1595 for (size_t i = 0; i < sizeof(V); i++) { 1595 for (size_t i = 0; i < sizeof(V); i++) {
1596 dst[i] = src[sizeof(V) - i - 1]; 1596 dst[i] = src[sizeof(V) - i - 1];
1597 } 1597 }
1598 #endif // V8_TARGET_LITTLE_ENDIAN 1598 #endif // V8_TARGET_LITTLE_ENDIAN
1599 } 1599 }
1600
1601 // Represents a linked list that threads through the nodes in the linked list.
1602 // Entries in the list are pointers to nodes. The nodes need to have a T**
1603 // next() method that returns the location where the next value is stored.
1604 template <typename T>
1605 class ThreadedList final {
1606 public:
1607 ThreadedList() : head_(nullptr), tail_(&head_) {}
1608 void Add(T* v) {
1609 *tail_ = v;
1610 tail_ = v->next();
adamk 2016/10/31 20:34:23 Should Add() be DCHECKing that *v->next() is null
1611 }
1612
1613 void Clear() {
1614 head_ = nullptr;
1615 tail_ = &head_;
1616 }
1617
1618 class Iterator final {
1619 public:
1620 Iterator& operator++() {
1621 entry_ = (*entry_)->next();
1622 return *this;
1623 }
1624 bool operator!=(const Iterator& other) { return entry_ != other.entry_; }
1625 T* operator*() { return *entry_; }
1626 Iterator& operator=(T* entry) {
1627 T* next = *(*entry_)->next();
1628 *entry->next() = next;
1629 *entry_ = entry;
1630 return *this;
1631 }
1632
1633 private:
1634 explicit Iterator(T** entry) : entry_(entry) {}
1635
1636 T** entry_;
1637
1638 friend class ThreadedList;
1639 };
1640
1641 Iterator begin() { return Iterator(&head_); }
1642 Iterator end() { return Iterator(tail_); }
1643
1644 void Rewind(Iterator reset_point) {
1645 tail_ = reset_point.entry_;
1646 *tail_ = nullptr;
1647 }
1648
1649 bool is_empty() const { return head_ == nullptr; }
1650
1651 // Slow. For testing purposes.
1652 int LengthForTest() {
1653 int result = 0;
1654 for (Iterator t = begin(); t != end(); ++t) ++result;
1655 return result;
1656 }
1657 T* AtForTest(int i) {
1658 Iterator t = begin();
1659 while (i-- > 0) ++t;
1660 return *t;
1661 }
1662
1663 private:
1664 T* head_;
1665 T** tail_;
1666 DISALLOW_COPY_AND_ASSIGN(ThreadedList);
1667 };
1668
1600 } // namespace internal 1669 } // namespace internal
1601 } // namespace v8 1670 } // namespace v8
1602 1671
1603 #endif // V8_UTILS_H_ 1672 #endif // V8_UTILS_H_
OLDNEW
« src/ast/ast.h ('K') | « src/parsing/parser.cc ('k') | test/cctest/asmjs/test-asm-typer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698