source: src/AST/Node.cpp @ 55b6476

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 55b6476 was 7d0881c, checked in by Michael Brooks <mlbrooks@…>, 5 years ago

Aaron added decrement-without delete option to Node infrastructure

  • Property mode set to 100644
File size: 17.7 KB
RevLine 
[87701b6]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       : Thu May 16 14:16:00 2019
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#include "Node.hpp"
17#include "Fwd.hpp"
[10a1225]18
[9ea38de]19#include <csignal>  // MEMORY DEBUG -- for raise
[733074e]20#include <iostream>
21
[10a1225]22#include "Attribute.hpp"
[87701b6]23#include "Decl.hpp"
24#include "Expr.hpp"
[10a1225]25#include "Init.hpp"
[87701b6]26#include "Stmt.hpp"
27#include "Type.hpp"
[10a1225]28#include "TypeSubstitution.hpp"
[87701b6]29
[461046f]30#include "Print.hpp"
31
[bcb311b]32/// MEMORY DEBUG -- allows breaking on ref-count changes of dynamically chosen object.
[9ea38de]33/// Process to use in GDB:
34///   break ast::Node::_trap()
35///   run
36///   set variable MEM_TRAP_OBJ = <target>
37///   disable <first breakpoint>
38///   continue
39void * MEM_TRAP_OBJ = nullptr;
40
[bcb311b]41void _trap( const void * node ) {
42        if ( node == MEM_TRAP_OBJ ) std::raise(SIGTRAP);
[9ea38de]43}
44
[87701b6]45template< typename node_t, enum ast::Node::ref_type ref_t >
[bcb311b]46void ast::ptr_base<node_t, ref_t>::_inc( const node_t * node ) {
47        node->increment(ref_t);
48        _trap( node );
49}
[87701b6]50
51template< typename node_t, enum ast::Node::ref_type ref_t >
[7d0881c]52void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node, bool do_delete ) {
[bcb311b]53        _trap( node );
[7d0881c]54        node->decrement(ref_t, do_delete );
[bcb311b]55}
[87701b6]56
[4864a73]57template< typename node_t, enum ast::Node::ref_type ref_t >
[e0e9a0b]58void ast::ptr_base<node_t, ref_t>::_check() const { 
59        // if(node) assert(node->was_ever_strong == false || node->strong_count > 0);
60}
[4864a73]61
[10a1225]62template< typename node_t, enum ast::Node::ref_type ref_t >
[76ed81f]63node_t * ast::ptr_base<node_t, ref_t>::get_and_mutate() {
[10a1225]64        // get mutable version of `n`
65        auto r = mutate( node );
66        // re-assign mutable version in case `mutate()` produced a new pointer
67        assign( r );
68        return r;
69}
70
[76ed81f]71template< typename node_t, enum ast::Node::ref_type ref_t >
72node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) {
73        // ensure ownership of `n` by this node to avoid spurious single-owner mutates
74        assign( n );
75        // return mutable version
76        return get_and_mutate();
77}
78
[733074e]79std::ostream & ast::operator<< ( std::ostream & out, const ast::Node * node ) {
[461046f]80        print(out, node);
[733074e]81        return out;
82}
83
[87701b6]84template class ast::ptr_base< ast::Node, ast::Node::ref_type::weak >;
85template class ast::ptr_base< ast::Node, ast::Node::ref_type::strong >;
86template class ast::ptr_base< ast::ParseNode, ast::Node::ref_type::weak >;
87template class ast::ptr_base< ast::ParseNode, ast::Node::ref_type::strong >;
88template class ast::ptr_base< ast::Decl, ast::Node::ref_type::weak >;
89template class ast::ptr_base< ast::Decl, ast::Node::ref_type::strong >;
90template class ast::ptr_base< ast::DeclWithType, ast::Node::ref_type::weak >;
91template class ast::ptr_base< ast::DeclWithType, ast::Node::ref_type::strong >;
92template class ast::ptr_base< ast::ObjectDecl, ast::Node::ref_type::weak >;
93template class ast::ptr_base< ast::ObjectDecl, ast::Node::ref_type::strong >;
94template class ast::ptr_base< ast::FunctionDecl, ast::Node::ref_type::weak >;
95template class ast::ptr_base< ast::FunctionDecl, ast::Node::ref_type::strong >;
96template class ast::ptr_base< ast::AggregateDecl, ast::Node::ref_type::weak >;
97template class ast::ptr_base< ast::AggregateDecl, ast::Node::ref_type::strong >;
98template class ast::ptr_base< ast::StructDecl, ast::Node::ref_type::weak >;
99template class ast::ptr_base< ast::StructDecl, ast::Node::ref_type::strong >;
100template class ast::ptr_base< ast::UnionDecl, ast::Node::ref_type::weak >;
101template class ast::ptr_base< ast::UnionDecl, ast::Node::ref_type::strong >;
102template class ast::ptr_base< ast::EnumDecl, ast::Node::ref_type::weak >;
103template class ast::ptr_base< ast::EnumDecl, ast::Node::ref_type::strong >;
104template class ast::ptr_base< ast::TraitDecl, ast::Node::ref_type::weak >;
105template class ast::ptr_base< ast::TraitDecl, ast::Node::ref_type::strong >;
106template class ast::ptr_base< ast::NamedTypeDecl, ast::Node::ref_type::weak >;
107template class ast::ptr_base< ast::NamedTypeDecl, ast::Node::ref_type::strong >;
108template class ast::ptr_base< ast::TypeDecl, ast::Node::ref_type::weak >;
109template class ast::ptr_base< ast::TypeDecl, ast::Node::ref_type::strong >;
110template class ast::ptr_base< ast::TypedefDecl, ast::Node::ref_type::weak >;
111template class ast::ptr_base< ast::TypedefDecl, ast::Node::ref_type::strong >;
112template class ast::ptr_base< ast::AsmDecl, ast::Node::ref_type::weak >;
113template class ast::ptr_base< ast::AsmDecl, ast::Node::ref_type::strong >;
114template class ast::ptr_base< ast::StaticAssertDecl, ast::Node::ref_type::weak >;
115template class ast::ptr_base< ast::StaticAssertDecl, ast::Node::ref_type::strong >;
116template class ast::ptr_base< ast::Stmt, ast::Node::ref_type::weak >;
117template class ast::ptr_base< ast::Stmt, ast::Node::ref_type::strong >;
118template class ast::ptr_base< ast::CompoundStmt, ast::Node::ref_type::weak >;
119template class ast::ptr_base< ast::CompoundStmt, ast::Node::ref_type::strong >;
120template class ast::ptr_base< ast::ExprStmt, ast::Node::ref_type::weak >;
121template class ast::ptr_base< ast::ExprStmt, ast::Node::ref_type::strong >;
122template class ast::ptr_base< ast::AsmStmt, ast::Node::ref_type::weak >;
123template class ast::ptr_base< ast::AsmStmt, ast::Node::ref_type::strong >;
124template class ast::ptr_base< ast::DirectiveStmt, ast::Node::ref_type::weak >;
125template class ast::ptr_base< ast::DirectiveStmt, ast::Node::ref_type::strong >;
126template class ast::ptr_base< ast::IfStmt, ast::Node::ref_type::weak >;
127template class ast::ptr_base< ast::IfStmt, ast::Node::ref_type::strong >;
128template class ast::ptr_base< ast::WhileStmt, ast::Node::ref_type::weak >;
129template class ast::ptr_base< ast::WhileStmt, ast::Node::ref_type::strong >;
130template class ast::ptr_base< ast::ForStmt, ast::Node::ref_type::weak >;
131template class ast::ptr_base< ast::ForStmt, ast::Node::ref_type::strong >;
132template class ast::ptr_base< ast::SwitchStmt, ast::Node::ref_type::weak >;
133template class ast::ptr_base< ast::SwitchStmt, ast::Node::ref_type::strong >;
134template class ast::ptr_base< ast::CaseStmt, ast::Node::ref_type::weak >;
135template class ast::ptr_base< ast::CaseStmt, ast::Node::ref_type::strong >;
136template class ast::ptr_base< ast::BranchStmt, ast::Node::ref_type::weak >;
137template class ast::ptr_base< ast::BranchStmt, ast::Node::ref_type::strong >;
138template class ast::ptr_base< ast::ReturnStmt, ast::Node::ref_type::weak >;
139template class ast::ptr_base< ast::ReturnStmt, ast::Node::ref_type::strong >;
140template class ast::ptr_base< ast::ThrowStmt, ast::Node::ref_type::weak >;
141template class ast::ptr_base< ast::ThrowStmt, ast::Node::ref_type::strong >;
142template class ast::ptr_base< ast::TryStmt, ast::Node::ref_type::weak >;
143template class ast::ptr_base< ast::TryStmt, ast::Node::ref_type::strong >;
144template class ast::ptr_base< ast::CatchStmt, ast::Node::ref_type::weak >;
145template class ast::ptr_base< ast::CatchStmt, ast::Node::ref_type::strong >;
146template class ast::ptr_base< ast::FinallyStmt, ast::Node::ref_type::weak >;
147template class ast::ptr_base< ast::FinallyStmt, ast::Node::ref_type::strong >;
148template class ast::ptr_base< ast::WaitForStmt, ast::Node::ref_type::weak >;
149template class ast::ptr_base< ast::WaitForStmt, ast::Node::ref_type::strong >;
150template class ast::ptr_base< ast::WithStmt, ast::Node::ref_type::weak >;
151template class ast::ptr_base< ast::WithStmt, ast::Node::ref_type::strong >;
152template class ast::ptr_base< ast::DeclStmt, ast::Node::ref_type::weak >;
153template class ast::ptr_base< ast::DeclStmt, ast::Node::ref_type::strong >;
154template class ast::ptr_base< ast::NullStmt, ast::Node::ref_type::weak >;
155template class ast::ptr_base< ast::NullStmt, ast::Node::ref_type::strong >;
156template class ast::ptr_base< ast::ImplicitCtorDtorStmt, ast::Node::ref_type::weak >;
157template class ast::ptr_base< ast::ImplicitCtorDtorStmt, ast::Node::ref_type::strong >;
158template class ast::ptr_base< ast::Expr, ast::Node::ref_type::weak >;
159template class ast::ptr_base< ast::Expr, ast::Node::ref_type::strong >;
160template class ast::ptr_base< ast::ApplicationExpr, ast::Node::ref_type::weak >;
161template class ast::ptr_base< ast::ApplicationExpr, ast::Node::ref_type::strong >;
162template class ast::ptr_base< ast::UntypedExpr, ast::Node::ref_type::weak >;
163template class ast::ptr_base< ast::UntypedExpr, ast::Node::ref_type::strong >;
164template class ast::ptr_base< ast::NameExpr, ast::Node::ref_type::weak >;
165template class ast::ptr_base< ast::NameExpr, ast::Node::ref_type::strong >;
166template class ast::ptr_base< ast::AddressExpr, ast::Node::ref_type::weak >;
167template class ast::ptr_base< ast::AddressExpr, ast::Node::ref_type::strong >;
168template class ast::ptr_base< ast::LabelAddressExpr, ast::Node::ref_type::weak >;
169template class ast::ptr_base< ast::LabelAddressExpr, ast::Node::ref_type::strong >;
170template class ast::ptr_base< ast::CastExpr, ast::Node::ref_type::weak >;
171template class ast::ptr_base< ast::CastExpr, ast::Node::ref_type::strong >;
172template class ast::ptr_base< ast::KeywordCastExpr, ast::Node::ref_type::weak >;
173template class ast::ptr_base< ast::KeywordCastExpr, ast::Node::ref_type::strong >;
174template class ast::ptr_base< ast::VirtualCastExpr, ast::Node::ref_type::weak >;
175template class ast::ptr_base< ast::VirtualCastExpr, ast::Node::ref_type::strong >;
176template class ast::ptr_base< ast::MemberExpr, ast::Node::ref_type::weak >;
177template class ast::ptr_base< ast::MemberExpr, ast::Node::ref_type::strong >;
178template class ast::ptr_base< ast::UntypedMemberExpr, ast::Node::ref_type::weak >;
179template class ast::ptr_base< ast::UntypedMemberExpr, ast::Node::ref_type::strong >;
180template class ast::ptr_base< ast::VariableExpr, ast::Node::ref_type::weak >;
181template class ast::ptr_base< ast::VariableExpr, ast::Node::ref_type::strong >;
182template class ast::ptr_base< ast::ConstantExpr, ast::Node::ref_type::weak >;
183template class ast::ptr_base< ast::ConstantExpr, ast::Node::ref_type::strong >;
184template class ast::ptr_base< ast::SizeofExpr, ast::Node::ref_type::weak >;
185template class ast::ptr_base< ast::SizeofExpr, ast::Node::ref_type::strong >;
186template class ast::ptr_base< ast::AlignofExpr, ast::Node::ref_type::weak >;
187template class ast::ptr_base< ast::AlignofExpr, ast::Node::ref_type::strong >;
188template class ast::ptr_base< ast::UntypedOffsetofExpr, ast::Node::ref_type::weak >;
189template class ast::ptr_base< ast::UntypedOffsetofExpr, ast::Node::ref_type::strong >;
190template class ast::ptr_base< ast::OffsetofExpr, ast::Node::ref_type::weak >;
191template class ast::ptr_base< ast::OffsetofExpr, ast::Node::ref_type::strong >;
192template class ast::ptr_base< ast::OffsetPackExpr, ast::Node::ref_type::weak >;
193template class ast::ptr_base< ast::OffsetPackExpr, ast::Node::ref_type::strong >;
194template class ast::ptr_base< ast::LogicalExpr, ast::Node::ref_type::weak >;
195template class ast::ptr_base< ast::LogicalExpr, ast::Node::ref_type::strong >;
196template class ast::ptr_base< ast::ConditionalExpr, ast::Node::ref_type::weak >;
197template class ast::ptr_base< ast::ConditionalExpr, ast::Node::ref_type::strong >;
198template class ast::ptr_base< ast::CommaExpr, ast::Node::ref_type::weak >;
199template class ast::ptr_base< ast::CommaExpr, ast::Node::ref_type::strong >;
200template class ast::ptr_base< ast::TypeExpr, ast::Node::ref_type::weak >;
201template class ast::ptr_base< ast::TypeExpr, ast::Node::ref_type::strong >;
202template class ast::ptr_base< ast::AsmExpr, ast::Node::ref_type::weak >;
203template class ast::ptr_base< ast::AsmExpr, ast::Node::ref_type::strong >;
204template class ast::ptr_base< ast::ImplicitCopyCtorExpr, ast::Node::ref_type::weak >;
205template class ast::ptr_base< ast::ImplicitCopyCtorExpr, ast::Node::ref_type::strong >;
206template class ast::ptr_base< ast::ConstructorExpr, ast::Node::ref_type::weak >;
207template class ast::ptr_base< ast::ConstructorExpr, ast::Node::ref_type::strong >;
208template class ast::ptr_base< ast::CompoundLiteralExpr, ast::Node::ref_type::weak >;
209template class ast::ptr_base< ast::CompoundLiteralExpr, ast::Node::ref_type::strong >;
210template class ast::ptr_base< ast::RangeExpr, ast::Node::ref_type::weak >;
211template class ast::ptr_base< ast::RangeExpr, ast::Node::ref_type::strong >;
212template class ast::ptr_base< ast::UntypedTupleExpr, ast::Node::ref_type::weak >;
213template class ast::ptr_base< ast::UntypedTupleExpr, ast::Node::ref_type::strong >;
214template class ast::ptr_base< ast::TupleExpr, ast::Node::ref_type::weak >;
215template class ast::ptr_base< ast::TupleExpr, ast::Node::ref_type::strong >;
216template class ast::ptr_base< ast::TupleIndexExpr, ast::Node::ref_type::weak >;
217template class ast::ptr_base< ast::TupleIndexExpr, ast::Node::ref_type::strong >;
218template class ast::ptr_base< ast::TupleAssignExpr, ast::Node::ref_type::weak >;
219template class ast::ptr_base< ast::TupleAssignExpr, ast::Node::ref_type::strong >;
220template class ast::ptr_base< ast::StmtExpr, ast::Node::ref_type::weak >;
221template class ast::ptr_base< ast::StmtExpr, ast::Node::ref_type::strong >;
222template class ast::ptr_base< ast::UniqueExpr, ast::Node::ref_type::weak >;
223template class ast::ptr_base< ast::UniqueExpr, ast::Node::ref_type::strong >;
224template class ast::ptr_base< ast::UntypedInitExpr, ast::Node::ref_type::weak >;
225template class ast::ptr_base< ast::UntypedInitExpr, ast::Node::ref_type::strong >;
226template class ast::ptr_base< ast::InitExpr, ast::Node::ref_type::weak >;
227template class ast::ptr_base< ast::InitExpr, ast::Node::ref_type::strong >;
228template class ast::ptr_base< ast::DeletedExpr, ast::Node::ref_type::weak >;
229template class ast::ptr_base< ast::DeletedExpr, ast::Node::ref_type::strong >;
230template class ast::ptr_base< ast::DefaultArgExpr, ast::Node::ref_type::weak >;
231template class ast::ptr_base< ast::DefaultArgExpr, ast::Node::ref_type::strong >;
232template class ast::ptr_base< ast::GenericExpr, ast::Node::ref_type::weak >;
233template class ast::ptr_base< ast::GenericExpr, ast::Node::ref_type::strong >;
234template class ast::ptr_base< ast::Type, ast::Node::ref_type::weak >;
235template class ast::ptr_base< ast::Type, ast::Node::ref_type::strong >;
236template class ast::ptr_base< ast::VoidType, ast::Node::ref_type::weak >;
237template class ast::ptr_base< ast::VoidType, ast::Node::ref_type::strong >;
238template class ast::ptr_base< ast::BasicType, ast::Node::ref_type::weak >;
239template class ast::ptr_base< ast::BasicType, ast::Node::ref_type::strong >;
240template class ast::ptr_base< ast::PointerType, ast::Node::ref_type::weak >;
241template class ast::ptr_base< ast::PointerType, ast::Node::ref_type::strong >;
242template class ast::ptr_base< ast::ArrayType, ast::Node::ref_type::weak >;
243template class ast::ptr_base< ast::ArrayType, ast::Node::ref_type::strong >;
244template class ast::ptr_base< ast::ReferenceType, ast::Node::ref_type::weak >;
245template class ast::ptr_base< ast::ReferenceType, ast::Node::ref_type::strong >;
246template class ast::ptr_base< ast::QualifiedType, ast::Node::ref_type::weak >;
247template class ast::ptr_base< ast::QualifiedType, ast::Node::ref_type::strong >;
248template class ast::ptr_base< ast::FunctionType, ast::Node::ref_type::weak >;
249template class ast::ptr_base< ast::FunctionType, ast::Node::ref_type::strong >;
250template class ast::ptr_base< ast::ReferenceToType, ast::Node::ref_type::weak >;
251template class ast::ptr_base< ast::ReferenceToType, ast::Node::ref_type::strong >;
252template class ast::ptr_base< ast::StructInstType, ast::Node::ref_type::weak >;
253template class ast::ptr_base< ast::StructInstType, ast::Node::ref_type::strong >;
254template class ast::ptr_base< ast::UnionInstType, ast::Node::ref_type::weak >;
255template class ast::ptr_base< ast::UnionInstType, ast::Node::ref_type::strong >;
256template class ast::ptr_base< ast::EnumInstType, ast::Node::ref_type::weak >;
257template class ast::ptr_base< ast::EnumInstType, ast::Node::ref_type::strong >;
258template class ast::ptr_base< ast::TraitInstType, ast::Node::ref_type::weak >;
259template class ast::ptr_base< ast::TraitInstType, ast::Node::ref_type::strong >;
260template class ast::ptr_base< ast::TypeInstType, ast::Node::ref_type::weak >;
261template class ast::ptr_base< ast::TypeInstType, ast::Node::ref_type::strong >;
262template class ast::ptr_base< ast::TupleType, ast::Node::ref_type::weak >;
263template class ast::ptr_base< ast::TupleType, ast::Node::ref_type::strong >;
264template class ast::ptr_base< ast::TypeofType, ast::Node::ref_type::weak >;
265template class ast::ptr_base< ast::TypeofType, ast::Node::ref_type::strong >;
266template class ast::ptr_base< ast::VarArgsType, ast::Node::ref_type::weak >;
267template class ast::ptr_base< ast::VarArgsType, ast::Node::ref_type::strong >;
268template class ast::ptr_base< ast::ZeroType, ast::Node::ref_type::weak >;
269template class ast::ptr_base< ast::ZeroType, ast::Node::ref_type::strong >;
270template class ast::ptr_base< ast::OneType, ast::Node::ref_type::weak >;
271template class ast::ptr_base< ast::OneType, ast::Node::ref_type::strong >;
272template class ast::ptr_base< ast::GlobalScopeType, ast::Node::ref_type::weak >;
273template class ast::ptr_base< ast::GlobalScopeType, ast::Node::ref_type::strong >;
274template class ast::ptr_base< ast::Designation, ast::Node::ref_type::weak >;
275template class ast::ptr_base< ast::Designation, ast::Node::ref_type::strong >;
276template class ast::ptr_base< ast::Init, ast::Node::ref_type::weak >;
277template class ast::ptr_base< ast::Init, ast::Node::ref_type::strong >;
278template class ast::ptr_base< ast::SingleInit, ast::Node::ref_type::weak >;
279template class ast::ptr_base< ast::SingleInit, ast::Node::ref_type::strong >;
280template class ast::ptr_base< ast::ListInit, ast::Node::ref_type::weak >;
281template class ast::ptr_base< ast::ListInit, ast::Node::ref_type::strong >;
282template class ast::ptr_base< ast::ConstructorInit, ast::Node::ref_type::weak >;
283template class ast::ptr_base< ast::ConstructorInit, ast::Node::ref_type::strong >;
284template class ast::ptr_base< ast::Attribute, ast::Node::ref_type::weak >;
285template class ast::ptr_base< ast::Attribute, ast::Node::ref_type::strong >;
286template class ast::ptr_base< ast::TypeSubstitution, ast::Node::ref_type::weak >;
287template class ast::ptr_base< ast::TypeSubstitution, ast::Node::ref_type::strong >;
Note: See TracBrowser for help on using the repository browser.