67class SemanticsContext {
79 return languageFeatures_;
82 int GetDefaultKind(TypeCategory)
const;
83 int doublePrecisionKind()
const {
84 return defaultKinds_.doublePrecisionKind();
86 int quadPrecisionKind()
const {
return defaultKinds_.quadPrecisionKind(); }
87 bool IsEnabled(common::LanguageFeature feature)
const {
88 return languageFeatures_.IsEnabled(feature);
90 template <
typename A>
bool ShouldWarn(A x)
const {
91 return languageFeatures_.ShouldWarn(x);
93 const std::optional<parser::CharBlock> &location()
const {
return location_; }
94 const std::vector<std::string> &searchDirectories()
const {
95 return searchDirectories_;
97 const std::vector<std::string> &intrinsicModuleDirectories()
const {
98 return intrinsicModuleDirectories_;
100 const std::string &moduleDirectory()
const {
return moduleDirectory_; }
101 const std::string &moduleFileSuffix()
const {
return moduleFileSuffix_; }
102 bool underscoring()
const {
return underscoring_; }
103 bool warningsAreErrors()
const {
return warningsAreErrors_; }
104 bool debugModuleWriter()
const {
return debugModuleWriter_; }
105 const evaluate::IntrinsicProcTable &intrinsics()
const {
return intrinsics_; }
107 return targetCharacteristics_;
110 return targetCharacteristics_;
112 Scope &globalScope() {
return globalScope_; }
113 Scope &intrinsicModulesScope() {
return intrinsicModulesScope_; }
114 Scope *currentHermeticModuleFileScope() {
115 return currentHermeticModuleFileScope_;
117 void set_currentHermeticModuleFileScope(
Scope *scope) {
118 currentHermeticModuleFileScope_ = scope;
124 std::map<const Symbol *, SourceName> &moduleFileOutputRenamings() {
125 return moduleFileOutputRenamings_;
128 SemanticsContext &set_location(
129 const std::optional<parser::CharBlock> &location) {
130 location_ = location;
133 SemanticsContext &set_searchDirectories(
const std::vector<std::string> &x) {
134 searchDirectories_ = x;
137 SemanticsContext &set_intrinsicModuleDirectories(
138 const std::vector<std::string> &x) {
139 intrinsicModuleDirectories_ = x;
142 SemanticsContext &set_moduleDirectory(
const std::string &x) {
143 moduleDirectory_ = x;
146 SemanticsContext &set_moduleFileSuffix(
const std::string &x) {
147 moduleFileSuffix_ = x;
150 SemanticsContext &set_underscoring(
bool x) {
154 SemanticsContext &set_warnOnNonstandardUsage(
bool x) {
155 warnOnNonstandardUsage_ = x;
158 SemanticsContext &set_maxErrors(
size_t x) {
162 SemanticsContext &set_warningsAreErrors(
bool x) {
163 warningsAreErrors_ = x;
166 SemanticsContext &set_debugModuleWriter(
bool x) {
167 debugModuleWriter_ = x;
171 const DeclTypeSpec &MakeNumericType(TypeCategory,
int kind = 0);
174 std::size_t maxErrors()
const {
return maxErrors_; }
176 bool AnyFatalError()
const;
179 bool HasError(
const Symbol &);
180 bool HasError(
const Symbol *);
182 void SetError(
const Symbol &,
bool =
true);
186 return messages_.Say(*location_, std::forward<A>(args)...);
188 template <
typename... A>
190 return messages_.Say(at, std::forward<A>(args)...);
193 return messages_.Say(std::move(msg));
195 template <
typename... A>
199 auto &message{Say(at, std::move(msg), args...)};
200 evaluate::AttachDeclaration(&message, symbol);
204 template <
typename... A>
207 return messages.Warn(IsInModuleFile(at), languageFeatures_, feature, at,
208 std::forward<A>(args)...);
210 template <
typename... A>
213 return messages.Warn(IsInModuleFile(at), languageFeatures_, warning, at,
214 std::forward<A>(args)...);
216 template <
typename... A>
219 return messages.Warn(IsInModuleFile(at), languageFeatures_, feature, at,
220 std::forward<A>(args)...);
222 template <
typename... A>
225 return messages.Warn(IsInModuleFile(at), languageFeatures_, warning, at,
226 std::forward<A>(args)...);
228 template <
typename... A>
230 common::LanguageFeature feature, A &&...args) {
231 return messages.Warn(IsInModuleFile(messages.at()), languageFeatures_,
232 feature, messages.at(), std::forward<A>(args)...);
234 template <
typename... A>
236 common::UsageWarning warning, A &&...args) {
237 return messages.Warn(IsInModuleFile(messages.at()), languageFeatures_,
238 warning, messages.at(), std::forward<A>(args)...);
240 template <
typename... A>
243 return Warn(messages_, feature, at, std::forward<A>(args)...);
245 template <
typename... A>
248 return Warn(messages_, warning, at, std::forward<A>(args)...);
250 template <
typename... A>
253 return Warn(feature, *location_, std::forward<A>(args)...);
255 template <
typename... A>
258 return Warn(warning, *location_, std::forward<A>(args)...);
261 void EmitMessages(llvm::raw_ostream &);
266 void DumpScopeIndex(llvm::raw_ostream &)
const;
270 const ConstructStack &constructStack()
const {
return constructStack_; }
271 template <
typename N>
void PushConstruct(
const N &node) {
272 constructStack_.emplace_back(&node);
276 ENUM_CLASS(IndexVarKind, DO, FORALL)
283 void ActivateIndexVar(
const parser::Name &, IndexVarKind);
285 SymbolVector GetIndexVars(IndexVarKind);
286 SourceName SaveTempName(std::string &&);
287 SourceName GetTempName(
const Scope &);
288 static bool IsTempName(
const std::string &);
291 Scope *GetBuiltinModule(
const char *name);
294 void UseFortranBuiltinsModule();
295 const Scope *GetBuiltinsScope()
const {
return builtinsScope_; }
297 const Scope &GetCUDABuiltinsScope();
298 const Scope &GetCUDADeviceScope();
300 void UsePPCBuiltinTypesModule();
301 void UsePPCBuiltinsModule();
302 Scope *GetPPCBuiltinTypesScope() {
return ppcBuiltinTypesScope_; }
303 const Scope *GetPPCBuiltinsScope()
const {
return ppcBuiltinsScope_; }
307 parser::Program &SaveParseTree(parser::Program &&);
315 void MapCommonBlockAndCheckConflicts(
const Symbol &);
331 CommonBlockList GetCommonBlocks()
const;
333 void NoteDefinedSymbol(
const Symbol &);
334 bool IsSymbolDefined(
const Symbol &)
const;
335 void NoteUsedSymbol(
const Symbol &);
336 void NoteUsedSymbols(
const UnorderedSymbolSet &);
337 bool IsSymbolUsed(
const Symbol &)
const;
339 void DumpSymbols(llvm::raw_ostream &);
345 struct ScopeIndexComparator {
349 std::multimap<parser::CharBlock, Scope &, ScopeIndexComparator>;
354 void CheckError(
const Symbol &);
360 std::optional<parser::CharBlock> location_;
361 std::vector<std::string> searchDirectories_;
362 std::vector<std::string> intrinsicModuleDirectories_;
363 std::string moduleDirectory_{
"."s};
364 std::string moduleFileSuffix_{
".mod"};
365 bool underscoring_{
true};
366 bool warnOnNonstandardUsage_{
false};
367 bool warningsAreErrors_{
false};
368 bool debugModuleWriter_{
false};
369 const evaluate::IntrinsicProcTable intrinsics_;
372 Scope &intrinsicModulesScope_;
373 Scope *currentHermeticModuleFileScope_{
nullptr};
374 ScopeIndex scopeIndex_;
376 std::size_t maxErrors_{0};
378 ConstructStack constructStack_;
379 struct IndexVarInfo {
383 std::map<SymbolRef, const IndexVarInfo, SymbolAddressCompare>
385 UnorderedSymbolSet errorSymbols_;
386 std::set<std::string> tempNames_;
387 const Scope *builtinsScope_{
nullptr};
388 Scope *ppcBuiltinTypesScope_{
nullptr};
389 std::optional<const Scope *> cudaBuiltinsScope_;
390 std::optional<const Scope *> cudaDeviceScope_;
391 const Scope *ppcBuiltinsScope_{
nullptr};
392 std::list<parser::Program> modFileParseTrees_;
393 std::unique_ptr<CommonBlockMap> commonBlockMap_;
395 std::map<const Symbol *, SourceName> moduleFileOutputRenamings_;
396 UnorderedSymbolSet isDefined_;
397 UnorderedSymbolSet isUsed_;
398 std::list<ProgramTree> programTrees_;