source: src/Validate/FindSpecialDeclsNew.cpp @ 12c1eef

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 12c1eef was ce36b55, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Translation of Validate F; and some improvements in some helpers.

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[ce36b55]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::TranslationUnit::Global & global;
33        FindDeclsCore( ast::TranslationUnit::Global & 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: When everything gets the globals from the translation unit,
77        // remove these.
78        ast::dereferenceOperator = translationUnit.global.dereference;
79        ast::dtorStruct = translationUnit.global.dtorStruct;
80        ast::dtorStructDestroy = translationUnit.global.dtorDestroy;
81
82        // TODO: conditionally generate 'fake' declarations for missing features,
83        // so that translation can proceed in the event that builtins, prelude,
84        // etc. are missing.
85}
86
87} // namespace Validate
88
89// Local Variables: //
90// tab-width: 4 //
91// mode: c++ //
92// compile-command: "make install" //
93// End: //
Note: See TracBrowser for help on using the repository browser.