source: src/AST/Util.cpp@ 496f92ed

ADT ast-experimental enum pthread-emulation qualifiedEnum
Last change on this file since 496f92ed was f69fac7, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Got the Util module started by moving over the unused AssertAcyclic pass.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2019 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// Util.hpp -- General utilities for working with the AST.
8//
9// Author : Andrew Beach
10// Created On : Wed Jan 19 9:46:00 2022
11// Last Modified By : Andrew Beach
12// Last Modified On : Fri Feb 18 9:42:00 2022
13// Update Count : 0
14//
15
16#include "Util.hpp"
17
18#include "Decl.hpp"
19#include "Node.hpp"
20#include "Pass.hpp"
21#include "TranslationUnit.hpp"
22#include "Common/ScopedMap.h"
23
24#include <vector>
25
26namespace ast {
27
28namespace {
29
30/// Check that ast::ptr/strong references do not form a cycle.
31struct NoStrongCyclesCore {
32 std::vector<const Node *> parents;
33
34 void previsit( const Node * node ) {
35 for ( auto & parent : parents ) {
36 assert( parent != node );
37 }
38 parents.push_back( node );
39 }
40
41 void postvisit( const Node * node ) {
42 assert( !parents.empty() );
43 assert( parents.back() == node );
44 parents.pop_back();
45 }
46};
47
48struct InvariantCore {
49 // To save on the number of visits: this is a kind of composed core.
50 // None of the passes should make changes so ordering doesn't matter.
51 NoStrongCyclesCore no_strong_cycles;
52
53 void previsit( const Node * node ) {
54 no_strong_cycles.previsit( node );
55 }
56
57 void postvisit( const Node * node ) {
58 no_strong_cycles.postvisit( node );
59 }
60};
61
62} // namespace
63
64void checkInvariants( TranslationUnit & transUnit ) {
65 ast::Pass<InvariantCore>::run( transUnit );
66}
67
68} // namespace ast
Note: See TracBrowser for help on using the repository browser.