source: src/AST/Create.cpp @ 0bcd707

ADTast-experimental
Last change on this file since 0bcd707 was 8f06277, checked in by Andrew Beach <ajbeach@…>, 15 months ago

Some clean-up in Common/utility.h. Deleted some unused declarations and moved others to one of two new headers.

  • Property mode set to 100644
File size: 1.9 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 21  9:29:00 2022
13// Update Count     : 1
14//
15
16#include "AST/Create.hpp"
17
18#include "AST/Attribute.hpp"
19#include "AST/Copy.hpp"
20#include "AST/Decl.hpp"
21#include "AST/Type.hpp"
22#include "Common/Iterate.hpp"
23
24namespace ast {
25
26namespace {
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
40FunctionDecl * 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
59StructDecl * 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
72UnionDecl * 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}
Note: See TracBrowser for help on using the repository browser.