71class SemanticsContext {
83 return languageFeatures_;
86 const std::string &openAccDefaultNoneScalarsStrictDisableOption()
const {
87 return openAccDefaultNoneScalarsStrictDisableOption_;
89 int GetDefaultKind(TypeCategory)
const;
90 int doublePrecisionKind()
const {
91 return defaultKinds_.doublePrecisionKind();
93 int quadPrecisionKind()
const {
return defaultKinds_.quadPrecisionKind(); }
94 bool IsEnabled(common::LanguageFeature feature)
const {
95 return languageFeatures_.IsEnabled(feature);
97 template <
typename A>
bool ShouldWarn(A x)
const {
98 return languageFeatures_.ShouldWarn(x);
100 const std::optional<parser::CharBlock> &location()
const {
return location_; }
101 const std::vector<std::string> &searchDirectories()
const {
102 return searchDirectories_;
104 const std::vector<std::string> &intrinsicModuleDirectories()
const {
105 return intrinsicModuleDirectories_;
107 const std::vector<std::string> &implicitUseModules()
const {
108 return implicitUseModules_;
110 const std::string &moduleDirectory()
const {
return moduleDirectory_; }
111 const std::string &moduleFileSuffix()
const {
return moduleFileSuffix_; }
112 bool underscoring()
const {
return underscoring_; }
113 bool warningsAreErrors()
const {
return warningsAreErrors_; }
114 bool debugModuleWriter()
const {
return debugModuleWriter_; }
115 const evaluate::IntrinsicProcTable &intrinsics()
const {
return intrinsics_; }
117 return targetCharacteristics_;
120 return targetCharacteristics_;
122 const std::string &targetTriple()
const {
return targetTriple_; }
123 const std::string &targetFeatures()
const {
return targetFeatures_; }
124 Scope &globalScope() {
return globalScope_; }
125 Scope &intrinsicModulesScope() {
return intrinsicModulesScope_; }
126 Scope *currentHermeticModuleFileScope() {
127 return currentHermeticModuleFileScope_;
129 void set_currentHermeticModuleFileScope(
Scope *scope) {
130 currentHermeticModuleFileScope_ = scope;
136 std::map<const Symbol *, SourceName> &moduleFileOutputRenamings() {
137 return moduleFileOutputRenamings_;
140 SemanticsContext &set_location(
141 const std::optional<parser::CharBlock> &location) {
142 location_ = location;
145 SemanticsContext &set_searchDirectories(
const std::vector<std::string> &x) {
146 searchDirectories_ = x;
149 SemanticsContext &set_intrinsicModuleDirectories(
150 const std::vector<std::string> &x) {
151 intrinsicModuleDirectories_ = x;
154 SemanticsContext &set_implicitUseModules(
const std::vector<std::string> &x) {
155 implicitUseModules_ = x;
158 SemanticsContext &set_moduleDirectory(
const std::string &x) {
159 moduleDirectory_ = x;
162 SemanticsContext &set_moduleFileSuffix(
const std::string &x) {
163 moduleFileSuffix_ = x;
166 SemanticsContext &set_underscoring(
bool x) {
170 SemanticsContext &set_warnOnNonstandardUsage(
bool x) {
171 warnOnNonstandardUsage_ = x;
174 SemanticsContext &set_maxErrors(
size_t x) {
178 SemanticsContext &set_warningsAreErrors(
bool x) {
179 warningsAreErrors_ = x;
182 SemanticsContext &set_debugModuleWriter(
bool x) {
183 debugModuleWriter_ = x;
186 SemanticsContext &set_openAccDefaultNoneScalarsStrictDisableOption(
188 openAccDefaultNoneScalarsStrictDisableOption_ = std::move(x);
191 SemanticsContext &set_targetTriple(
const std::string &x) {
195 SemanticsContext &set_targetFeatures(
const std::string &x) {
200 const DeclTypeSpec &MakeNumericType(TypeCategory,
int kind = 0);
203 std::size_t maxErrors()
const {
return maxErrors_; }
205 bool AnyFatalError()
const;
208 bool HasError(
const Symbol &);
209 bool HasError(
const Symbol *);
211 void SetError(
const Symbol &,
bool =
true);
215 return messages_.Say(*location_, std::forward<A>(args)...);
217 template <
typename... A>
219 return messages_.Say(at, std::forward<A>(args)...);
222 return messages_.Say(std::move(msg));
224 template <
typename... A>
228 auto &message{Say(at, std::move(msg), args...)};
229 evaluate::AttachDeclaration(&message, symbol);
233 template <
typename... A>
236 return messages.Warn(IsInModuleFile(at), languageFeatures_, feature, at,
237 std::forward<A>(args)...);
239 template <
typename... A>
242 return messages.Warn(IsInModuleFile(at), languageFeatures_, warning, at,
243 std::forward<A>(args)...);
245 template <
typename... A>
248 return messages.Warn(IsInModuleFile(at), languageFeatures_, feature, at,
249 std::forward<A>(args)...);
251 template <
typename... A>
254 return messages.Warn(IsInModuleFile(at), languageFeatures_, warning, at,
255 std::forward<A>(args)...);
257 template <
typename... A>
259 common::LanguageFeature feature, A &&...args) {
260 return messages.Warn(IsInModuleFile(messages.at()), languageFeatures_,
261 feature, messages.at(), std::forward<A>(args)...);
263 template <
typename... A>
265 common::UsageWarning warning, A &&...args) {
266 return messages.Warn(IsInModuleFile(messages.at()), languageFeatures_,
267 warning, messages.at(), std::forward<A>(args)...);
269 template <
typename... A>
272 return Warn(messages_, feature, at, std::forward<A>(args)...);
274 template <
typename... A>
277 return Warn(messages_, warning, at, std::forward<A>(args)...);
279 template <
typename... A>
282 return Warn(feature, *location_, std::forward<A>(args)...);
284 template <
typename... A>
287 return Warn(warning, *location_, std::forward<A>(args)...);
290 void EmitMessages(llvm::raw_ostream &);
298 void DumpScopeIndex(llvm::raw_ostream &)
const;
302 const ConstructStack &constructStack()
const {
return constructStack_; }
303 template <
typename N>
void PushConstruct(
const N &node) {
304 constructStack_.emplace_back(&node);
308 ENUM_CLASS(IndexVarKind, DO, FORALL)
315 void ActivateIndexVar(
const parser::Name &, IndexVarKind);
317 SymbolVector GetIndexVars(IndexVarKind);
318 SourceName SaveTempName(std::string &&);
319 SourceName GetTempName(
const Scope &);
320 static bool IsTempName(
const std::string &);
323 Scope *GetBuiltinModule(
const char *name);
326 void UseFortranBuiltinsModule();
327 const Scope *GetBuiltinsScope()
const {
return builtinsScope_; }
331 const Scope *GetCUDABuiltinsScope();
332 const Scope *GetCUDADeviceScope();
334 void UsePPCBuiltinTypesModule();
335 void UsePPCBuiltinsModule();
336 Scope *GetPPCBuiltinTypesScope() {
return ppcBuiltinTypesScope_; }
337 const Scope *GetPPCBuiltinsScope()
const {
return ppcBuiltinsScope_; }
341 parser::Program &SaveParseTree(parser::Program &&);
349 void MapCommonBlockAndCheckConflicts(
const Symbol &);
358 void CheckCommonBlockInitializationConflicts();
374 CommonBlockList GetCommonBlocks()
const;
378 void NoteOpenACCDataMapping() { anyOpenACCDataMapping_ =
true; }
379 bool AnyOpenACCDataMapping()
const {
return anyOpenACCDataMapping_; }
381 void NoteDefinedSymbol(
const Symbol &);
382 bool IsSymbolDefined(
const Symbol &)
const;
383 void NoteUsedSymbol(
const Symbol &);
384 void NoteUsedSymbols(
const UnorderedSymbolSet &);
385 bool IsSymbolUsed(
const Symbol &)
const;
390 accObjectDuplicates_.insert(o);
393 return accObjectDuplicates_.count(o) != 0;
396 void DumpSymbols(llvm::raw_ostream &);
401 const std::list<parser::Program> &GetModFileParseTrees() {
402 return modFileParseTrees_;
411 branchTargets_.insert(statementPosition);
415 return branchTargets_.find(statementPosition) != branchTargets_.end();
421 struct ScopeIndexComparator {
425 std::multimap<parser::CharBlock, Scope &, ScopeIndexComparator>;
430 void CheckError(
const Symbol &);
432 std::set<parser::CharBlock, ScopeIndexComparator> branchTargets_;
437 std::string openAccDefaultNoneScalarsStrictDisableOption_;
438 std::optional<parser::CharBlock> location_;
439 std::vector<std::string> searchDirectories_;
440 std::vector<std::string> intrinsicModuleDirectories_;
441 std::vector<std::string> implicitUseModules_;
442 std::string moduleDirectory_{
"."s};
443 std::string moduleFileSuffix_{
".mod"};
444 std::string targetTriple_;
445 std::string targetFeatures_;
446 bool underscoring_{
true};
447 bool warnOnNonstandardUsage_{
false};
448 bool warningsAreErrors_{
false};
449 bool debugModuleWriter_{
false};
450 const evaluate::IntrinsicProcTable intrinsics_;
453 Scope &intrinsicModulesScope_;
454 Scope *currentHermeticModuleFileScope_{
nullptr};
455 ScopeIndex scopeIndex_;
457 std::size_t maxErrors_{0};
459 ConstructStack constructStack_;
460 struct IndexVarInfo {
464 std::map<SymbolRef, const IndexVarInfo, SymbolAddressCompare>
466 UnorderedSymbolSet errorSymbols_;
467 std::set<std::string> tempNames_;
468 const Scope *builtinsScope_{
nullptr};
469 Scope *ppcBuiltinTypesScope_{
nullptr};
470 std::optional<const Scope *> cudaBuiltinsScope_;
471 std::optional<const Scope *> cudaDeviceScope_;
472 const Scope *ppcBuiltinsScope_{
nullptr};
473 std::list<parser::Program> modFileParseTrees_;
474 std::unique_ptr<CommonBlockMap> commonBlockMap_;
476 std::map<const Symbol *, SourceName> moduleFileOutputRenamings_;
477 UnorderedSymbolSet isDefined_;
478 UnorderedSymbolSet isUsed_;
479 std::set<const parser::AccObject *> accObjectDuplicates_;
480 bool anyOpenACCDataMapping_{
false};
481 std::unique_ptr<omp::SemanticOverrides> ompOverrides_;
482 std::list<ProgramTree> programTrees_;