Skip to content

Commit d73ec66

Browse files
committed
Allow pragmas to customize throwing mode for try/catch
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
1 parent 2943116 commit d73ec66

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

frontend/include/chpl/parsing/parsing-queries.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,12 @@ const uast::AstNode* parentAst(Context* context, const uast::AstNode* node);
596596
*/
597597
ID idToParentModule(Context* context, ID id);
598598

599+
/**
600+
Return the ID for the module containing the given ID,
601+
unless the ID itself is a module, in which case return the ID itself.
602+
*/
603+
ID idToModule(Context* context, ID id);
604+
599605
/**
600606
Given an ID 'id', attempt to lookup the declared linkage of the composite
601607
type associated with 'id'. Returns 'DEFAULT_LINKAGE' if no such AST was

frontend/lib/parsing/parsing-queries.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,10 @@ ID idToParentModule(Context* context, ID id) {
15971597
return getModuleForId(context, parentSymId);
15981598
}
15991599

1600+
ID idToModule(Context* context, ID id) {
1601+
return getModuleForId(context, id);
1602+
}
1603+
16001604
bool idIsToplevelModule(Context* context, ID id) {
16011605
if (idIsModule(context, id)) {
16021606
ID parentSymId = id.parentSymbolId(context);

frontend/lib/resolution/try-catch-analysis.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,20 @@ namespace resolution {
409409
// PERMIT_UNHANDLED_MODULE_ERRORS compiler flag to determine the handling mode
410410
static ErrorCheckingMode computeErrorCheckingMode(Context* context,
411411
const AstNode* node) {
412+
// pragmas on modules override the default error checking mode.
413+
auto moduleId = parsing::idToModule(context, node->id());
414+
auto ag = parsing::idToAttributeGroup(context, moduleId);
415+
if (!ag) {
416+
// fall through to figuring out the mode from the module kind
417+
} else if (ag->hasPragma(pragmatags::PRAGMA_ERROR_MODE_FATAL)) {
418+
return ErrorCheckingMode::FATAL;
419+
} else if (ag->hasPragma(pragmatags::PRAGMA_ERROR_MODE_STRICT)) {
420+
CHPL_UNIMPL("strict error checking mode not implemented");
421+
return ErrorCheckingMode::RELAXED;
422+
} else if (ag->hasPragma(pragmatags::PRAGMA_ERROR_MODE_RELAXED)) {
423+
return ErrorCheckingMode::RELAXED;
424+
}
425+
412426
auto mode = ErrorCheckingMode::UNKNOWN;
413427
auto moduleKind = parsing::idToModuleKind(context, node->id());
414428
if (moduleKind == Module::Kind::PROTOTYPE ||

0 commit comments

Comments
 (0)