67class SemanticsContext {
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_;
127 SemanticsContext &set_location(
128 const std::optional<parser::CharBlock> &location) {
129 location_ = location;
132 SemanticsContext &set_searchDirectories(
const std::vector<std::string> &x) {
133 searchDirectories_ = x;
136 SemanticsContext &set_intrinsicModuleDirectories(
137 const std::vector<std::string> &x) {
138 intrinsicModuleDirectories_ = x;
141 SemanticsContext &set_moduleDirectory(
const std::string &x) {
142 moduleDirectory_ = x;
145 SemanticsContext &set_moduleFileSuffix(
const std::string &x) {
146 moduleFileSuffix_ = x;
149 SemanticsContext &set_underscoring(
bool x) {
153 SemanticsContext &set_warnOnNonstandardUsage(
bool x) {
154 warnOnNonstandardUsage_ = x;
157 SemanticsContext &set_maxErrors(
size_t x) {
161 SemanticsContext &set_warningsAreErrors(
bool x) {
162 warningsAreErrors_ = x;
165 SemanticsContext &set_debugModuleWriter(
bool x) {
166 debugModuleWriter_ = x;
170 const DeclTypeSpec &MakeNumericType(TypeCategory,
int kind = 0);
173 std::size_t maxErrors()
const {
return maxErrors_; }
175 bool AnyFatalError()
const;
178 bool HasError(
const Symbol &);
179 bool HasError(
const Symbol *);
181 void SetError(
const Symbol &,
bool =
true);
185 return messages_.Say(*location_, std::forward<A>(args)...);
187 template <
typename... A>
189 return messages_.Say(at, std::forward<A>(args)...);
192 return messages_.Say(std::move(msg));
194 template <
typename... A>
198 auto &message{Say(at, std::move(msg), args...)};
199 evaluate::AttachDeclaration(&message, symbol);
203 template <
typename... A>
206 return messages.Warn(IsInModuleFile(at), languageFeatures_, feature, at,
207 std::forward<A>(args)...);
209 template <
typename... A>
212 return messages.Warn(IsInModuleFile(at), languageFeatures_, warning, at,
213 std::forward<A>(args)...);
215 template <
typename... A>
218 return messages.Warn(IsInModuleFile(at), languageFeatures_, feature, at,
219 std::forward<A>(args)...);
221 template <
typename... A>
224 return messages.Warn(IsInModuleFile(at), languageFeatures_, warning, at,
225 std::forward<A>(args)...);
227 template <
typename... A>
229 common::LanguageFeature feature, A &&...args) {
230 return messages.Warn(IsInModuleFile(messages.at()), languageFeatures_,
231 feature, messages.at(), std::forward<A>(args)...);
233 template <
typename... A>
235 common::UsageWarning warning, A &&...args) {
236 return messages.Warn(IsInModuleFile(messages.at()), languageFeatures_,
237 warning, messages.at(), std::forward<A>(args)...);
239 template <
typename... A>
242 return Warn(messages_, feature, at, std::forward<A>(args)...);
244 template <
typename... A>
247 return Warn(messages_, warning, at, std::forward<A>(args)...);
249 template <
typename... A>
252 return Warn(feature, *location_, std::forward<A>(args)...);
254 template <
typename... A>
257 return Warn(warning, *location_, std::forward<A>(args)...);
260 void EmitMessages(llvm::raw_ostream &);
268 const ConstructStack &constructStack()
const {
return constructStack_; }
269 template <
typename N>
void PushConstruct(
const N &node) {
270 constructStack_.emplace_back(&node);
274 ENUM_CLASS(IndexVarKind, DO, FORALL)
281 void ActivateIndexVar(
const parser::Name &, IndexVarKind);
283 SymbolVector GetIndexVars(IndexVarKind);
284 SourceName SaveTempName(std::string &&);
285 SourceName GetTempName(
const Scope &);
286 static bool IsTempName(
const std::string &);
289 Scope *GetBuiltinModule(
const char *name);
292 void UseFortranBuiltinsModule();
293 const Scope *GetBuiltinsScope()
const {
return builtinsScope_; }
295 const Scope &GetCUDABuiltinsScope();
296 const Scope &GetCUDADeviceScope();
298 void UsePPCBuiltinTypesModule();
299 void UsePPCBuiltinsModule();
300 Scope *GetPPCBuiltinTypesScope() {
return ppcBuiltinTypesScope_; }
301 const Scope *GetPPCBuiltinsScope()
const {
return ppcBuiltinsScope_; }
305 parser::Program &SaveParseTree(parser::Program &&);
313 void MapCommonBlockAndCheckConflicts(
const Symbol &);
329 CommonBlockList GetCommonBlocks()
const;
331 void NoteDefinedSymbol(
const Symbol &);
332 bool IsSymbolDefined(
const Symbol &)
const;
334 void DumpSymbols(llvm::raw_ostream &);
340 struct ScopeIndexComparator {
344 std::multimap<parser::CharBlock, Scope &, ScopeIndexComparator>;
349 void CheckError(
const Symbol &);
355 std::optional<parser::CharBlock> location_;
356 std::vector<std::string> searchDirectories_;
357 std::vector<std::string> intrinsicModuleDirectories_;
358 std::string moduleDirectory_{
"."s};
359 std::string moduleFileSuffix_{
".mod"};
360 bool underscoring_{
true};
361 bool warnOnNonstandardUsage_{
false};
362 bool warningsAreErrors_{
false};
363 bool debugModuleWriter_{
false};
364 const evaluate::IntrinsicProcTable intrinsics_;
367 Scope &intrinsicModulesScope_;
368 Scope *currentHermeticModuleFileScope_{
nullptr};
369 ScopeIndex scopeIndex_;
371 std::size_t maxErrors_{0};
373 ConstructStack constructStack_;
374 struct IndexVarInfo {
378 std::map<SymbolRef, const IndexVarInfo, SymbolAddressCompare>
380 UnorderedSymbolSet errorSymbols_;
381 std::set<std::string> tempNames_;
382 const Scope *builtinsScope_{
nullptr};
383 Scope *ppcBuiltinTypesScope_{
nullptr};
384 std::optional<const Scope *> cudaBuiltinsScope_;
385 std::optional<const Scope *> cudaDeviceScope_;
386 const Scope *ppcBuiltinsScope_{
nullptr};
387 std::list<parser::Program> modFileParseTrees_;
388 std::unique_ptr<CommonBlockMap> commonBlockMap_;
390 std::map<const Symbol *, SourceName> moduleFileOutputRenamings_;
391 UnorderedSymbolSet isDefined_;
392 std::list<ProgramTree> programTrees_;