9#ifndef FORTRAN_SEMANTICS_SEMANTICS_H_
10#define FORTRAN_SEMANTICS_SEMANTICS_H_
12#include "module-dependences.h"
13#include "program-tree.h"
16#include "flang/Common/Fortran-features.h"
17#include "flang/Common/LangOptions.h"
18#include "flang/Evaluate/common.h"
19#include "flang/Evaluate/intrinsics.h"
20#include "flang/Evaluate/target.h"
21#include "flang/Parser/message.h"
32class IntrinsicTypeDefaultKinds;
38class AllCookedSources;
39struct AssociateConstruct;
43struct ChangeTeamConstruct;
44struct CriticalConstruct;
45struct ForallConstruct;
47struct SelectRankConstruct;
48struct SelectTypeConstruct;
53namespace Fortran::semantics {
57using CommonBlockList = std::vector<std::pair<SymbolRef, std::size_t>>;
59using ConstructNode = std::variant<
const parser::AssociateConstruct *,
60 const parser::BlockConstruct *,
const parser::CaseConstruct *,
61 const parser::ChangeTeamConstruct *,
const parser::CriticalConstruct *,
62 const parser::DoConstruct *,
const parser::ForallConstruct *,
63 const parser::IfConstruct *,
const parser::SelectRankConstruct *,
64 const parser::SelectTypeConstruct *,
const parser::WhereConstruct *>;
65using ConstructStack = std::vector<ConstructNode>;
78 return languageFeatures_;
81 int GetDefaultKind(TypeCategory)
const;
82 int doublePrecisionKind()
const {
83 return defaultKinds_.doublePrecisionKind();
85 int quadPrecisionKind()
const {
return defaultKinds_.quadPrecisionKind(); }
86 bool IsEnabled(common::LanguageFeature feature)
const {
87 return languageFeatures_.IsEnabled(feature);
89 template <
typename A>
bool ShouldWarn(A x)
const {
90 return languageFeatures_.ShouldWarn(x);
92 const std::optional<parser::CharBlock> &location()
const {
return location_; }
93 const std::vector<std::string> &searchDirectories()
const {
94 return searchDirectories_;
96 const std::vector<std::string> &intrinsicModuleDirectories()
const {
97 return intrinsicModuleDirectories_;
99 const std::string &moduleDirectory()
const {
return moduleDirectory_; }
100 const std::string &moduleFileSuffix()
const {
return moduleFileSuffix_; }
101 bool underscoring()
const {
return underscoring_; }
102 bool warningsAreErrors()
const {
return warningsAreErrors_; }
103 bool debugModuleWriter()
const {
return debugModuleWriter_; }
104 const evaluate::IntrinsicProcTable &intrinsics()
const {
return intrinsics_; }
106 return targetCharacteristics_;
109 return targetCharacteristics_;
111 Scope &globalScope() {
return globalScope_; }
112 Scope &intrinsicModulesScope() {
return intrinsicModulesScope_; }
113 Scope *currentHermeticModuleFileScope() {
114 return currentHermeticModuleFileScope_;
116 void set_currentHermeticModuleFileScope(
Scope *scope) {
117 currentHermeticModuleFileScope_ = scope;
123 std::map<const Symbol *, SourceName> &moduleFileOutputRenamings() {
124 return moduleFileOutputRenamings_;
128 const std::optional<parser::CharBlock> &location) {
129 location_ = location;
132 SemanticsContext &set_searchDirectories(
const std::vector<std::string> &x) {
133 searchDirectories_ = x;
137 const std::vector<std::string> &x) {
138 intrinsicModuleDirectories_ = x;
142 moduleDirectory_ = x;
146 moduleFileSuffix_ = x;
154 warnOnNonstandardUsage_ = x;
158 warningsAreErrors_ = x;
163 debugModuleWriter_ = x;
167 const DeclTypeSpec &MakeNumericType(TypeCategory,
int kind = 0);
170 bool AnyFatalError()
const;
173 bool HasError(
const Symbol &);
174 bool HasError(
const Symbol *);
176 void SetError(
const Symbol &,
bool =
true);
180 return messages_.Say(*location_, std::forward<A>(args)...);
182 template <
typename... A>
184 return messages_.Say(at, std::forward<A>(args)...);
187 return messages_.Say(std::move(msg));
189 template <
typename... A>
193 auto &message{Say(at, std::move(msg), args...)};
194 evaluate::AttachDeclaration(&message, symbol);
198 template <
typename FeatureOrUsageWarning,
typename... A>
201 if (languageFeatures_.ShouldWarn(warning) && !IsInModuleFile(at)) {
203 messages_.Say(warning, at, std::forward<A>(args)...)};
210 template <
typename FeatureOrUsageWarning,
typename... A>
213 return Warn(warning, *location_, std::forward<A>(args)...);
222 const ConstructStack &constructStack()
const {
return constructStack_; }
223 template <
typename N>
void PushConstruct(
const N &node) {
224 constructStack_.emplace_back(&node);
228 ENUM_CLASS(IndexVarKind, DO, FORALL)
235 void ActivateIndexVar(
const parser::Name &, IndexVarKind);
237 SymbolVector GetIndexVars(IndexVarKind);
240 static bool IsTempName(
const std::string &);
243 Scope *GetBuiltinModule(
const char *name);
246 void UseFortranBuiltinsModule();
247 const Scope *GetBuiltinsScope()
const {
return builtinsScope_; }
249 const Scope &GetCUDABuiltinsScope();
250 const Scope &GetCUDADeviceScope();
252 void UsePPCBuiltinTypesModule();
253 void UsePPCBuiltinsModule();
254 Scope *GetPPCBuiltinTypesScope() {
return ppcBuiltinTypesScope_; }
255 const Scope *GetPPCBuiltinsScope()
const {
return ppcBuiltinsScope_; }
259 parser::Program &SaveParseTree(parser::Program &&);
267 void MapCommonBlockAndCheckConflicts(
const Symbol &);
283 CommonBlockList GetCommonBlocks()
const;
285 void NoteDefinedSymbol(
const Symbol &);
286 bool IsSymbolDefined(
const Symbol &)
const;
288 void DumpSymbols(llvm::raw_ostream &);
294 struct ScopeIndexComparator {
298 std::multimap<parser::CharBlock, Scope &, ScopeIndexComparator>;
303 void CheckError(
const Symbol &);
309 std::optional<parser::CharBlock> location_;
310 std::vector<std::string> searchDirectories_;
311 std::vector<std::string> intrinsicModuleDirectories_;
312 std::string moduleDirectory_{
"."s};
313 std::string moduleFileSuffix_{
".mod"};
314 bool underscoring_{
true};
315 bool warnOnNonstandardUsage_{
false};
316 bool warningsAreErrors_{
false};
317 bool debugModuleWriter_{
false};
318 const evaluate::IntrinsicProcTable intrinsics_;
321 Scope &intrinsicModulesScope_;
322 Scope *currentHermeticModuleFileScope_{
nullptr};
323 ScopeIndex scopeIndex_;
326 ConstructStack constructStack_;
327 struct IndexVarInfo {
331 std::map<SymbolRef, const IndexVarInfo, SymbolAddressCompare>
333 UnorderedSymbolSet errorSymbols_;
334 std::set<std::string> tempNames_;
335 const Scope *builtinsScope_{
nullptr};
336 Scope *ppcBuiltinTypesScope_{
nullptr};
337 std::optional<const Scope *> cudaBuiltinsScope_;
338 std::optional<const Scope *> cudaDeviceScope_;
339 const Scope *ppcBuiltinsScope_{
nullptr};
340 std::list<parser::Program> modFileParseTrees_;
341 std::unique_ptr<CommonBlockMap> commonBlockMap_;
343 std::map<const Symbol *, SourceName> moduleFileOutputRenamings_;
344 UnorderedSymbolSet isDefined_;
345 std::list<ProgramTree> programTrees_;
351 : context_{context}, program_{program} {}
352 Semantics &set_hermeticModuleFileOutput(
bool yes =
true) {
353 hermeticModuleFileOutput_ = yes;
360 return context_.FindScope(where);
362 bool AnyFatalError()
const {
return context_.AnyFatalError(); }
363 void EmitMessages(llvm::raw_ostream &);
364 void DumpSymbols(llvm::raw_ostream &);
365 void DumpSymbolsSources(llvm::raw_ostream &)
const;
369 parser::Program &program_;
370 bool hermeticModuleFileOutput_{
false};
375 template <
typename N>
void Enter(
const N &) {}
376 template <
typename N>
void Leave(
const N &) {}
Definition: default-kinds.h:26
Definition: LangOptions.h:58
Definition: Fortran-features.h:85
Definition: provenance.h:281
Definition: char-block.h:28
Definition: message.h:188
Definition: message.h:319
Definition: module-dependences.h:21
Definition: program-tree.h:31
Definition: semantics.h:67
Definition: semantics.h:348
Definition: bit-population-count.h:20
Definition: check-expression.h:19
Definition: parse-tree.h:580
Definition: parse-tree.h:1865
Definition: semantics.h:374