Changeset 0751d4d2


Ignore:
Timestamp:
Apr 17, 2017, 5:41:48 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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, resolv-new, with_gc
Children:
e2ef6bf
Parents:
bb91487
Message:

add space around *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/generic_types.tex

    rbb91487 r0751d4d2  
    11761176std::forward_list wrapped in std::stack interface
    11771177
    1178 template<typename T> void print(ostream& out, const T& x) { out << x; }
    1179 template<> void print<bool>(ostream& out, const bool& x) { out << (x ? "true" : "false"); }
    1180 template<> void print<char>(ostream& out, const char& x ) { out << "'" << x << "'"; }
    1181 template<typename R, typename S> ostream& operator<< (ostream& out, const pair<R, S>& x) {
     1178template<typename T> void print(ostream & out, const T & x) { out << x; }
     1179template<> void print<bool>(ostream & out, const bool & x) { out << (x ? "true" : "false"); }
     1180template<> void print<char>(ostream & out, const char & x ) { out << "'" << x << "'"; }
     1181template<typename R, typename S> ostream & operator<< (ostream & out, const pair<R, S>& x) {
    11821182        out << "["; print(out, x.first); out << ", "; print(out, x.second); return out << "]"; }
    1183 template<typename T, typename... Args> void print(ostream& out, const T& arg, const Args&... rest) {
     1183template<typename T, typename... Args> void print(ostream & out, const T & arg, const Args &... rest) {
    11841184        out << arg;     print(out, rest...); }
    11851185\end{lstlisting}
     
    12201220forall(otype T) struct stack_node {
    12211221        T value;
    1222         stack_node(T)* next;
     1222        stack_node(T) * next;
    12231223};
    1224 forall(otype T) void ?{}(stack(T)* s) { (&s->head){ 0 }; }
    1225 forall(otype T) void ?{}(stack(T)* s, stack(T) t) {
    1226         stack_node(T)** crnt = &s->head;
    1227         for ( stack_node(T)* next = t.head; next; next = next->next ) {
    1228                 *crnt = ((stack_node(T)*)malloc()){ next->value }; /***/
    1229                 stack_node(T)* acrnt = *crnt;
     1224forall(otype T) void ?{}(stack(T) * s) { (&s->head){ 0 }; }
     1225forall(otype T) void ?{}(stack(T) * s, stack(T) t) {
     1226        stack_node(T) ** crnt = &s->head;
     1227        for ( stack_node(T) * next = t.head; next; next = next->next ) {
     1228                *crnt = ((stack_node(T) *)malloc()){ next->value }; /***/
     1229                stack_node(T) * acrnt = *crnt;
    12301230                crnt = &acrnt->next;
    12311231        }
    12321232        *crnt = 0;
    12331233}
    1234 forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t) {
     1234forall(otype T) stack(T) ?=?(stack(T) * s, stack(T) t) {
    12351235        if ( s->head == t.head ) return *s;
    12361236        clear(s);
     
    12381238        return *s;
    12391239}
    1240 forall(otype T) void ^?{}(stack(T)* s) { clear(s); }
    1241 forall(otype T) _Bool empty(const stack(T)* s) { return s->head == 0; }
    1242 forall(otype T) void push(stack(T)* s, T value) {
    1243         s->head = ((stack_node(T)*)malloc()){ value, s->head }; /***/
    1244 }
    1245 forall(otype T) T pop(stack(T)* s) {
    1246         stack_node(T)* n = s->head;
     1240forall(otype T) void ^?{}(stack(T) * s) { clear(s); }
     1241forall(otype T) _Bool empty(const stack(T) * s) { return s->head == 0; }
     1242forall(otype T) void push(stack(T) * s, T value) {
     1243        s->head = ((stack_node(T) *)malloc()){ value, s->head }; /***/
     1244}
     1245forall(otype T) T pop(stack(T) * s) {
     1246        stack_node(T) * n = s->head;
    12471247        s->head = n->next;
    12481248        T x = n->value;
     
    12511251        return x;
    12521252}
    1253 forall(otype T) void clear(stack(T)* s) {
    1254         for ( stack_node(T)* next = s->head; next; ) {
    1255                 stack_node(T)* crnt = next;
     1253forall(otype T) void clear(stack(T) * s) {
     1254        for ( stack_node(T) * next = s->head; next; ) {
     1255                stack_node(T) * crnt = next;
    12561256                next = crnt->next;
    12571257                delete(crnt);
     
    12671267        struct node {
    12681268                T value;
    1269                 node* next;
    1270                 node( const T& v, node* n = nullptr ) : value(v), next(n) {}
     1269                node * next;
     1270                node( const T & v, node * n = nullptr ) : value(v), next(n) {}
    12711271        };
    1272         node* head;
     1272        node * head;
    12731273        void copy(const stack<T>& o) {
    1274                 node** crnt = &head;
    1275                 for ( node* next = o.head;; next; next = next->next ) {
     1274                node ** crnt = &head;
     1275                for ( node * next = o.head;; next; next = next->next ) {
    12761276                        *crnt = new node{ next->value }; /***/
    12771277                        crnt = &(*crnt)->next;
     
    12821282        stack() : head(nullptr) {}
    12831283        stack(const stack<T>& o) { copy(o); }
    1284         stack(stack<T>&& o) : head(o.head) { o.head = nullptr; }
     1284        stack(stack<T> && o) : head(o.head) { o.head = nullptr; }
    12851285        ~stack() { clear(); }
    1286         stack& operator= (const stack<T>& o) {
     1286        stack & operator= (const stack<T>& o) {
    12871287                if ( this == &o ) return *this;
    12881288                clear();
     
    12901290                return *this;
    12911291        }
    1292         stack& operator= (stack<T>&& o) {
     1292        stack & operator= (stack<T> && o) {
    12931293                if ( this == &o ) return *this;
    12941294                head = o.head;
     
    12971297        }
    12981298        bool empty() const { return head == nullptr; }
    1299         void push(const T& value) { head = new node{ value, head };  /***/ }
     1299        void push(const T & value) { head = new node{ value, head };  /***/ }
    13001300        T pop() {
    1301                 node* n = head;
     1301                node * n = head;
    13021302                head = n->next;
    13031303                T x = std::move(n->value);
     
    13061306        }
    13071307        void clear() {
    1308                 for ( node* next = head; next; ) {
    1309                         node* crnt = next;
     1308                for ( node * next = head; next; ) {
     1309                        node * crnt = next;
    13101310                        next = crnt->next;
    13111311                        delete crnt;
     
    13201320\begin{lstlisting}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
    13211321struct stack_node {
    1322         void* value;
    1323         struct stack_node* next;
     1322        void * value;
     1323        struct stack_node * next;
    13241324};
    13251325struct stack new_stack() { return (struct stack){ NULL }; /***/ }
    1326 void copy_stack(struct stack* s, const struct stack* t, void* (*copy)(const void*)) {
    1327         struct stack_node** crnt = &s->head;
    1328         for ( struct stack_node* next = t->head; next; next = next->next ) {
     1326void copy_stack(struct stack * s, const struct stack * t, void * (*copy)(const void *)) {
     1327        struct stack_node ** crnt = &s->head;
     1328        for ( struct stack_node * next = t->head; next; next = next->next ) {
    13291329                *crnt = malloc(sizeof(struct stack_node)); /***/
    13301330                **crnt = (struct stack_node){ copy(next->value) }; /***/
     
    13331333        *crnt = 0;
    13341334}
    1335 _Bool stack_empty(const struct stack* s) { return s->head == NULL; }
    1336 void push_stack(struct stack* s, void* value) {
    1337         struct stack_node* n = malloc(sizeof(struct stack_node)); /***/
     1335_Bool stack_empty(const struct stack * s) { return s->head == NULL; }
     1336void push_stack(struct stack * s, void * value) {
     1337        struct stack_node * n = malloc(sizeof(struct stack_node)); /***/
    13381338        *n = (struct stack_node){ value, s->head }; /***/
    13391339        s->head = n;
    13401340}
    1341 void* pop_stack(struct stack* s) {
    1342         struct stack_node* n = s->head;
     1341void * pop_stack(struct stack * s) {
     1342        struct stack_node * n = s->head;
    13431343        s->head = n->next;
    1344         void* x = n->value;
     1344        void * x = n->value;
    13451345        free(n);
    13461346        return x;
    13471347}
    1348 void clear_stack(struct stack* s, void (*free_el)(void*)) {
    1349         for ( struct stack_node* next = s->head; next; ) {
    1350                 struct stack_node* crnt = next;
     1348void clear_stack(struct stack * s, void (*free_el)(void *)) {
     1349        for ( struct stack_node * next = s->head; next; ) {
     1350                struct stack_node * crnt = next;
    13511351                next = crnt->next;
    13521352                free_el(crnt->value);
     
    13601360\CCV
    13611361\begin{lstlisting}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
    1362 stack::node::node( const object& v, node* n ) : value( v.new_copy() ), next( n ) {}
    1363 void stack::copy(const stack& o) {
    1364         node** crnt = &head;
    1365         for ( node* next = o.head; next; next = next->next ) {
     1362stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {}
     1363void stack::copy(const stack & o) {
     1364        node ** crnt = &head;
     1365        for ( node * next = o.head; next; next = next->next ) {
    13661366                *crnt = new node{ *next->value };
    13671367                crnt = &(*crnt)->next;
     
    13701370}
    13711371stack::stack() : head(nullptr) {}
    1372 stack::stack(const stack& o) { copy(o); }
    1373 stack::stack(stack&& o) : head(o.head) { o.head = nullptr; }
     1372stack::stack(const stack & o) { copy(o); }
     1373stack::stack(stack && o) : head(o.head) { o.head = nullptr; }
    13741374stack::~stack() { clear(); }
    1375 stack& stack::operator= (const stack& o) {
     1375stack & stack::operator= (const stack & o) {
    13761376        if ( this == &o ) return *this;
    13771377        clear();
     
    13791379        return *this;
    13801380}
    1381 stack& stack::operator= (stack&& o) {
     1381stack & stack::operator= (stack && o) {
    13821382        if ( this == &o ) return *this;
    13831383        head = o.head;
     
    13861386}
    13871387bool stack::empty() const { return head == nullptr; }
    1388 void stack::push(const object& value) { head = new node{ value, head }; /***/ }
     1388void stack::push(const object & value) { head = new node{ value, head }; /***/ }
    13891389ptr<object> stack::pop() {
    1390         node* n = head;
     1390        node * n = head;
    13911391        head = n->next;
    13921392        ptr<object> x = std::move(n->value);
     
    13951395}
    13961396void stack::clear() {
    1397         for ( node* next = head; next; ) {
    1398                 node* crnt = next;
     1397        for ( node * next = head; next; ) {
     1398                node * crnt = next;
    13991399                next = crnt->next;
    14001400                delete crnt;
Note: See TracChangeset for help on using the changeset viewer.