source: src/AST/GenericSubstitution.cpp@ 76ed81f

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum stuck-waitfor-destruct
Last change on this file since 76ed81f was 76ed81f, checked in by Aaron Moss <a3moss@…>, 7 years ago

Broken stuff pre-Pass fix

  • Property mode set to 100644
File size: 1.6 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// 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"
25#include "TypeSubstitution.cpp"
26
27namespace ast {
28
29namespace {
30 struct GenericSubstitutionBuilder : public WithShortCircuiting {
31 TypeSubstitution sub;
32
33 const Type * previsit( const Type * ty ) {
34 assertf( false, "Attempted generic substitution for non-aggregate type: %s",
35 toString( ty ).c_str() );
36 return ty;
37 }
38
39 const ReferenceType * previsit( const ReferenceType * ty ) {
40 // do nothing; allows substitution from base type
41 return ty;
42 }
43
44 const ReferenceToType * previsit( const ReferenceToType * ty ) {
45 visit_children = false;
46 // build substitution from base parameters
47 const AggregateDecl * aggr = ty->aggr();
48 sub = TypeSubstitution{ aggr->params.begin(), aggr->params.end(), ty->params.begin() };
49 return ty;
50 }
51 };
52}
53
54TypeSubstitution genericSubsitution( const Type * ty ) {
55 Pass<GenericSubstitutionBuilder> builder;
56 maybe_accept( ty, builder );
57 return std::move(builder.pass.sub);
58}
59
60}
61
62// Local Variables: //
63// tab-width: 4 //
64// mode: c++ //
65// compile-command: "make install" //
66// End: //
Note: See TracBrowser for help on using the repository browser.