source: src/ResolvExpr/EraseWith.cpp@ f22b170b

Last change on this file since f22b170b was d3652df, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Took the new EraseWith pass out of the box pass. It might be able to go even earlier or folded into an existing pass. C code generation now will not generate WithStmt nodes.

  • Property mode set to 100644
File size: 1.1 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// EraseWith.cpp -- After resolution, erase all with constructs.
8//
9// Author : Andrew Beach
10// Created On : Sun Oct 8 9:42:00 2023
11// Last Modified By : Andrew Beach
12// Last Modified On : Sun Oct 8 10:03:00 2023
13// Update Count : 0
14//
15
16#include "EraseWith.hpp"
17
18#include "AST/Decl.hpp"
19#include "AST/Pass.hpp"
20#include "AST/Stmt.hpp"
21
22namespace ResolvExpr {
23
24namespace {
25
26struct WithEraser {
27 ast::FunctionDecl const * postvisit( ast::FunctionDecl const * decl ) {
28 if ( decl->withExprs.empty() ) return decl;
29 auto mutDecl = mutate( decl );
30 mutDecl->withExprs.clear();
31 return mutDecl;
32 }
33
34 ast::Stmt const * postvisit( ast::DeclStmt const * stmt ) {
35 if ( auto decl = stmt->decl.as<ast::WithStmt>() ) return decl->stmt;
36 return stmt;
37 }
38};
39
40} // namespace
41
42void eraseWith( ast::TranslationUnit & translationUnit ) {
43 ast::Pass<WithEraser>::run( translationUnit );
44}
45
46} // namespace ResolvExpr
Note: See TracBrowser for help on using the repository browser.