source: src/ResolvExpr/PtrsAssignable.cc @ 4040425

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 4040425 was 4040425, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

change keyword type to otype and context to trait

  • Property mode set to 100644
File size: 4.4 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 : Peter A. Buhr
12// Last Modified On : Wed Mar  2 17:36:05 2016
13// Update Count     : 8
14//
15
16#include "typeops.h"
17#include "SynTree/Type.h"
18#include "SynTree/Declaration.h"
19#include "SynTree/Visitor.h"
20
21
22namespace ResolvExpr {
23        class PtrsAssignable : public Visitor {
24          public:
25                PtrsAssignable( Type *dest, const TypeEnvironment &env );
26
27                int get_result() const { return result; }
28
29                virtual void visit( VoidType *voidType );
30                virtual void visit( BasicType *basicType );
31                virtual void visit( PointerType *pointerType );
32                virtual void visit( ArrayType *arrayType );
33                virtual void visit( FunctionType *functionType );
34                virtual void visit( StructInstType *inst );
35                virtual void visit( UnionInstType *inst );
36                virtual void visit( EnumInstType *inst );
37                virtual void visit( TraitInstType *inst );
38                virtual void visit( TypeInstType *inst );
39                virtual void visit( TupleType *tupleType );
40                virtual void visit( VarArgsType *varArgsType );
41          private:
42                Type *dest;
43                int result;
44                const TypeEnvironment &env;
45        };
46
47        int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env ) {
48                if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
49                        EqvClass eqvClass;
50                        if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) {
51                                return ptrsAssignable( src, eqvClass.type, env );
52                        } // if
53                } // if
54                if ( dynamic_cast< VoidType* >( dest ) ) {
55                        return 1;
56                } else {
57                        PtrsAssignable ptrs( dest, env );
58                        src->accept( ptrs );
59                        return ptrs.get_result();
60                } // if
61        }
62
63        PtrsAssignable::PtrsAssignable( Type *dest, const TypeEnvironment &env ) : dest( dest ), result( 0 ), env( env ) {
64        }
65
66        void PtrsAssignable::visit( VoidType *voidType ) {
67                if ( dynamic_cast< FunctionType* >( dest ) ) {
68                        result = 0;
69                } else {
70                        result = -1;
71                } // if
72        }
73
74        void PtrsAssignable::visit( BasicType *basicType ) {
75        }
76
77        void PtrsAssignable::visit( PointerType *pointerType ) {
78        }
79
80        void PtrsAssignable::visit( ArrayType *arrayType ) {
81        }
82
83        void PtrsAssignable::visit( FunctionType *functionType ) {
84                result = -1;
85        }
86
87        void PtrsAssignable::visit( StructInstType *inst ) {
88                // I don't think we should be doing anything here, but I'm willing to admit that I might be wrong
89        }
90
91        void PtrsAssignable::visit( UnionInstType *inst ) {
92                // I don't think we should be doing anything here, but I'm willing to admit that I might be wrong
93        }
94
95        void PtrsAssignable::visit( EnumInstType *inst ) {
96                if ( dynamic_cast< EnumInstType* >( inst ) ) {
97                        result = 1;
98                } else if ( BasicType *bt = dynamic_cast< BasicType* >( inst ) ) {
99                        result = bt->get_kind() == BasicType::SignedInt;
100                }
101        }
102
103        void PtrsAssignable::visit( TraitInstType *inst ) {
104                // I definitely don't think we should be doing anything here
105        }
106
107        void PtrsAssignable::visit( TypeInstType *inst ) {
108                EqvClass eqvClass;
109                if ( env.lookup( inst->get_name(), eqvClass ) && eqvClass.type ) {
110                        result = ptrsAssignable( eqvClass.type, dest, env );
111                } else {
112                        result = 0;
113                } // if
114        }
115
116        void PtrsAssignable::visit( TupleType *tupleType ) {
117///  // This code doesn't belong here, but it might be useful somewhere else
118///   if ( TupleType *destAsTuple = dynamic_cast< TupleType* >( dest ) ) {
119///     int ret = 0;
120///     std::list< Type* >::const_iterator srcIt = tupleType->get_types().begin();
121///     std::list< Type* >::const_iterator destIt = destAsTuple->get_types().begin();
122///     while ( srcIt != tupleType->get_types().end() && destIt != destAsTuple->get_types().end() ) {
123///       int assignResult = ptrsAssignable( *srcIt++, *destIt++ );
124///       if ( assignResult == 0 ) {
125///         result = assignResult;
126///         return;
127///       } else if ( assignResult < 0 ) {
128///         ret = -1;
129///       } else if ( ret > 0 ) {
130///         ret += assignResult;
131///       }
132///     }
133///     if ( srcIt == tupleType->get_types().end() && destIt == destAsTuple->get_types().end() ) {
134///       result = ret;
135///     } else {
136///       result = 0;
137///     }
138///   }
139        }
140
141        void PtrsAssignable::visit( VarArgsType *varArgsType ) {
142        }
143} // namespace ResolvExpr
144
145// Local Variables: //
146// tab-width: 4 //
147// mode: c++ //
148// compile-command: "make install" //
149// End: //
Note: See TracBrowser for help on using the repository browser.