source: src/Validate/FindSpecialDeclsNew.cpp @ c8238c0

ADTast-experimental
Last change on this file since c8238c0 was 39d8950, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Thread global information through resolution. Non-top-level calls to the resolver have a bit of a hack but improvements would require changes to the Pass helpers.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 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// FindSpecialDeclsNew.cpp -- Find special declarations used in the compiler.
8//
9// Author           : Andrew Beach
10// Created On       : Wed Nov 10 13:51:00 2021
11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Nov 10 15:22:00 2021
13// Update Count     : 0
14//
15
16#include "Validate/FindSpecialDecls.h"
17
18#include "AST/Decl.hpp"
19#include "AST/Pass.hpp"
20#include "AST/TranslationUnit.hpp"
21
22// NOTE: currently, it is assumed that every special declaration occurs at the
23// top-level, so function bodies, aggregate bodies, object initializers, etc.
24// are not visited. If this assumption changes, e.g., with the introduction
25// of namespaces, remove the visit_children assignments.
26
27namespace Validate {
28
29namespace {
30
31struct FindDeclsCore : public ast::WithShortCircuiting {
32        ast::TranslationGlobal & global;
33        FindDeclsCore( ast::TranslationGlobal & g ) : global( g ) {}
34
35        void previsit( const ast::Decl * decl );
36        void previsit( const ast::FunctionDecl * decl );
37        void previsit( const ast::StructDecl * decl );
38};
39
40void FindDeclsCore::previsit( const ast::Decl * ) {
41        visit_children = false;
42}
43
44void FindDeclsCore::previsit( const ast::FunctionDecl * decl ) {
45        visit_children = false;
46        if ( !global.dereference && decl->name == "*?" ) {
47                const ast::FunctionType * type = decl->type.get();
48                if ( decl->linkage == ast::Linkage::Intrinsic && type->params.size() == 1 ) {
49                        const ast::PointerType * ptrType = type->params.front().strict_as<ast::PointerType>();
50                        ast::ptr<ast::Type> baseType = ptrType->base;
51                        if ( baseType->qualifiers == ast::CV::Qualifiers() ) {
52                                const ast::TypeInstType * inst = baseType.as<ast::TypeInstType>();
53                                if ( inst || inst->kind != ast::TypeDecl::Ftype ) {
54                                        global.dereference = decl;
55                                }
56                        }
57                }
58        } else if ( !global.dtorDestroy && decl->name == "__destroy_Destructor" ) {
59                global.dtorDestroy = decl;
60        }
61}
62
63void FindDeclsCore::previsit( const ast::StructDecl * decl ) {
64        visit_children = false;
65        if ( !global.dtorStruct && decl->name == "__Destructor" ) {
66                global.dtorStruct = decl;
67        }
68}
69
70} // namespace
71
72// Fill the TranslationUnit's dereference, dtorStruct and dtorDestroy fields.
73void findGlobalDecls( ast::TranslationUnit & translationUnit ) {
74        ast::Pass<FindDeclsCore>::run( translationUnit, translationUnit.global );
75
76        // TODO: conditionally generate 'fake' declarations for missing features,
77        // so that translation can proceed in the event that builtins, prelude,
78        // etc. are missing.
79}
80
81} // namespace Validate
82
83// Local Variables: //
84// tab-width: 4 //
85// mode: c++ //
86// compile-command: "make install" //
87// End: //
Note: See TracBrowser for help on using the repository browser.