source: src/AST/Create.cpp @ 7ed7b4a

ADTast-experimental
Last change on this file since 7ed7b4a was 20737104, checked in by Andrew Beach <ajbeach@…>, 20 months ago

Wrote a new asForward helper for Autogen.

  • 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// 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
23namespace ast {
24
25namespace {
26
27        template<typename node_t>
28        std::vector<ast::ptr<node_t>> vectorCopy(
29                        std::vector<ast::ptr<node_t>> const & nodes ) {
30                return map_range<std::vector<ast::ptr<node_t>>>( nodes,
31                        []( ptr<node_t> const & node ){
32                                return deepCopy<node_t>( node );
33                        }
34                );
35        }
36
37} // namespace
38
39FunctionDecl * asForward( FunctionDecl const * decl ) {
40        if ( nullptr == decl->stmts ) {
41                return nullptr;
42        }
43        return new ast::FunctionDecl( decl->location,
44                decl->name,
45                vectorCopy( decl->type_params ),
46                vectorCopy( decl->assertions ),
47                vectorCopy( decl->params ),
48                vectorCopy( decl->returns ),
49                nullptr,
50                decl->storage,
51                decl->linkage,
52                vectorCopy( decl->attributes ),
53                decl->funcSpec,
54                decl->type->isVarArgs
55        );
56}
57
58StructDecl * asForward( StructDecl const * decl ) {
59        if ( !decl->body ) {
60                return nullptr;
61        }
62        StructDecl * fwd = new StructDecl( decl->location,
63                decl->name,
64                decl->kind,
65                vectorCopy<ast::Attribute>( decl->attributes ),
66                decl->linkage );
67        fwd->params = vectorCopy( decl->params );
68        return fwd;
69}
70
71UnionDecl * asForward( UnionDecl const * decl ) {
72        if ( !decl->body ) {
73                return nullptr;
74        }
75        UnionDecl * fwd = new UnionDecl( decl->location,
76                decl->name,
77                vectorCopy( decl->attributes ),
78                decl->linkage );
79        fwd->params = vectorCopy( decl->params );
80        return fwd;
81}
82
83}
Note: See TracBrowser for help on using the repository browser.