2019-03-04 10:13:12 -08:00
|
|
|
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef FORTRAN_SEMANTICS_TOOLS_H_
|
|
|
|
#define FORTRAN_SEMANTICS_TOOLS_H_
|
|
|
|
|
|
|
|
// Simple predicates and look-up functions that are best defined
|
|
|
|
// canonically for use in semantic checking.
|
|
|
|
|
2019-04-12 16:30:03 -07:00
|
|
|
#include "../common/Fortran.h"
|
2019-03-04 10:13:12 -08:00
|
|
|
#include "../evaluate/variable.h"
|
2019-04-12 16:30:03 -07:00
|
|
|
|
|
|
|
namespace Fortran::parser {
|
|
|
|
class Messages;
|
|
|
|
struct Expr;
|
|
|
|
struct Name;
|
|
|
|
struct Variable;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Fortran::evaluate {
|
|
|
|
class GenericExprWrapper;
|
|
|
|
}
|
2019-03-04 10:13:12 -08:00
|
|
|
|
|
|
|
namespace Fortran::semantics {
|
|
|
|
|
2019-04-12 16:30:03 -07:00
|
|
|
class DeclTypeSpec;
|
|
|
|
class DerivedTypeSpec;
|
|
|
|
class Scope;
|
|
|
|
class Symbol;
|
|
|
|
|
2019-03-04 10:13:12 -08:00
|
|
|
const Symbol *FindCommonBlockContaining(const Symbol &object);
|
|
|
|
const Scope *FindProgramUnitContaining(const Scope &);
|
|
|
|
const Scope *FindProgramUnitContaining(const Symbol &);
|
|
|
|
const Scope *FindPureFunctionContaining(const Scope *);
|
2019-03-04 16:28:35 -08:00
|
|
|
const Symbol *FindPointerComponent(const Scope &);
|
|
|
|
const Symbol *FindPointerComponent(const DerivedTypeSpec &);
|
|
|
|
const Symbol *FindPointerComponent(const DeclTypeSpec &);
|
|
|
|
const Symbol *FindPointerComponent(const Symbol &);
|
2019-03-04 10:13:12 -08:00
|
|
|
|
|
|
|
bool IsCommonBlockContaining(const Symbol &block, const Symbol &object);
|
2019-03-05 13:11:57 -08:00
|
|
|
bool DoesScopeContain(const Scope *maybeAncestor, const Scope &maybeDescendent);
|
|
|
|
bool DoesScopeContain(const Scope *, const Symbol &);
|
2019-03-04 10:13:12 -08:00
|
|
|
bool IsUseAssociated(const Symbol *, const Scope &);
|
|
|
|
bool IsHostAssociated(const Symbol &, const Scope &);
|
|
|
|
bool IsDummy(const Symbol &);
|
2019-04-07 11:29:48 -07:00
|
|
|
bool IsPointer(const Symbol &);
|
2019-03-04 10:13:12 -08:00
|
|
|
bool IsPointerDummy(const Symbol &);
|
|
|
|
bool IsFunction(const Symbol &);
|
|
|
|
bool IsPureFunction(const Symbol &);
|
|
|
|
bool IsPureFunction(const Scope &);
|
2019-04-07 11:29:48 -07:00
|
|
|
bool IsProcName(const Symbol &symbol); // proc-name
|
|
|
|
bool IsVariableName(const Symbol &symbol); // variable-name
|
2019-04-10 22:17:44 -07:00
|
|
|
bool IsAllocatable(const Symbol &);
|
|
|
|
bool IsAllocatableOrPointer(const Symbol &);
|
2019-03-04 10:13:12 -08:00
|
|
|
|
|
|
|
// Determines whether an object might be visible outside a
|
2019-03-04 16:28:35 -08:00
|
|
|
// PURE function (C1594); returns a non-null Symbol pointer for
|
|
|
|
// diagnostic purposes if so.
|
|
|
|
const Symbol *FindExternallyVisibleObject(const Symbol &, const Scope &);
|
2019-03-04 10:13:12 -08:00
|
|
|
|
2019-03-04 16:28:35 -08:00
|
|
|
template<typename A>
|
|
|
|
const Symbol *FindExternallyVisibleObject(const A &, const Scope &) {
|
|
|
|
return nullptr; // default base case
|
2019-03-04 10:13:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2019-03-04 16:28:35 -08:00
|
|
|
const Symbol *FindExternallyVisibleObject(
|
2019-03-04 10:13:12 -08:00
|
|
|
const evaluate::Designator<T> &designator, const Scope &scope) {
|
|
|
|
if (const Symbol * symbol{designator.GetBaseObject().symbol()}) {
|
2019-03-04 16:28:35 -08:00
|
|
|
return FindExternallyVisibleObject(*symbol, scope);
|
|
|
|
} else if (std::holds_alternative<evaluate::CoarrayRef>(designator.u)) {
|
2019-03-04 10:13:12 -08:00
|
|
|
// Coindexed values are visible even if their image-local objects are not.
|
2019-03-04 16:28:35 -08:00
|
|
|
return designator.GetBaseObject().symbol();
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
2019-03-04 10:13:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2019-03-04 16:28:35 -08:00
|
|
|
const Symbol *FindExternallyVisibleObject(
|
2019-03-04 10:13:12 -08:00
|
|
|
const evaluate::Expr<T> &expr, const Scope &scope) {
|
|
|
|
return std::visit(
|
2019-03-04 16:28:35 -08:00
|
|
|
[&](const auto &x) { return FindExternallyVisibleObject(x, scope); },
|
2019-03-04 10:13:12 -08:00
|
|
|
expr.u);
|
|
|
|
}
|
2019-03-26 00:33:03 -07:00
|
|
|
|
|
|
|
bool ExprHasTypeCategory(
|
|
|
|
const evaluate::GenericExprWrapper &expr, const common::TypeCategory &type);
|
2019-04-12 16:30:03 -07:00
|
|
|
|
|
|
|
// If this Expr or Variable represents a simple Name, return it.
|
|
|
|
parser::Name *GetSimpleName(parser::Expr &);
|
|
|
|
const parser::Name *GetSimpleName(const parser::Expr &);
|
|
|
|
parser::Name *GetSimpleName(parser::Variable &);
|
|
|
|
const parser::Name *GetSimpleName(const parser::Variable &);
|
2019-03-04 10:13:12 -08:00
|
|
|
}
|
|
|
|
#endif // FORTRAN_SEMANTICS_TOOLS_H_
|