ADTast-experimentalpthread-emulation
Last change
on this file since b6c3688 was
8f1e035,
checked in by Andrew Beach <ajbeach@…>, 22 months ago
|
Created a new module for more ast helpers. Put in code to efficiently create forward declarations.
|
-
Property mode set to
100644
|
File size:
1.4 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 | // Create.cpp -- Helpers to create pieces of the AST. |
---|
8 | // |
---|
9 | // Author : Andrew Beach |
---|
10 | // Created On : Tue Sep 20 13:28:00 2022 |
---|
11 | // Last Modified By : Andrew Beach |
---|
12 | // Last Modified On : Tue Sep 20 14:55:00 2022 |
---|
13 | // Update Count : 0 |
---|
14 | // |
---|
15 | |
---|
16 | #include "AST/Create.hpp" |
---|
17 | |
---|
18 | #include "AST/Attribute.hpp" |
---|
19 | #include "AST/Copy.hpp" |
---|
20 | #include "AST/Decl.hpp" |
---|
21 | |
---|
22 | namespace ast { |
---|
23 | |
---|
24 | namespace { |
---|
25 | |
---|
26 | template<typename node_t> |
---|
27 | std::vector<ast::ptr<node_t>> vectorCopy( |
---|
28 | std::vector<ast::ptr<node_t>> const & nodes ) { |
---|
29 | return map_range<std::vector<ast::ptr<node_t>>>( nodes, |
---|
30 | []( ptr<node_t> const & node ){ |
---|
31 | return deepCopy<node_t>( node ); |
---|
32 | } |
---|
33 | ); |
---|
34 | } |
---|
35 | |
---|
36 | } // namespace |
---|
37 | |
---|
38 | StructDecl * asForward( StructDecl const * decl ) { |
---|
39 | if ( !decl->body ) { |
---|
40 | return nullptr; |
---|
41 | } |
---|
42 | StructDecl * fwd = new StructDecl( decl->location, |
---|
43 | decl->name, |
---|
44 | decl->kind, |
---|
45 | vectorCopy<ast::Attribute>( decl->attributes ), |
---|
46 | decl->linkage ); |
---|
47 | fwd->params = vectorCopy( decl->params ); |
---|
48 | return fwd; |
---|
49 | } |
---|
50 | |
---|
51 | UnionDecl * asForward( UnionDecl const * decl ) { |
---|
52 | if ( !decl->body ) { |
---|
53 | return nullptr; |
---|
54 | } |
---|
55 | UnionDecl * fwd = new UnionDecl( decl->location, |
---|
56 | decl->name, |
---|
57 | vectorCopy( decl->attributes ), |
---|
58 | decl->linkage ); |
---|
59 | fwd->params = vectorCopy( decl->params ); |
---|
60 | return fwd; |
---|
61 | } |
---|
62 | |
---|
63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.