Ignore:
Timestamp:
Apr 17, 2018, 12:01:09 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
3265399
Parents:
b2fe1c9 (diff), 81bb114 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/evaluation/cpp-vstack.cpp

    rb2fe1c9 r32cab5b  
    22#include <utility>
    33
    4 stack::node::node( const object& v, node* n ) : value( v.new_copy() ), next( n ) {}
    5 
    6 void stack::copy(const stack& o) {
    7         node** crnt = &head;
    8         for ( node* next = o.head; next; next = next->next ) {
    9                 *crnt = new node{ *next->value };
    10                 crnt = &(*crnt)->next;
    11         }
    12         *crnt = nullptr;
    13 }
    14 
    15 stack::stack() : head(nullptr) {}
    16 stack::stack(const stack& o) { copy(o); }
    17 stack::stack(stack&& o) : head(o.head) { o.head = nullptr; }
    18 stack::~stack() { clear(); }
    19 
    20 stack& stack::operator= (const stack& o) {
    21         if ( this == &o ) return *this;
    22         clear();
    23         copy(o);
    24         return *this;
    25 }
    26 
    27 stack& stack::operator= (stack&& o) {
    28         if ( this == &o ) return *this;
    29         head = o.head;
    30         o.head = nullptr;
    31         return *this;
    32 }
     4stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {}
    335
    346void stack::clear() {
    35     for ( node* next = head; next; ) {
    36                 node* crnt = next;
     7        for ( node * next = head; next; ) {
     8                node * crnt = next;
    379                next = crnt->next;
    3810                delete crnt;
     
    4113}
    4214
     15void stack::copy( const stack & o ) {
     16        node ** crnt = &head;
     17        for ( node * next = o.head; next; next = next->next ) {
     18                *crnt = new node{ *next->value }; /***/
     19                crnt = &(*crnt)->next;
     20        }
     21        *crnt = nullptr;
     22}
     23
     24stack::stack() : head( nullptr ) {}
     25stack::stack( const stack & o ) { copy( o ); }
     26stack::~stack() { clear(); }
     27
     28stack & stack::operator=( const stack & o ) {
     29        if ( this == &o ) return *this;
     30        clear();
     31        copy( o );
     32        return *this;
     33}
    4334
    4435bool stack::empty() const { return head == nullptr; }
    4536
    46 void stack::push(const object& value) { head = new node{ value, head }; /***/ }
     37void stack::push( const object & value ) { head = new node{ value, head }; /***/ }
    4738
    4839ptr<object> stack::pop() {
    49         node* n = head;
     40        node * n = head;
    5041        head = n->next;
    51         ptr<object> x = std::move(n->value);
     42        ptr<object> v = std::move( n->value );
    5243        delete n;
    53         return x;
     44        return v;
    5445}
Note: See TracChangeset for help on using the changeset viewer.