source: src/Common/Examine.cc@ f1149ac

Last change on this file since f1149ac was c6b4432, checked in by Andrew Beach <ajbeach@…>, 23 months ago

Remove BaseSyntaxNode and clean-up.

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[1c01c58]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//
[4f6dda0]7// Examine.cc -- Helpers for examining AST code.
[1c01c58]8//
9// Author : Andrew Beach
10// Created On : Wed Sept 2 14:02 2020
11// Last Modified By : Andrew Beach
[4f6dda0]12// Last Modified On : Fri Dec 10 10:27 2021
13// Update Count : 1
[1c01c58]14//
15
16#include "Common/Examine.h"
17
[4f6dda0]18#include "AST/Type.hpp"
[1c01c58]19#include "CodeGen/OperatorTable.h"
[4f6dda0]20#include "InitTweak/InitTweak.h"
[1c01c58]21
[4f6dda0]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
[1c01c58]53namespace {
[4f6dda0]54
55const ast::Type * getDestructorParam( const ast::FunctionDecl * func ) {
56 if ( !CodeGen::isDestructor( func->name ) ) return nullptr;
57 //return InitTweak::getParamThis( func )->type;
58 return getTypeofThisSolo( func );
59}
60
[1c01c58]61}
62
[4f6dda0]63bool isDestructorFor(
64 const ast::FunctionDecl * func, const ast::StructDecl * type_decl ) {
65 if ( const ast::Type * type = getDestructorParam( func ) ) {
66 auto stype = dynamic_cast<const ast::StructInstType *>( type );
67 return stype && stype->base.get() == type_decl;
68 }
69 return false;
70}
Note: See TracBrowser for help on using the repository browser.