source: src/Validate/EliminateTypedef.cpp @ 9939dc3

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since 9939dc3 was 298fe57, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Translated 3/4 of validate_B. Link Reference To Types has been removed and will be translated after we know how much support we need for forall function pointers.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2018 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// EliminateTypedef.cpp -- Removes TypedefDecl nodes from the AST.
8//
9// Author           : Andrew Beach
10// Created On       : Wed Apr 20 16:37:00 2022
11// Last Modified By : Andrew Beach
12// Last Modified On : Mon Apr 25 14:26:00 2022
13// Update Count     : 0
14//
15
16#include "Validate/EliminateTypedef.hpp"
17
18#include <algorithm>
19
20#include "AST/Decl.hpp"
21#include "AST/Pass.hpp"
22#include "AST/Stmt.hpp"
23#include "Common/utility.h"
24
25namespace Validate {
26
27namespace {
28
29struct EliminateTypedefCore {
30        ast::StructDecl const * previsit( ast::StructDecl const * decl );
31        ast::UnionDecl const * previsit( ast::UnionDecl const * decl );
32        ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt );
33};
34
35bool isTypedef( ast::ptr<ast::Decl> const & decl ) {
36        return (nullptr != decl.as<ast::TypedefDecl>());
37}
38
39bool isTypedefStmt( ast::ptr<ast::Stmt> const & stmt ) {
40        if ( auto declStmt = stmt.as<ast::DeclStmt>() ) {
41                return isTypedef( declStmt->decl );
42        }
43        return false;
44}
45
46template<typename node_t, typename super_t, typename field_t, typename pred_t>
47node_t const * field_erase_if( node_t const * node, field_t super_t::*field, pred_t && pred) {
48        node_t * mut = ast::mutate( node );
49        erase_if( mut->*field, pred );
50        return mut;
51}
52
53ast::StructDecl const * EliminateTypedefCore::previsit( ast::StructDecl const * decl ) {
54        return field_erase_if( decl, &ast::StructDecl::members, isTypedef );
55}
56
57ast::UnionDecl const * EliminateTypedefCore::previsit( ast::UnionDecl const * decl ) {
58        return field_erase_if( decl, &ast::UnionDecl::members, isTypedef );
59}
60
61ast::CompoundStmt const * EliminateTypedefCore::previsit( ast::CompoundStmt const * stmt ) {
62        return field_erase_if( stmt, &ast::CompoundStmt::kids, isTypedefStmt );
63}
64
65} // namespace
66
67/// Removes TypedefDecl nodes from the AST.
68void eliminateTypedef( ast::TranslationUnit & translationUnit ) {
69        ast::Pass<EliminateTypedefCore>::run( translationUnit );
70        erase_if( translationUnit.decls, isTypedef );
71}
72
73} // namespace Validate
74
75// Local Variables: //
76// tab-width: 4 //
77// mode: c++ //
78// compile-command: "make install" //
79// End: //
Note: See TracBrowser for help on using the repository browser.