source: translator/ResolvExpr/PtrsAssignable.cc @ f7f6785

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 f7f6785 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

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