source: src/Validate/FindSpecialDecls.cc @ 2bfc6b2

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2bfc6b2 was 2bfc6b2, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Refactor FindSpecialDeclarations? and associated special declarations

  • Property mode set to 100644
File size: 3.1 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2018 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// FindSpecialDecls.cc --
8//
9// Author           : Rob Schluntz
10// Created On       : Thu Aug 30 09:49:43 2018
11// Last Modified By : Rob Schluntz
12// Last Modified On : Thu Aug 30 09:55:25 2018
13// Update Count     : 2
14//
15
16#include "FindSpecialDecls.h"
17
18#include "Common/PassVisitor.h"
19#include "SynTree/Declaration.h"
20#include "SynTree/Type.h"
21
22// NOTE: currently, it is assumed that every special declaration occurs at the top-level,
23// so function bodies, aggregate bodies, object initializers, etc. are not visited.
24// If this assumption changes, e.g., with the introduction of namespaces, remove the visit_children assignments.
25
26namespace Validate {
27        Type * SizeType = nullptr;
28  FunctionDecl * dereferenceOperator = nullptr;
29  StructDecl * dtorStruct = nullptr;
30  FunctionDecl * dtorStructDestroy = nullptr;
31
32        namespace {
33                struct FindSpecialDecls final : public WithShortCircuiting {
34                        void previsit( ObjectDecl * objDecl );
35                        void previsit( FunctionDecl * funcDecl );
36                        void previsit( StructDecl * structDecl );
37                        void previsit( UnionDecl * unionDecl );
38                        void previsit( EnumDecl * enumDecl );
39                        void previsit( TraitDecl * traitDecl );
40                };
41        } // namespace
42
43        void findSpecialDecls( std::list< Declaration * > &translationUnit ) {
44                PassVisitor<FindSpecialDecls> finder;
45                acceptAll( translationUnit, finder );
46                // TODO: conditionally generate 'fake' declarations for missing features, so that
47                // translation can proceed in the event that builtins, prelude, etc. are missing.
48        }
49
50        namespace {
51                void FindSpecialDecls::previsit( ObjectDecl * ) {
52                        visit_children = false;
53                }
54
55                void FindSpecialDecls::previsit( FunctionDecl * funcDecl ) {
56                        visit_children = false;
57                        if ( ! dereferenceOperator && funcDecl->name == "*?" && funcDecl->linkage == LinkageSpec::Intrinsic ) {
58                                // find and remember the intrinsic dereference operator for object pointers
59                                FunctionType * ftype = funcDecl->type;
60                                if ( ftype->parameters.size() == 1 ) {
61                                        PointerType * ptrType = strict_dynamic_cast<PointerType *>( ftype->parameters.front()->get_type() );
62                                        if ( ptrType->base->get_qualifiers() == Type::Qualifiers() ) {
63                                                TypeInstType * inst = dynamic_cast<TypeInstType *>( ptrType->base );
64                                                if ( inst && ! inst->get_isFtype() ) {
65                                                        dereferenceOperator = funcDecl;
66                                                }
67                                        }
68                                }
69                        } else if ( ! dtorStructDestroy && funcDecl->name == "__destroy_Destructor" ) {
70                                dtorStructDestroy = funcDecl;
71                        }
72                }
73
74                void FindSpecialDecls::previsit( StructDecl * structDecl ) {
75                        visit_children = false;
76                        if ( ! dtorStruct && structDecl->name == "__Destructor" ) {
77                                dtorStruct = structDecl;
78                        }
79                }
80
81                void FindSpecialDecls::previsit( UnionDecl * ) {
82                        visit_children = false;
83                }
84
85                void FindSpecialDecls::previsit( EnumDecl * ) {
86                        visit_children = false;
87                }
88
89                void FindSpecialDecls::previsit( TraitDecl * ) {
90                        visit_children = false;
91                }
92
93        } // namespace
94} // namespace Validate
95
96// Local Variables: //
97// tab-width: 4 //
98// mode: c++ //
99// compile-command: "make install" //
100// End: //
Note: See TracBrowser for help on using the repository browser.