source: src/ResolvExpr/PtrsAssignable.cc@ f5ec35a

Last change on this file since f5ec35a was c6b4432, checked in by Andrew Beach <ajbeach@…>, 23 months ago

Remove BaseSyntaxNode and clean-up.

  • Property mode set to 100644
File size: 3.5 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// PtrsAssignable.cc --
8//
9// Author : Richard C. Bilson
10// Created On : Sun May 17 11:44:11 2015
11// Last Modified By : Andrew
12// Last Modified On : Mon Jun 24 15:29:00 2019
13// Update Count : 9
14//
15
16#include "PtrsAssignable.hpp"
17
18#include "AST/Pass.hpp"
19#include "AST/Type.hpp"
20#include "AST/TypeEnvironment.hpp"
21
22namespace ResolvExpr {
23
24// TODO: Get rid of the `_new` suffix when the old version is removed.
25struct PtrsAssignable_new : public ast::WithShortCircuiting {
26 const ast::Type * dst;
27 const ast::TypeEnvironment & typeEnv;
28 int result;
29
30 PtrsAssignable_new( const ast::Type * dst, const ast::TypeEnvironment & env ) :
31 dst( dst ), typeEnv( env ), result( 0 ) {}
32
33 void previsit( Type * ) { visit_children = false; }
34
35 void postvisit( const ast::EnumInstType * ) {
36 if ( dynamic_cast< const ast::BasicType * >( dst ) ) {
37 // int * = E *, etc. is safe. This isn't technically correct, as each
38 // enum has one basic type that it is compatible with, an that type can
39 // differ from enum to enum. Without replicating GCC's internal logic,
40 // there is no way to know which type this particular enum is compatible
41 // with, so punt on this for now.
42 result = 1;
43 }
44 }
45 void postvisit( const ast::TypeInstType * inst ) {
46 if ( const ast::EqvClass * eqv = typeEnv.lookup( *inst ) ) {
47 if ( eqv->bound ) {
48 // T * = S * for any S depends on the type bound to T
49 result = ptrsAssignable( eqv->bound, dst, typeEnv );
50 }
51 }
52 }
53};
54
55int ptrsAssignable( const ast::Type * src, const ast::Type * dst,
56 const ast::TypeEnvironment & env ) {
57 if ( const ast::TypeInstType * dstAsInst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
58 if ( const ast::EqvClass * eqv = env.lookup( *dstAsInst ) ) {
59 return ptrsAssignable( src, eqv->bound, env );
60 }
61 }
62 if ( dynamic_cast< const ast::VoidType * >( dst ) ) {
63 return -1;
64 } else {
65 ast::Pass<PtrsAssignable_new> visitor( dst, env );
66 src->accept( visitor );
67 return visitor.core.result;
68 }
69
70// see ticket #136 (this should be able to replace the visitor).
71#if 0
72 if ( const ast::TypeInstType * dstAsTypeInst =
73 dynamic_cast< const ast::TypeInstType* >( dst ) ) {
74 if ( const ast::EqvClass * eqv = env.lookup( dstAsTypeInst->get_name() ) ) {
75 return ptrsAssignable( src, eqv->type, env );
76 } // if
77 } // if
78 if ( dynamic_cast< VoidType* >( dst ) ) {
79 // void * = T * for any T is unsafe
80 // xxx - this should be safe, but that currently breaks the build
81 return -1;
82 } else if ( dynamic_cast< EnumInstType * >( src ) ) {
83 if ( dynamic_cast< BasicType * >( dst ) ) {
84 // int * = E *, etc. is safe. This isn't technically correct, as each
85 // enum has one basic type that it is compatible with, an that type can
86 // differ from enum to enum. Without replicating GCC's internal logic,
87 // there is no way to know which type this particular enum is compatible
88 // with, so punt on this for now.
89 return 1;
90 }
91 } else if ( const ast::TypeInstType * typeInstType =
92 dynamic_cast< const ast::TypeInstType * >( src ) ) {
93 if ( const ast::EqvClass * eqv = env.lookup( typeInstType->name ) ) {
94 if ( eqv->bound ) {
95 // T * = S * for any S depends on the type bound to T
96 return ptrsAssignable( eqv->bound, dst, env );
97 }
98 }
99 }
100 return 0;
101#endif
102}
103
104} // namespace ResolvExpr
105
106// Local Variables: //
107// tab-width: 4 //
108// mode: c++ //
109// compile-command: "make install" //
110// End: //
Note: See TracBrowser for help on using the repository browser.