source: src/ResolvExpr/ResolveTypeof.cc @ 9d79f93

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 9d79f93 was 9d79f93, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Convert ResolveTypeof? to PassVisitor?

  • Property mode set to 100644
File size: 2.2 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// ResolveTypeof.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 12:12:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue May 19 16:49:04 2015
13// Update Count     : 3
14//
15
16#include "ResolveTypeof.h"
17
18#include <cassert>               // for assert
19
20#include "Common/PassVisitor.h"  // for PassVisitor
21#include "Resolver.h"            // for resolveInVoidContext
22#include "SynTree/Expression.h"  // for Expression
23#include "SynTree/Mutator.h"     // for Mutator
24#include "SynTree/Type.h"        // for TypeofType, Type
25
26namespace SymTab {
27class Indexer;
28}  // namespace SymTab
29
30namespace ResolvExpr {
31        namespace {
32#if 0
33                void
34                printAlts( const AltList &list, std::ostream &os, int indent = 0 )
35                {
36                        for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) {
37                                i->print( os, indent );
38                                os << std::endl;
39                        }
40                }
41#endif
42        }
43
44        class ResolveTypeof : public WithShortCircuiting {
45          public:
46                ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {}
47                void premutate( TypeofType *typeofType );
48                Type * postmutate( TypeofType *typeofType );
49
50          private:
51                const SymTab::Indexer &indexer;
52        };
53
54        Type * resolveTypeof( Type *type, const SymTab::Indexer &indexer ) {
55                PassVisitor<ResolveTypeof> mutator( indexer );
56                return type->acceptMutator( mutator );
57        }
58
59        void ResolveTypeof::premutate( TypeofType * ) {
60                visit_children = false;
61        }
62
63        Type * ResolveTypeof::postmutate( TypeofType *typeofType ) {
64#if 0
65                std::cerr << "resolving typeof: ";
66                typeofType->print( std::cerr );
67                std::cerr << std::endl;
68#endif
69                if ( typeofType->expr ) {
70                        Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer );
71                        assert( newExpr->result && ! newExpr->result->isVoid() );
72                        Type * newType = newExpr->result;
73                        newExpr->result = nullptr;
74                        delete typeofType;
75                        delete newExpr;
76                        return newType;
77                } // if
78                return typeofType;
79        }
80} // namespace ResolvExpr
81
82// Local Variables: //
83// tab-width: 4 //
84// mode: c++ //
85// compile-command: "make install" //
86// End: //
Note: See TracBrowser for help on using the repository browser.