source: src/Common/Examine.cc @ 0336e83

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 0336e83 was 1c01c58, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Rather large commit to get coroutine cancellation working.

This includes what you would expect, like new code in exceptions and a new
test, but it also includes a bunch of other things.

New coroutine state, currently just marks that the stack was cancelled. New
helpers for checking code structure and generating vtables. Changes to the
coroutine interface so resume may throw exceptions on cancellation, plus the
exception type that is thrown. Changes to the coroutine keyword generation to
generate exception code for each type of coroutine.

  • Property mode set to 100644
File size: 1.5 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.h --
8//
9// Author           : Andrew Beach
10// Created On       : Wed Sept 2 14:02 2020
11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Sep  8 12:15 2020
13// Update Count     : 0
14//
15
16#include "Common/Examine.h"
17
18#include "CodeGen/OperatorTable.h"
19
20DeclarationWithType * isMainFor( FunctionDecl * func, AggregateDecl::Aggregate kind ) {
21        if (func->name != "main") return nullptr;
22        if (func->type->parameters.size() != 1) return nullptr;
23
24        auto param = func->type->parameters.front();
25
26        auto type = dynamic_cast<ReferenceType * >(param->get_type());
27        if (!type) return nullptr;
28
29        auto obj = dynamic_cast<StructInstType *>(type->base);
30        if (!obj) return nullptr;
31
32        if (kind != obj->baseStruct->kind) return nullptr;
33
34        return param;
35}
36
37namespace {
38        Type * getDestructorParam( FunctionDecl * func ) {
39                if ( !CodeGen::isDestructor( func->name ) ) return nullptr;
40
41                auto params = func->type->parameters;
42                if ( 1 != params.size() ) return nullptr;
43
44                auto ref = dynamic_cast<ReferenceType *>( params.front()->get_type() );
45                if ( ref ) {
46                        return ref->base;
47                }
48                return nullptr;
49        }
50}
51
52bool isDestructorFor( FunctionDecl * func, StructDecl * type_decl ) {
53        if ( Type * type = getDestructorParam( func ) ) {
54                auto stype = dynamic_cast<StructInstType *>( type );
55                return stype && stype->baseStruct == type_decl;
56        }
57        return false;
58}
Note: See TracBrowser for help on using the repository browser.