| 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 | // FindSpecialDecls.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.hpp"
|
|---|
| 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 |
|
|---|
| 27 | namespace Validate {
|
|---|
| 28 |
|
|---|
| 29 | namespace {
|
|---|
| 30 |
|
|---|
| 31 | struct 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 |
|
|---|
| 40 | void FindDeclsCore::previsit( const ast::Decl * ) {
|
|---|
| 41 | visit_children = false;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | void 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 |
|
|---|
| 63 | void 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.
|
|---|
| 73 | void 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: //
|
|---|