source: doc/papers/general/evaluation/cpp-vstack.cpp@ 1a3eab8

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum with_gc
Last change on this file since 1a3eab8 was ac4dad2, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

shorten experimental code

  • Property mode set to 100644
File size: 945 bytes
Line 
1#include "cpp-vstack.hpp"
2#include <utility>
3
4stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {}
5
6void stack::clear() {
7 for ( node * nx = head; nx; ) {
8 node * cr = nx;
9 nx = cr->next;
10 delete cr;
11 }
12 head = nullptr;
13}
14
15void stack::copy( const stack & o ) {
16 node ** cr = &head;
17 for ( node * nx = o.head; nx; nx = nx->next ) {
18 *cr = new node{ *nx->value }; /***/
19 cr = &(*cr)->next;
20 }
21 *cr = 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}
34
35bool stack::empty() const { return head == nullptr; }
36
37void stack::push( const object & value ) { head = new node{ value, head }; /***/ }
38
39ptr<object> stack::pop() {
40 node * n = head;
41 head = n->next;
42 ptr<object> v = std::move( n->value );
43 delete n;
44 return v;
45}
Note: See TracBrowser for help on using the repository browser.