source: src/ControlStruct/HoistControlDecls.cpp @ a488783

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since a488783 was a488783, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Translated the first half of validate-D. HoistControlStruct? is pretty much the same, Autogen has changed a lot due to the changes in the AST.

  • Property mode set to 100644
File size: 1.8 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// HoistControlDecls.cpp -- Desugar Cforall control structures.
8//
9// Author           : Andrew Beach
10// Created On       : Fri Dec  3 15:34:00 2021
11// Last Modified By : Andrew Beach
12// Last Modified On : Fri Dec  3 15:34:00 2021
13// Update Count     : 0
14//
15
16#include "HoistControlDecls.hpp"
17
18#include "AST/Decl.hpp"
19#include "AST/Pass.hpp"
20#include "AST/TranslationUnit.hpp"
21
22namespace ControlStruct {
23
24namespace {
25
26template<typename StmtT>
27const ast::Stmt * hoist( const StmtT * stmt ) {
28        // If no hoisting is needed, then make no changes.
29        if ( 0 == stmt->inits.size() ) {
30                return stmt;
31        }
32
33        // Put initializers and the old statement in the compound statement.
34        ast::CompoundStmt * block = new ast::CompoundStmt( stmt->location );
35        StmtT * mutStmt = ast::mutate( stmt );
36        for ( const ast::Stmt * next : mutStmt->inits ) {
37                block->kids.push_back( next );
38        }
39        mutStmt->inits.clear();
40        block->kids.push_back( mutStmt );
41        return block;
42}
43
44struct HoistControlCore {
45        const ast::Stmt * postvisit( const ast::IfStmt * stmt ) {
46                return hoist<ast::IfStmt>( stmt );
47        }
48        const ast::Stmt * postvisit( const ast::ForStmt * stmt ) {
49                return hoist<ast::ForStmt>( stmt );
50        }
51        const ast::Stmt * postvisit( const ast::WhileStmt * stmt ) {
52                return hoist<ast::WhileStmt>( stmt );
53        }
54};
55
56} // namespace
57
58/// Hoist initialization out of for statements.
59void hoistControlDecls( ast::TranslationUnit & translationUnit ) {
60        ast::Pass<HoistControlCore>::run( translationUnit );
61}
62
63} // namespace ControlStruct
64
65// Local Variables: //
66// tab-width: 4 //
67// mode: c++ //
68// compile-command: "make install" //
69// End: //
Note: See TracBrowser for help on using the repository browser.