Changeset 2bb4a01


Ignore:
Timestamp:
May 9, 2019, 3:21:39 PM (2 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
8d90b6b, a300e4a
Parents:
f47f887
Message:

Start on new AST

Location:
src/AST
Files:
15 added
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.hpp

    rf47f887 r2bb4a01  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Node.hpp --
     8//
     9// Author           : Thierry Delisle
     10// Created On       : Wed May 8 10:27:04 2019
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Wed May 8 11:00:00 2019
     13// Update Count     : 2
     14//
     15
    116#pragma once
    217
    3 #include <memory>
     18#include <cassert>
     19#include <iosfwd>
    420
    521namespace ast {
     22
     23class Visitor;
     24
     25/// Base class for all AST nodes.
     26/// Keeps both strong and weak reference counts.
    627class Node {
    728public:
     29        // override defaults to ensure assignment doesn't
     30        // change/share reference counts
     31        Node() = default;
     32        Node(const Node&) : strong_ref(0), weak_ref(0) {}
     33        Node(Node&&) : strong_ref(0), weak_ref(0) {}
     34        Node& operator= (const Node&) = delete;
     35        Node& operator= (Node&&) = delete;
    836        virtual ~Node() = default;
    937
     38        virtual Node* accept( Visitor& v ) = 0;
     39
     40        /// Types of node references
    1041        enum class ref_type {
    1142                strong,
     
    3566
    3667private:
     68        /// Make a copy of this node; should be overridden in subclass with more precise return type
     69        virtual Node* clone() const = 0;
     70
    3771        mutable size_t strong_ref = 0;
    3872        mutable size_t weak_ref = 0;
     
    5892}
    5993
     94std::ostream& operator<< ( std::ostream& out, const Node* node );
     95
    6096// Base class for the smart pointer types
    6197// should never really be used.
     
    76112        ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o.node) {
    77113                if( node ) node->increment(ref_t);
    78                 if( node ) node->decrement(o_ref_t);
    79114        }
    80115
     
    89124                if(o.node == node) return *this;
    90125                assign(o.node);
    91                 if( node ) node->decrement(o_ref_t);
    92126                return *this;
    93127        }
     
    112146};
    113147
     148/// Owning pointer to node
    114149template< typename node_t >
    115150using ptr = ptr_base< node_t, Node::ref_type::strong >;
    116151
     152/// Observing pointer to node
    117153template< typename node_t >
    118154using readonly = ptr_base< node_t, Node::ref_type::weak >;
    119155}
     156
     157// Local Variables: //
     158// tab-width: 4 //
     159// mode: c++ //
     160// compile-command: "make install" //
     161// End: //
Note: See TracChangeset for help on using the changeset viewer.