source: src/Common/Examine.cpp @ cad8c88

Last change on this file since cad8c88 was c92bdcc, checked in by Andrew Beach <ajbeach@…>, 8 weeks ago

Updated the rest of the names in src/ (except for the generated files).

  • Property mode set to 100644
File size: 1.8 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// Examine.cpp -- Helpers for examining AST code.
8//
9// Author           : Andrew Beach
10// Created On       : Wed Sept 2 14:02 2020
11// Last Modified By : Andrew Beach
12// Last Modified On : Fri Dec 10 10:27 2021
13// Update Count     : 1
14//
15
16#include "Common/Examine.hpp"
17
18#include "AST/Type.hpp"
19#include "CodeGen/OperatorTable.hpp"
20#include "InitTweak/InitTweak.hpp"
21
22namespace {
23
24// getTypeofThis but does some extra checks used in this module.
25const ast::Type * getTypeofThisSolo( const ast::FunctionDecl * func ) {
26        if ( 1 != func->params.size() ) {
27                return nullptr;
28        }
29        auto ref = func->type->params.front().as<ast::ReferenceType>();
30        return (ref) ? ref->base : nullptr;
31}
32
33}
34
35const ast::DeclWithType * isMainFor(
36                const ast::FunctionDecl * func, ast::AggregateDecl::Aggregate kind ) {
37        if ( "main" != func->name ) return nullptr;
38        if ( 1 != func->params.size() ) return nullptr;
39
40        auto param = func->params.front();
41
42        auto type = dynamic_cast<const ast::ReferenceType *>( param->get_type() );
43        if ( !type ) return nullptr;
44
45        auto obj = type->base.as<ast::StructInstType>();
46        if ( !obj ) return nullptr;
47
48        if ( kind != obj->base->kind ) return nullptr;
49
50        return param;
51}
52
53namespace {
54
55const ast::Type * getDestructorParam( const ast::FunctionDecl * func ) {
56        if ( !CodeGen::isDestructor( func->name ) ) return nullptr;
57        return getTypeofThisSolo( func );
58}
59
60}
61
62bool isDestructorFor(
63                const ast::FunctionDecl * func, const ast::StructDecl * type_decl ) {
64        if ( const ast::Type * type = getDestructorParam( func ) ) {
65                auto stype = dynamic_cast<const ast::StructInstType *>( type );
66                return stype && stype->base.get() == type_decl;
67        }
68        return false;
69}
Note: See TracBrowser for help on using the repository browser.