source: src/ResolvExpr/PtrsAssignable.cc @ 1cbca6e

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 1cbca6e was 843054c2, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

licencing: seventh groups of files

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