68class SemanticsContext {
80 return languageFeatures_;
83 int GetDefaultKind(TypeCategory)
const;
84 int doublePrecisionKind()
const {
85 return defaultKinds_.doublePrecisionKind();
87 int quadPrecisionKind()
const {
return defaultKinds_.quadPrecisionKind(); }
88 bool IsEnabled(common::LanguageFeature feature)
const {
89 return languageFeatures_.IsEnabled(feature);
91 template <
typename A>
bool ShouldWarn(A x)
const {
92 return languageFeatures_.ShouldWarn(x);
94 const std::optional<parser::CharBlock> &location()
const {
return location_; }
95 const std::vector<std::string> &searchDirectories()
const {
96 return searchDirectories_;
98 const std::vector<std::string> &intrinsicModuleDirectories()
const {
99 return intrinsicModuleDirectories_;
101 const std::string &moduleDirectory()
const {
return moduleDirectory_; }
102 const std::string &moduleFileSuffix()
const {
return moduleFileSuffix_; }
103 bool underscoring()
const {
return underscoring_; }
104 bool warningsAreErrors()
const {
return warningsAreErrors_; }
105 bool debugModuleWriter()
const {
return debugModuleWriter_; }
106 const evaluate::IntrinsicProcTable &intrinsics()
const {
return intrinsics_; }
108 return targetCharacteristics_;
111 return targetCharacteristics_;
113 Scope &globalScope() {
return globalScope_; }
114 Scope &intrinsicModulesScope() {
return intrinsicModulesScope_; }
115 Scope *currentHermeticModuleFileScope() {
116 return currentHermeticModuleFileScope_;
118 void set_currentHermeticModuleFileScope(
Scope *scope) {
119 currentHermeticModuleFileScope_ = scope;
125 std::map<const Symbol *, SourceName> &moduleFileOutputRenamings() {
126 return moduleFileOutputRenamings_;
129 SemanticsContext &set_location(
130 const std::optional<parser::CharBlock> &location) {
131 location_ = location;
134 SemanticsContext &set_searchDirectories(
const std::vector<std::string> &x) {
135 searchDirectories_ = x;
138 SemanticsContext &set_intrinsicModuleDirectories(
139 const std::vector<std::string> &x) {
140 intrinsicModuleDirectories_ = x;
143 SemanticsContext &set_moduleDirectory(
const std::string &x) {
144 moduleDirectory_ = x;
147 SemanticsContext &set_moduleFileSuffix(
const std::string &x) {
148 moduleFileSuffix_ = x;
151 SemanticsContext &set_underscoring(
bool x) {
155 SemanticsContext &set_warnOnNonstandardUsage(
bool x) {
156 warnOnNonstandardUsage_ = x;
159 SemanticsContext &set_maxErrors(
size_t x) {
163 SemanticsContext &set_warningsAreErrors(
bool x) {
164 warningsAreErrors_ = x;
167 SemanticsContext &set_debugModuleWriter(
bool x) {
168 debugModuleWriter_ = x;
172 const DeclTypeSpec &MakeNumericType(TypeCategory,
int kind = 0);
175 std::size_t maxErrors()
const {
return maxErrors_; }
177 bool AnyFatalError()
const;
180 bool HasError(
const Symbol &);
181 bool HasError(
const Symbol *);
183 void SetError(
const Symbol &,
bool =
true);
187 return messages_.Say(*location_, std::forward<A>(args)...);
189 template <
typename... A>
191 return messages_.Say(at, std::forward<A>(args)...);
194 return messages_.Say(std::move(msg));
196 template <
typename... A>
200 auto &message{Say(at, std::move(msg), args...)};
201 evaluate::AttachDeclaration(&message, symbol);
205 template <
typename... A>
208 return messages.Warn(IsInModuleFile(at), languageFeatures_, feature, at,
209 std::forward<A>(args)...);
211 template <
typename... A>
214 return messages.Warn(IsInModuleFile(at), languageFeatures_, warning, at,
215 std::forward<A>(args)...);
217 template <
typename... A>
220 return messages.Warn(IsInModuleFile(at), languageFeatures_, feature, at,
221 std::forward<A>(args)...);
223 template <
typename... A>
226 return messages.Warn(IsInModuleFile(at), languageFeatures_, warning, at,
227 std::forward<A>(args)...);
229 template <
typename... A>
231 common::LanguageFeature feature, A &&...args) {
232 return messages.Warn(IsInModuleFile(messages.at()), languageFeatures_,
233 feature, messages.at(), std::forward<A>(args)...);
235 template <
typename... A>
237 common::UsageWarning warning, A &&...args) {
238 return messages.Warn(IsInModuleFile(messages.at()), languageFeatures_,
239 warning, messages.at(), std::forward<A>(args)...);
241 template <
typename... A>
244 return Warn(messages_, feature, at, std::forward<A>(args)...);
246 template <
typename... A>
249 return Warn(messages_, warning, at, std::forward<A>(args)...);
251 template <
typename... A>
254 return Warn(feature, *location_, std::forward<A>(args)...);
256 template <
typename... A>
259 return Warn(warning, *location_, std::forward<A>(args)...);
262 void EmitMessages(llvm::raw_ostream &);
267 void DumpScopeIndex(llvm::raw_ostream &)
const;
271 const ConstructStack &constructStack()
const {
return constructStack_; }
272 template <
typename N>
void PushConstruct(
const N &node) {
273 constructStack_.emplace_back(&node);
277 ENUM_CLASS(IndexVarKind, DO, FORALL)
284 void ActivateIndexVar(
const parser::Name &, IndexVarKind);
286 SymbolVector GetIndexVars(IndexVarKind);
287 SourceName SaveTempName(std::string &&);
288 SourceName GetTempName(
const Scope &);
289 static bool IsTempName(
const std::string &);
292 Scope *GetBuiltinModule(
const char *name);
295 void UseFortranBuiltinsModule();
296 const Scope *GetBuiltinsScope()
const {
return builtinsScope_; }
300 const Scope *GetCUDABuiltinsScope();
301 const Scope *GetCUDADeviceScope();
303 void UsePPCBuiltinTypesModule();
304 void UsePPCBuiltinsModule();
305 Scope *GetPPCBuiltinTypesScope() {
return ppcBuiltinTypesScope_; }
306 const Scope *GetPPCBuiltinsScope()
const {
return ppcBuiltinsScope_; }
310 parser::Program &SaveParseTree(parser::Program &&);
318 void MapCommonBlockAndCheckConflicts(
const Symbol &);
334 CommonBlockList GetCommonBlocks()
const;
336 void NoteDefinedSymbol(
const Symbol &);
337 bool IsSymbolDefined(
const Symbol &)
const;
338 void NoteUsedSymbol(
const Symbol &);
339 void NoteUsedSymbols(
const UnorderedSymbolSet &);
340 bool IsSymbolUsed(
const Symbol &)
const;
345 accObjectDuplicates_.insert(o);
348 return accObjectDuplicates_.count(o) != 0;
351 void DumpSymbols(llvm::raw_ostream &);
357 struct ScopeIndexComparator {
361 std::multimap<parser::CharBlock, Scope &, ScopeIndexComparator>;
366 void CheckError(
const Symbol &);
372 std::optional<parser::CharBlock> location_;
373 std::vector<std::string> searchDirectories_;
374 std::vector<std::string> intrinsicModuleDirectories_;
375 std::string moduleDirectory_{
"."s};
376 std::string moduleFileSuffix_{
".mod"};
377 bool underscoring_{
true};
378 bool warnOnNonstandardUsage_{
false};
379 bool warningsAreErrors_{
false};
380 bool debugModuleWriter_{
false};
381 const evaluate::IntrinsicProcTable intrinsics_;
384 Scope &intrinsicModulesScope_;
385 Scope *currentHermeticModuleFileScope_{
nullptr};
386 ScopeIndex scopeIndex_;
388 std::size_t maxErrors_{0};
390 ConstructStack constructStack_;
391 struct IndexVarInfo {
395 std::map<SymbolRef, const IndexVarInfo, SymbolAddressCompare>
397 UnorderedSymbolSet errorSymbols_;
398 std::set<std::string> tempNames_;
399 const Scope *builtinsScope_{
nullptr};
400 Scope *ppcBuiltinTypesScope_{
nullptr};
401 std::optional<const Scope *> cudaBuiltinsScope_;
402 std::optional<const Scope *> cudaDeviceScope_;
403 const Scope *ppcBuiltinsScope_{
nullptr};
404 std::list<parser::Program> modFileParseTrees_;
405 std::unique_ptr<CommonBlockMap> commonBlockMap_;
407 std::map<const Symbol *, SourceName> moduleFileOutputRenamings_;
408 UnorderedSymbolSet isDefined_;
409 UnorderedSymbolSet isUsed_;
410 std::set<const parser::AccObject *> accObjectDuplicates_;
411 std::list<ProgramTree> programTrees_;