[8f1e035] | 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 |
---|
[20737104] | 12 | // Last Modified On : Tue Sep 21 9:29:00 2022 |
---|
| 13 | // Update Count : 1 |
---|
[8f1e035] | 14 | // |
---|
| 15 | |
---|
| 16 | #include "AST/Create.hpp" |
---|
| 17 | |
---|
| 18 | #include "AST/Attribute.hpp" |
---|
| 19 | #include "AST/Copy.hpp" |
---|
| 20 | #include "AST/Decl.hpp" |
---|
[20737104] | 21 | #include "AST/Type.hpp" |
---|
[8f06277] | 22 | #include "Common/Iterate.hpp" |
---|
[8f1e035] | 23 | |
---|
| 24 | namespace ast { |
---|
| 25 | |
---|
| 26 | namespace { |
---|
| 27 | |
---|
| 28 | template<typename node_t> |
---|
| 29 | std::vector<ast::ptr<node_t>> vectorCopy( |
---|
| 30 | std::vector<ast::ptr<node_t>> const & nodes ) { |
---|
| 31 | return map_range<std::vector<ast::ptr<node_t>>>( nodes, |
---|
| 32 | []( ptr<node_t> const & node ){ |
---|
| 33 | return deepCopy<node_t>( node ); |
---|
| 34 | } |
---|
| 35 | ); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | } // namespace |
---|
| 39 | |
---|
[20737104] | 40 | FunctionDecl * asForward( FunctionDecl const * decl ) { |
---|
| 41 | if ( nullptr == decl->stmts ) { |
---|
| 42 | return nullptr; |
---|
| 43 | } |
---|
| 44 | return new ast::FunctionDecl( decl->location, |
---|
| 45 | decl->name, |
---|
| 46 | vectorCopy( decl->type_params ), |
---|
| 47 | vectorCopy( decl->assertions ), |
---|
| 48 | vectorCopy( decl->params ), |
---|
| 49 | vectorCopy( decl->returns ), |
---|
| 50 | nullptr, |
---|
| 51 | decl->storage, |
---|
| 52 | decl->linkage, |
---|
| 53 | vectorCopy( decl->attributes ), |
---|
| 54 | decl->funcSpec, |
---|
| 55 | decl->type->isVarArgs |
---|
| 56 | ); |
---|
| 57 | } |
---|
| 58 | |
---|
[8f1e035] | 59 | StructDecl * asForward( StructDecl const * decl ) { |
---|
| 60 | if ( !decl->body ) { |
---|
| 61 | return nullptr; |
---|
| 62 | } |
---|
| 63 | StructDecl * fwd = new StructDecl( decl->location, |
---|
| 64 | decl->name, |
---|
| 65 | decl->kind, |
---|
| 66 | vectorCopy<ast::Attribute>( decl->attributes ), |
---|
| 67 | decl->linkage ); |
---|
| 68 | fwd->params = vectorCopy( decl->params ); |
---|
| 69 | return fwd; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | UnionDecl * asForward( UnionDecl const * decl ) { |
---|
| 73 | if ( !decl->body ) { |
---|
| 74 | return nullptr; |
---|
| 75 | } |
---|
| 76 | UnionDecl * fwd = new UnionDecl( decl->location, |
---|
| 77 | decl->name, |
---|
| 78 | vectorCopy( decl->attributes ), |
---|
| 79 | decl->linkage ); |
---|
| 80 | fwd->params = vectorCopy( decl->params ); |
---|
| 81 | return fwd; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | } |
---|