source: src/AST/GenericSubstitution.cpp @ 5a3d67c

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 5a3d67c was 60aaa51d, checked in by Aaron Moss <a3moss@…>, 5 years ago

More resolver porting; mostly CurrentObject?

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[d8938622]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// GenericSubstitution.cpp --
8//
9// Author           : Aaron B. Moss
10// Created On       : Wed May 22 14:15:00 2019
11// Last Modified By : Aaron B. Moss
12// Created On       : Wed May 22 14:15:00 2019
13// Update Count     : 1
14//
15
16#include "GenericSubstitution.hpp"
17
18#include <cassert>
19#include <utility>               // for move
20
21#include "Decl.hpp"
22#include "Node.hpp"              // for maybe_accept
23#include "Pass.hpp"
24#include "Type.hpp"
[0b8bf27]25#include "TypeSubstitution.hpp"
[d8938622]26
27namespace ast {
28
29namespace {
30        struct GenericSubstitutionBuilder : public WithShortCircuiting {
31                TypeSubstitution sub;
32
[60aaa51d]33                void previsit( const Type * ) {
34                        // allow empty substitution for non-generic type
35                        visit_children = false;
[d8938622]36                }
37
[335f2d8]38                void previsit( const ReferenceType * ) {
[d8938622]39                        // do nothing; allows substitution from base type
40                }
41
[60aaa51d]42        private:
43                // make substitution for generic type
44                void makeSub( const ReferenceToType * ty ) {
[76ed81f]45                        visit_children = false;
[d8938622]46                        const AggregateDecl * aggr = ty->aggr();
47                        sub = TypeSubstitution{ aggr->params.begin(), aggr->params.end(), ty->params.begin() };
48                }
[60aaa51d]49
50        public:
51                void previsit( const StructInstType * ty ) {
52                        makeSub( ty );
53                }
54
55                void previsit( const UnionInstType * ty ) {
56                        makeSub( ty );
57                }
[d8938622]58        };
59}
60
[60aaa51d]61TypeSubstitution genericSubstitution( const Type * ty ) {
[d8938622]62        Pass<GenericSubstitutionBuilder> builder;
63        maybe_accept( ty, builder );
64        return std::move(builder.pass.sub);
65}
66
67}
68
69// Local Variables: //
70// tab-width: 4 //
71// mode: c++ //
72// compile-command: "make install" //
73// End: //
Note: See TracBrowser for help on using the repository browser.