source: src/SynTree/GcTracer.h @ b5aa3d8

new-envwith_gc
Last change on this file since b5aa3d8 was b5aa3d8, checked in by Aaron Moss <a3moss@…>, 5 years ago

Trace type attributes

  • Property mode set to 100644
File size: 2.0 KB
Line 
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// GcTracer.h --
8//
9// Author           : Aaron B. Moss
10// Created On       : Thu Mar 15 14:47:00 2018
11// Last Modified By : Aaron B. Moss
12// Last Modified On : Thu Mar 15 14:47:00 2018
13// Update Count     : 1
14//
15
16#pragma once
17
18#include <list>
19
20#include "BaseSyntaxNode.h"
21#include "Expression.h"
22#include "Type.h"
23
24#include "Common/GC.h"
25#include "Common/PassVisitor.h"
26
27class Expression;
28
29/// Implements `trace` method for syntax nodes
30class GcTracer final : public WithShortCircuiting, public WithVisitorRef<GcTracer> {
31        const GC& gc;
32
33public:
34        GcTracer( const GC& gc ) : gc(gc) {}
35
36        // mark node and children
37
38        void previsit( BaseSyntaxNode * node ) {
39                // skip tree if already seen
40                // xxx - this should be uncommented (it breaks object cycles), but at the moment it seems
41                // like the object cycles don't happen and other bugs do
42                // if ( node->mark == gc.mark ) {
43                //      visit_children = false;
44                //      return;
45                // }
46
47                // mark node
48                node->mark = gc.mark;
49        }
50
51        // add visits left out by PassVisitor
52
53        void postvisit( Expression* expr ) {
54                maybeAccept( expr->env, *visitor );
55        }
56
57        void postvisit( UntypedExpr* expr ) {
58                postvisit( static_cast<Expression*>(expr) );
59                maybeAccept( expr->function, *visitor );
60        }
61
62        void postvisit( Type* type ) {
63                acceptAll( type->attributes, *visitor );
64        }
65
66        void postvisit( PointerType* type ) {
67                postvisit( static_cast<Type*>(type) );
68                maybeAccept( type->dimension, *visitor );
69        }
70};
71
72/// Traces entire translation unit recursively
73static inline const GC& operator<< ( const GC& gc, const std::list<Declaration*>& translationUnit ) {
74        PassVisitor<GcTracer> tracer{ gc };
75        acceptAll( const_cast<std::list<Declaration*>&>( translationUnit ), tracer );
76        return gc;
77}
78
79// Local Variables: //
80// tab-width: 4 //
81// mode: c++ //
82// compile-command: "make install" //
83// End: //
Note: See TracBrowser for help on using the repository browser.