1//===-- FeatureList.cpp ---------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// A plugin that counts the amount of times a particular parse tree node
10// occurs. This plugin should cover each feature covered in dump-parse-tree.h
11//
12//===----------------------------------------------------------------------===//
13
14#include "flang/Frontend/FrontendActions.h"
15#include "flang/Frontend/FrontendPluginRegistry.h"
16#include "flang/Parser/parse-tree-visitor.h"
17#include "flang/Parser/parse-tree.h"
18#include "flang/Parser/parsing.h"
19
20#include <algorithm>
21#include <cstring>
22#include <unordered_map>
23#include <utility>
24#include <vector>
25
26using namespace Fortran::common;
27using namespace Fortran::frontend;
28using namespace Fortran::parser;
29using namespace Fortran;
30
31#define READ_FEATURE_CUST(classname, n) \
32 bool Pre(const classname &) { \
33 record(#n); \
34 return true; \
35 } \
36 void Post(const classname &) {}
37
38#define READ_FEATURE(classname) READ_FEATURE_CUST(classname, classname)
39
40struct NodeVisitor {
41private:
42 std::unordered_map<const char *, unsigned int> frequencies;
43
44 void record(const char *name) {
45 auto [it, ins] = frequencies.insert(x: {name, 1});
46 if (!ins) {
47 it->second++;
48 }
49 }
50
51public:
52 const std::unordered_map<const char *, unsigned int> &getFrequencies() const {
53 return frequencies;
54 }
55
56 READ_FEATURE_CUST(format::ControlEditDesc, ControlEditDesc)
57 READ_FEATURE_CUST(format::DerivedTypeDataEditDesc, DerivedTypeDataEditDesc)
58 READ_FEATURE_CUST(format::FormatItem, FormatItem)
59 READ_FEATURE_CUST(format::FormatSpecification, FormatSpecification)
60 READ_FEATURE_CUST(
61 format::IntrinsicTypeDataEditDesc, IntrinsicTypeDataEditDesc)
62 READ_FEATURE(Abstract)
63 READ_FEATURE(AccAtomicCapture)
64 READ_FEATURE(AccAtomicCapture::Stmt1)
65 READ_FEATURE(AccAtomicCapture::Stmt2)
66 READ_FEATURE(AccAtomicRead)
67 READ_FEATURE(AccAtomicUpdate)
68 READ_FEATURE(AccAtomicWrite)
69 READ_FEATURE(AccBeginBlockDirective)
70 READ_FEATURE(AccBeginCombinedDirective)
71 READ_FEATURE(AccBeginLoopDirective)
72 READ_FEATURE(AccBlockDirective)
73 READ_FEATURE(AccClause)
74 READ_FEATURE(AccBindClause)
75 READ_FEATURE(AccDefaultClause)
76 READ_FEATURE(AccClauseList)
77 READ_FEATURE(AccCombinedDirective)
78 READ_FEATURE(AccDataModifier)
79 READ_FEATURE(AccDataModifier::Modifier)
80 READ_FEATURE(AccDeclarativeDirective)
81 READ_FEATURE(AccEndAtomic)
82 READ_FEATURE(AccEndBlockDirective)
83 READ_FEATURE(AccEndCombinedDirective)
84 READ_FEATURE(AccGangArg)
85 READ_FEATURE(AccObject)
86 READ_FEATURE(AccObjectList)
87 READ_FEATURE(AccObjectListWithModifier)
88 READ_FEATURE(AccObjectListWithReduction)
89 READ_FEATURE(AccReductionOperator)
90 READ_FEATURE(AccReductionOperator::Operator)
91 READ_FEATURE(AccSizeExpr)
92 READ_FEATURE(AccSizeExprList)
93 READ_FEATURE(AccSelfClause)
94 READ_FEATURE(AccStandaloneDirective)
95 READ_FEATURE(AccDeviceTypeExpr)
96 READ_FEATURE(AccDeviceTypeExprList)
97 READ_FEATURE(AccTileExpr)
98 READ_FEATURE(AccTileExprList)
99 READ_FEATURE(AccLoopDirective)
100 READ_FEATURE(AccWaitArgument)
101 READ_FEATURE(AcImpliedDo)
102 READ_FEATURE(AcImpliedDoControl)
103 READ_FEATURE(AcValue)
104 READ_FEATURE(AccessStmt)
105 READ_FEATURE(AccessId)
106 READ_FEATURE(AccessSpec)
107 READ_FEATURE(AccessSpec::Kind)
108 READ_FEATURE(AcSpec)
109 READ_FEATURE(ActionStmt)
110 READ_FEATURE(ActualArg)
111 READ_FEATURE(ActualArg::PercentRef)
112 READ_FEATURE(ActualArg::PercentVal)
113 READ_FEATURE(ActualArgSpec)
114 READ_FEATURE(AcValue::Triplet)
115 READ_FEATURE(AllocOpt)
116 READ_FEATURE(AllocOpt::Mold)
117 READ_FEATURE(AllocOpt::Source)
118 READ_FEATURE(Allocatable)
119 READ_FEATURE(AllocatableStmt)
120 READ_FEATURE(AllocateCoarraySpec)
121 READ_FEATURE(AllocateObject)
122 READ_FEATURE(AllocateShapeSpec)
123 READ_FEATURE(AllocateStmt)
124 READ_FEATURE(Allocation)
125 READ_FEATURE(AltReturnSpec)
126 READ_FEATURE(ArithmeticIfStmt)
127 READ_FEATURE(ArrayConstructor)
128 READ_FEATURE(ArrayElement)
129 READ_FEATURE(ArraySpec)
130 READ_FEATURE(AssignStmt)
131 READ_FEATURE(AssignedGotoStmt)
132 READ_FEATURE(AssignmentStmt)
133 READ_FEATURE(AssociateConstruct)
134 READ_FEATURE(AssociateStmt)
135 READ_FEATURE(Association)
136 READ_FEATURE(AssumedImpliedSpec)
137 READ_FEATURE(AssumedRankSpec)
138 READ_FEATURE(AssumedShapeSpec)
139 READ_FEATURE(AssumedSizeSpec)
140 READ_FEATURE(Asynchronous)
141 READ_FEATURE(AsynchronousStmt)
142 READ_FEATURE(AttrSpec)
143 READ_FEATURE(BOZLiteralConstant)
144 READ_FEATURE(BackspaceStmt)
145 READ_FEATURE(BasedPointer)
146 READ_FEATURE(BasedPointerStmt)
147 READ_FEATURE(BindAttr)
148 READ_FEATURE(BindAttr::Deferred)
149 READ_FEATURE(BindAttr::Non_Overridable)
150 READ_FEATURE(BindEntity)
151 READ_FEATURE(BindEntity::Kind)
152 READ_FEATURE(BindStmt)
153 READ_FEATURE(Block)
154 READ_FEATURE(BlockConstruct)
155 READ_FEATURE(BlockData)
156 READ_FEATURE(BlockDataStmt)
157 READ_FEATURE(BlockSpecificationPart)
158 READ_FEATURE(BlockStmt)
159 READ_FEATURE(BoundsRemapping)
160 READ_FEATURE(BoundsSpec)
161 READ_FEATURE(Call)
162 READ_FEATURE(CallStmt)
163 READ_FEATURE(CaseConstruct)
164 READ_FEATURE(CaseConstruct::Case)
165 READ_FEATURE(CaseSelector)
166 READ_FEATURE(CaseStmt)
167 READ_FEATURE(CaseValueRange)
168 READ_FEATURE(CaseValueRange::Range)
169 READ_FEATURE(ChangeTeamConstruct)
170 READ_FEATURE(ChangeTeamStmt)
171 READ_FEATURE(CharLength)
172 READ_FEATURE(CharLiteralConstant)
173 READ_FEATURE(CharLiteralConstantSubstring)
174 READ_FEATURE(CharSelector)
175 READ_FEATURE(CharSelector::LengthAndKind)
176 READ_FEATURE(CloseStmt)
177 READ_FEATURE(CloseStmt::CloseSpec)
178 READ_FEATURE(CoarrayAssociation)
179 READ_FEATURE(CoarraySpec)
180 READ_FEATURE(CodimensionDecl)
181 READ_FEATURE(CodimensionStmt)
182 READ_FEATURE(CoindexedNamedObject)
183 READ_FEATURE(CommonBlockObject)
184 READ_FEATURE(CommonStmt)
185 READ_FEATURE(CommonStmt::Block)
186 READ_FEATURE(CompilerDirective)
187 READ_FEATURE(CompilerDirective::IgnoreTKR)
188 READ_FEATURE(CompilerDirective::LoopCount)
189 READ_FEATURE(CompilerDirective::NameValue)
190 READ_FEATURE(ComplexLiteralConstant)
191 READ_FEATURE(ComplexPart)
192 READ_FEATURE(ComponentArraySpec)
193 READ_FEATURE(ComponentAttrSpec)
194 READ_FEATURE(ComponentDataSource)
195 READ_FEATURE(ComponentDecl)
196 READ_FEATURE(FillDecl)
197 READ_FEATURE(ComponentOrFill)
198 READ_FEATURE(ComponentDefStmt)
199 READ_FEATURE(ComponentSpec)
200 READ_FEATURE(ComputedGotoStmt)
201 READ_FEATURE(ConcurrentControl)
202 READ_FEATURE(ConcurrentHeader)
203 READ_FEATURE(ConnectSpec)
204 READ_FEATURE(ConnectSpec::CharExpr)
205 READ_FEATURE(ConnectSpec::CharExpr::Kind)
206 READ_FEATURE(ConnectSpec::Newunit)
207 READ_FEATURE(ConnectSpec::Recl)
208 READ_FEATURE(ContainsStmt)
209 READ_FEATURE(Contiguous)
210 READ_FEATURE(ContiguousStmt)
211 READ_FEATURE(ContinueStmt)
212 READ_FEATURE(CriticalConstruct)
213 READ_FEATURE(CriticalStmt)
214 READ_FEATURE(CycleStmt)
215 READ_FEATURE(DataComponentDefStmt)
216 READ_FEATURE(DataIDoObject)
217 READ_FEATURE(DataImpliedDo)
218 READ_FEATURE(DataRef)
219 READ_FEATURE(DataStmt)
220 READ_FEATURE(DataStmtConstant)
221 READ_FEATURE(DataStmtObject)
222 READ_FEATURE(DataStmtRepeat)
223 READ_FEATURE(DataStmtSet)
224 READ_FEATURE(DataStmtValue)
225 READ_FEATURE(DeallocateStmt)
226 READ_FEATURE(DeclarationConstruct)
227 READ_FEATURE(DeclarationTypeSpec)
228 READ_FEATURE(DeclarationTypeSpec::Class)
229 READ_FEATURE(DeclarationTypeSpec::ClassStar)
230 READ_FEATURE(DeclarationTypeSpec::Record)
231 READ_FEATURE(DeclarationTypeSpec::Type)
232 READ_FEATURE(DeclarationTypeSpec::TypeStar)
233 READ_FEATURE(Default)
234 READ_FEATURE(DeferredCoshapeSpecList)
235 READ_FEATURE(DeferredShapeSpecList)
236 READ_FEATURE(DefinedOpName)
237 READ_FEATURE(DefinedOperator)
238 READ_FEATURE(DefinedOperator::IntrinsicOperator)
239 READ_FEATURE(DerivedTypeDef)
240 READ_FEATURE(DerivedTypeSpec)
241 READ_FEATURE(DerivedTypeStmt)
242 READ_FEATURE(Designator)
243 READ_FEATURE(DimensionStmt)
244 READ_FEATURE(DimensionStmt::Declaration)
245 READ_FEATURE(DoConstruct)
246 READ_FEATURE(DummyArg)
247 READ_FEATURE(ElseIfStmt)
248 READ_FEATURE(ElseStmt)
249 READ_FEATURE(ElsewhereStmt)
250 READ_FEATURE(EndAssociateStmt)
251 READ_FEATURE(EndBlockDataStmt)
252 READ_FEATURE(EndBlockStmt)
253 READ_FEATURE(EndChangeTeamStmt)
254 READ_FEATURE(EndCriticalStmt)
255 READ_FEATURE(EndDoStmt)
256 READ_FEATURE(EndEnumStmt)
257 READ_FEATURE(EndForallStmt)
258 READ_FEATURE(EndFunctionStmt)
259 READ_FEATURE(EndIfStmt)
260 READ_FEATURE(EndInterfaceStmt)
261 READ_FEATURE(EndLabel)
262 READ_FEATURE(EndModuleStmt)
263 READ_FEATURE(EndMpSubprogramStmt)
264 READ_FEATURE(EndProgramStmt)
265 READ_FEATURE(EndSelectStmt)
266 READ_FEATURE(EndSubmoduleStmt)
267 READ_FEATURE(EndSubroutineStmt)
268 READ_FEATURE(EndTypeStmt)
269 READ_FEATURE(EndWhereStmt)
270 READ_FEATURE(EndfileStmt)
271 READ_FEATURE(EntityDecl)
272 READ_FEATURE(EntryStmt)
273 READ_FEATURE(EnumDef)
274 READ_FEATURE(EnumDefStmt)
275 READ_FEATURE(Enumerator)
276 READ_FEATURE(EnumeratorDefStmt)
277 READ_FEATURE(EorLabel)
278 READ_FEATURE(EquivalenceObject)
279 READ_FEATURE(EquivalenceStmt)
280 READ_FEATURE(ErrLabel)
281 READ_FEATURE(ErrorRecovery)
282 READ_FEATURE(EventPostStmt)
283 READ_FEATURE(EventWaitStmt)
284 READ_FEATURE(EventWaitSpec)
285 READ_FEATURE(ExecutableConstruct)
286 READ_FEATURE(ExecutionPart)
287 READ_FEATURE(ExecutionPartConstruct)
288 READ_FEATURE(ExitStmt)
289 READ_FEATURE(ExplicitCoshapeSpec)
290 READ_FEATURE(ExplicitShapeSpec)
291 READ_FEATURE(Expr)
292 READ_FEATURE(Expr::Parentheses)
293 READ_FEATURE(Expr::UnaryPlus)
294 READ_FEATURE(Expr::Negate)
295 READ_FEATURE(Expr::NOT)
296 READ_FEATURE(Expr::PercentLoc)
297 READ_FEATURE(Expr::DefinedUnary)
298 READ_FEATURE(Expr::Power)
299 READ_FEATURE(Expr::Multiply)
300 READ_FEATURE(Expr::Divide)
301 READ_FEATURE(Expr::Add)
302 READ_FEATURE(Expr::Subtract)
303 READ_FEATURE(Expr::Concat)
304 READ_FEATURE(Expr::LT)
305 READ_FEATURE(Expr::LE)
306 READ_FEATURE(Expr::EQ)
307 READ_FEATURE(Expr::NE)
308 READ_FEATURE(Expr::GE)
309 READ_FEATURE(Expr::GT)
310 READ_FEATURE(Expr::AND)
311 READ_FEATURE(Expr::OR)
312 READ_FEATURE(Expr::EQV)
313 READ_FEATURE(Expr::NEQV)
314 READ_FEATURE(Expr::DefinedBinary)
315 READ_FEATURE(Expr::ComplexConstructor)
316 READ_FEATURE(External)
317 READ_FEATURE(ExternalStmt)
318 READ_FEATURE(FailImageStmt)
319 READ_FEATURE(FileUnitNumber)
320 READ_FEATURE(FinalProcedureStmt)
321 READ_FEATURE(FlushStmt)
322 READ_FEATURE(ForallAssignmentStmt)
323 READ_FEATURE(ForallBodyConstruct)
324 READ_FEATURE(ForallConstruct)
325 READ_FEATURE(ForallConstructStmt)
326 READ_FEATURE(ForallStmt)
327 READ_FEATURE(FormTeamStmt)
328 READ_FEATURE(FormTeamStmt::FormTeamSpec)
329 READ_FEATURE(Format)
330 READ_FEATURE(FormatStmt)
331 READ_FEATURE(FunctionReference)
332 READ_FEATURE(FunctionStmt)
333 READ_FEATURE(FunctionSubprogram)
334 READ_FEATURE(GenericSpec)
335 READ_FEATURE(GenericSpec::Assignment)
336 READ_FEATURE(GenericSpec::ReadFormatted)
337 READ_FEATURE(GenericSpec::ReadUnformatted)
338 READ_FEATURE(GenericSpec::WriteFormatted)
339 READ_FEATURE(GenericSpec::WriteUnformatted)
340 READ_FEATURE(GenericStmt)
341 READ_FEATURE(GotoStmt)
342 READ_FEATURE(HollerithLiteralConstant)
343 READ_FEATURE(IdExpr)
344 READ_FEATURE(IdVariable)
345 READ_FEATURE(IfConstruct)
346 READ_FEATURE(IfConstruct::ElseBlock)
347 READ_FEATURE(IfConstruct::ElseIfBlock)
348 READ_FEATURE(IfStmt)
349 READ_FEATURE(IfThenStmt)
350 READ_FEATURE(TeamValue)
351 READ_FEATURE(ImageSelector)
352 READ_FEATURE(ImageSelectorSpec)
353 READ_FEATURE(ImageSelectorSpec::Stat)
354 READ_FEATURE(ImageSelectorSpec::Team_Number)
355 READ_FEATURE(ImplicitPart)
356 READ_FEATURE(ImplicitPartStmt)
357 READ_FEATURE(ImplicitSpec)
358 READ_FEATURE(ImplicitStmt)
359 READ_FEATURE(ImplicitStmt::ImplicitNoneNameSpec)
360 READ_FEATURE(ImpliedShapeSpec)
361 READ_FEATURE(ImportStmt)
362 READ_FEATURE(Initialization)
363 READ_FEATURE(InputImpliedDo)
364 READ_FEATURE(InputItem)
365 READ_FEATURE(InquireSpec)
366 READ_FEATURE(InquireSpec::CharVar)
367 READ_FEATURE(InquireSpec::CharVar::Kind)
368 READ_FEATURE(InquireSpec::IntVar)
369 READ_FEATURE(InquireSpec::IntVar::Kind)
370 READ_FEATURE(InquireSpec::LogVar)
371 READ_FEATURE(InquireSpec::LogVar::Kind)
372 READ_FEATURE(InquireStmt)
373 READ_FEATURE(InquireStmt::Iolength)
374 READ_FEATURE(IntegerTypeSpec)
375 READ_FEATURE(IntentSpec)
376 READ_FEATURE(IntentSpec::Intent)
377 READ_FEATURE(IntentStmt)
378 READ_FEATURE(InterfaceBlock)
379 READ_FEATURE(InterfaceBody)
380 READ_FEATURE(InterfaceBody::Function)
381 READ_FEATURE(InterfaceBody::Subroutine)
382 READ_FEATURE(InterfaceSpecification)
383 READ_FEATURE(InterfaceStmt)
384 READ_FEATURE(InternalSubprogram)
385 READ_FEATURE(InternalSubprogramPart)
386 READ_FEATURE(Intrinsic)
387 READ_FEATURE(IntrinsicStmt)
388 READ_FEATURE(IntrinsicTypeSpec)
389 READ_FEATURE(IntrinsicTypeSpec::Character)
390 READ_FEATURE(IntrinsicTypeSpec::Complex)
391 READ_FEATURE(IntrinsicTypeSpec::DoubleComplex)
392 READ_FEATURE(IntrinsicTypeSpec::DoublePrecision)
393 READ_FEATURE(IntrinsicTypeSpec::Logical)
394 READ_FEATURE(IntrinsicTypeSpec::Real)
395 READ_FEATURE(IoControlSpec)
396 READ_FEATURE(IoControlSpec::Asynchronous)
397 READ_FEATURE(IoControlSpec::CharExpr)
398 READ_FEATURE(IoControlSpec::CharExpr::Kind)
399 READ_FEATURE(IoControlSpec::Pos)
400 READ_FEATURE(IoControlSpec::Rec)
401 READ_FEATURE(IoControlSpec::Size)
402 READ_FEATURE(IoUnit)
403 READ_FEATURE(Keyword)
404 READ_FEATURE(KindParam)
405 READ_FEATURE(KindSelector)
406 READ_FEATURE(KindSelector::StarSize)
407 READ_FEATURE(LabelDoStmt)
408 READ_FEATURE(LanguageBindingSpec)
409 READ_FEATURE(LengthSelector)
410 READ_FEATURE(LetterSpec)
411 READ_FEATURE(LiteralConstant)
412 READ_FEATURE(IntLiteralConstant)
413 READ_FEATURE(LocalitySpec)
414 READ_FEATURE(LocalitySpec::DefaultNone)
415 READ_FEATURE(LocalitySpec::Local)
416 READ_FEATURE(LocalitySpec::LocalInit)
417 READ_FEATURE(LocalitySpec::Shared)
418 READ_FEATURE(LockStmt)
419 READ_FEATURE(LockStmt::LockStat)
420 READ_FEATURE(LogicalLiteralConstant)
421 READ_FEATURE(LoopControl)
422 READ_FEATURE(LoopControl::Concurrent)
423 READ_FEATURE(MainProgram)
424 READ_FEATURE(Map)
425 READ_FEATURE(Map::EndMapStmt)
426 READ_FEATURE(Map::MapStmt)
427 READ_FEATURE(MaskedElsewhereStmt)
428 READ_FEATURE(Module)
429 READ_FEATURE(ModuleStmt)
430 READ_FEATURE(ModuleSubprogram)
431 READ_FEATURE(ModuleSubprogramPart)
432 READ_FEATURE(MpSubprogramStmt)
433 READ_FEATURE(MsgVariable)
434 READ_FEATURE(Name)
435 READ_FEATURE(NamedConstant)
436 READ_FEATURE(NamedConstantDef)
437 READ_FEATURE(NamelistStmt)
438 READ_FEATURE(NamelistStmt::Group)
439 READ_FEATURE(NonLabelDoStmt)
440 READ_FEATURE(NoPass)
441 READ_FEATURE(NotifyWaitStmt)
442 READ_FEATURE(NullifyStmt)
443 READ_FEATURE(NullInit)
444 READ_FEATURE(ObjectDecl)
445 READ_FEATURE(OldParameterStmt)
446 READ_FEATURE(OmpAlignedClause)
447 READ_FEATURE(OmpAtomic)
448 READ_FEATURE(OmpAtomicCapture)
449 READ_FEATURE(OmpAtomicCapture::Stmt1)
450 READ_FEATURE(OmpAtomicCapture::Stmt2)
451 READ_FEATURE(OmpAtomicRead)
452 READ_FEATURE(OmpAtomicUpdate)
453 READ_FEATURE(OmpAtomicWrite)
454 READ_FEATURE(OmpBeginBlockDirective)
455 READ_FEATURE(OmpBeginLoopDirective)
456 READ_FEATURE(OmpBeginSectionsDirective)
457 READ_FEATURE(OmpBlockDirective)
458 READ_FEATURE(OmpCancelType)
459 READ_FEATURE(OmpCancelType::Type)
460 READ_FEATURE(OmpClause)
461 READ_FEATURE(OmpClauseList)
462 READ_FEATURE(OmpCriticalDirective)
463 READ_FEATURE(OmpDeclareTargetSpecifier)
464 READ_FEATURE(OmpDeclareTargetWithClause)
465 READ_FEATURE(OmpDeclareTargetWithList)
466 READ_FEATURE(OmpDefaultClause)
467 READ_FEATURE(OmpDefaultClause::Type)
468 READ_FEATURE(OmpDefaultmapClause)
469 READ_FEATURE(OmpDefaultmapClause::ImplicitBehavior)
470 READ_FEATURE(OmpDefaultmapClause::VariableCategory)
471 READ_FEATURE(OmpDependClause)
472 READ_FEATURE(OmpDependClause::InOut)
473 READ_FEATURE(OmpDependClause::Sink)
474 READ_FEATURE(OmpDependClause::Source)
475 READ_FEATURE(OmpDependenceType)
476 READ_FEATURE(OmpDependenceType::Type)
477 READ_FEATURE(OmpDependSinkVec)
478 READ_FEATURE(OmpDependSinkVecLength)
479 READ_FEATURE(OmpEndAllocators)
480 READ_FEATURE(OmpEndAtomic)
481 READ_FEATURE(OmpEndBlockDirective)
482 READ_FEATURE(OmpEndCriticalDirective)
483 READ_FEATURE(OmpEndLoopDirective)
484 READ_FEATURE(OmpEndSectionsDirective)
485 READ_FEATURE(OmpIfClause)
486 READ_FEATURE(OmpIfClause::DirectiveNameModifier)
487 READ_FEATURE(OmpLinearClause)
488 READ_FEATURE(OmpLinearClause::WithModifier)
489 READ_FEATURE(OmpLinearClause::WithoutModifier)
490 READ_FEATURE(OmpLinearModifier)
491 READ_FEATURE(OmpLinearModifier::Type)
492 READ_FEATURE(OmpLoopDirective)
493 READ_FEATURE(OmpMapClause)
494 READ_FEATURE(OmpMapType)
495 READ_FEATURE(OmpMapType::Always)
496 READ_FEATURE(OmpMapType::Type)
497 READ_FEATURE(OmpObject)
498 READ_FEATURE(OmpObjectList)
499 READ_FEATURE(OmpOrderClause)
500 READ_FEATURE(OmpOrderClause::Type)
501 READ_FEATURE(OmpOrderModifier)
502 READ_FEATURE(OmpOrderModifier::Kind)
503 READ_FEATURE(OmpProcBindClause)
504 READ_FEATURE(OmpProcBindClause::Type)
505 READ_FEATURE(OmpReductionClause)
506 READ_FEATURE(OmpInReductionClause)
507 READ_FEATURE(OmpReductionCombiner)
508 READ_FEATURE(OmpReductionCombiner::FunctionCombiner)
509 READ_FEATURE(OmpReductionInitializerClause)
510 READ_FEATURE(OmpReductionOperator)
511 READ_FEATURE(OmpAllocateClause)
512 READ_FEATURE(OmpAllocateClause::AllocateModifier)
513 READ_FEATURE(OmpAllocateClause::AllocateModifier::Allocator)
514 READ_FEATURE(OmpAllocateClause::AllocateModifier::ComplexModifier)
515 READ_FEATURE(OmpAllocateClause::AllocateModifier::Align)
516 READ_FEATURE(OmpScheduleClause)
517 READ_FEATURE(OmpScheduleClause::ScheduleType)
518 READ_FEATURE(OmpDeviceClause)
519 READ_FEATURE(OmpDeviceClause::DeviceModifier)
520 READ_FEATURE(OmpDeviceTypeClause)
521 READ_FEATURE(OmpDeviceTypeClause::Type)
522 READ_FEATURE(OmpScheduleModifier)
523 READ_FEATURE(OmpScheduleModifier::Modifier1)
524 READ_FEATURE(OmpScheduleModifier::Modifier2)
525 READ_FEATURE(OmpScheduleModifierType)
526 READ_FEATURE(OmpScheduleModifierType::ModType)
527 READ_FEATURE(OmpSectionBlocks)
528 READ_FEATURE(OmpSectionsDirective)
529 READ_FEATURE(OmpSimpleStandaloneDirective)
530 READ_FEATURE(Only)
531 READ_FEATURE(OpenACCAtomicConstruct)
532 READ_FEATURE(OpenACCBlockConstruct)
533 READ_FEATURE(OpenACCCacheConstruct)
534 READ_FEATURE(OpenACCCombinedConstruct)
535 READ_FEATURE(OpenACCConstruct)
536 READ_FEATURE(OpenACCDeclarativeConstruct)
537 READ_FEATURE(OpenACCLoopConstruct)
538 READ_FEATURE(OpenACCRoutineConstruct)
539 READ_FEATURE(OpenACCStandaloneDeclarativeConstruct)
540 READ_FEATURE(OpenACCStandaloneConstruct)
541 READ_FEATURE(OpenACCWaitConstruct)
542 READ_FEATURE(OpenMPAtomicConstruct)
543 READ_FEATURE(OpenMPBlockConstruct)
544 READ_FEATURE(OpenMPCancelConstruct)
545 READ_FEATURE(OpenMPCancelConstruct::If)
546 READ_FEATURE(OpenMPCancellationPointConstruct)
547 READ_FEATURE(OpenMPConstruct)
548 READ_FEATURE(OpenMPCriticalConstruct)
549 READ_FEATURE(OpenMPDeclarativeAllocate)
550 READ_FEATURE(OpenMPDeclarativeConstruct)
551 READ_FEATURE(OpenMPDeclareReductionConstruct)
552 READ_FEATURE(OpenMPDeclareSimdConstruct)
553 READ_FEATURE(OpenMPDeclareTargetConstruct)
554 READ_FEATURE(OmpMemoryOrderClause)
555 READ_FEATURE(OmpAtomicClause)
556 READ_FEATURE(OmpAtomicClauseList)
557 READ_FEATURE(OmpAtomicDefaultMemOrderClause)
558 READ_FEATURE(OmpAtomicDefaultMemOrderType)
559 READ_FEATURE(OpenMPFlushConstruct)
560 READ_FEATURE(OpenMPLoopConstruct)
561 READ_FEATURE(OpenMPExecutableAllocate)
562 READ_FEATURE(OpenMPAllocatorsConstruct)
563 READ_FEATURE(OpenMPRequiresConstruct)
564 READ_FEATURE(OpenMPSimpleStandaloneConstruct)
565 READ_FEATURE(OpenMPStandaloneConstruct)
566 READ_FEATURE(OpenMPSectionConstruct)
567 READ_FEATURE(OpenMPSectionsConstruct)
568 READ_FEATURE(OpenMPThreadprivate)
569 READ_FEATURE(OpenStmt)
570 READ_FEATURE(Optional)
571 READ_FEATURE(OptionalStmt)
572 READ_FEATURE(OtherSpecificationStmt)
573 READ_FEATURE(OutputImpliedDo)
574 READ_FEATURE(OutputItem)
575 READ_FEATURE(Parameter)
576 READ_FEATURE(ParameterStmt)
577 READ_FEATURE(ParentIdentifier)
578 READ_FEATURE(Pass)
579 READ_FEATURE(PauseStmt)
580 READ_FEATURE(Pointer)
581 READ_FEATURE(PointerAssignmentStmt)
582 READ_FEATURE(PointerAssignmentStmt::Bounds)
583 READ_FEATURE(PointerDecl)
584 READ_FEATURE(PointerObject)
585 READ_FEATURE(PointerStmt)
586 READ_FEATURE(PositionOrFlushSpec)
587 READ_FEATURE(PrefixSpec)
588 READ_FEATURE(PrefixSpec::Elemental)
589 READ_FEATURE(PrefixSpec::Impure)
590 READ_FEATURE(PrefixSpec::Module)
591 READ_FEATURE(PrefixSpec::Non_Recursive)
592 READ_FEATURE(PrefixSpec::Pure)
593 READ_FEATURE(PrefixSpec::Recursive)
594 READ_FEATURE(PrintStmt)
595 READ_FEATURE(PrivateStmt)
596 READ_FEATURE(PrivateOrSequence)
597 READ_FEATURE(ProcAttrSpec)
598 READ_FEATURE(ProcComponentAttrSpec)
599 READ_FEATURE(ProcComponentDefStmt)
600 READ_FEATURE(ProcComponentRef)
601 READ_FEATURE(ProcDecl)
602 READ_FEATURE(ProcInterface)
603 READ_FEATURE(ProcPointerInit)
604 READ_FEATURE(ProcedureDeclarationStmt)
605 READ_FEATURE(ProcedureDesignator)
606 READ_FEATURE(ProcedureStmt)
607 READ_FEATURE(ProcedureStmt::Kind)
608 READ_FEATURE(Program)
609 READ_FEATURE(ProgramStmt)
610 READ_FEATURE(ProgramUnit)
611 READ_FEATURE(Protected)
612 READ_FEATURE(ProtectedStmt)
613 READ_FEATURE(ReadStmt)
614 READ_FEATURE(RealLiteralConstant)
615 READ_FEATURE(RealLiteralConstant::Real)
616 READ_FEATURE(Rename)
617 READ_FEATURE(Rename::Names)
618 READ_FEATURE(Rename::Operators)
619 READ_FEATURE(ReturnStmt)
620 READ_FEATURE(RewindStmt)
621 READ_FEATURE(Save)
622 READ_FEATURE(SaveStmt)
623 READ_FEATURE(SavedEntity)
624 READ_FEATURE(SavedEntity::Kind)
625 READ_FEATURE(SectionSubscript)
626 READ_FEATURE(SelectCaseStmt)
627 READ_FEATURE(SelectRankCaseStmt)
628 READ_FEATURE(SelectRankCaseStmt::Rank)
629 READ_FEATURE(SelectRankConstruct)
630 READ_FEATURE(SelectRankConstruct::RankCase)
631 READ_FEATURE(SelectRankStmt)
632 READ_FEATURE(SelectTypeConstruct)
633 READ_FEATURE(SelectTypeConstruct::TypeCase)
634 READ_FEATURE(SelectTypeStmt)
635 READ_FEATURE(Selector)
636 READ_FEATURE(SeparateModuleSubprogram)
637 READ_FEATURE(SequenceStmt)
638 READ_FEATURE(Sign)
639 READ_FEATURE(SignedComplexLiteralConstant)
640 READ_FEATURE(SignedIntLiteralConstant)
641 READ_FEATURE(SignedRealLiteralConstant)
642 READ_FEATURE(SpecificationConstruct)
643 READ_FEATURE(SpecificationExpr)
644 READ_FEATURE(SpecificationPart)
645 READ_FEATURE(Star)
646 READ_FEATURE(StatOrErrmsg)
647 READ_FEATURE(StatVariable)
648 READ_FEATURE(StatusExpr)
649 READ_FEATURE(StmtFunctionStmt)
650 READ_FEATURE(StopCode)
651 READ_FEATURE(StopStmt)
652 READ_FEATURE(StopStmt::Kind)
653 READ_FEATURE(StructureComponent)
654 READ_FEATURE(StructureConstructor)
655 READ_FEATURE(StructureDef)
656 READ_FEATURE(StructureDef::EndStructureStmt)
657 READ_FEATURE(StructureField)
658 READ_FEATURE(StructureStmt)
659 READ_FEATURE(Submodule)
660 READ_FEATURE(SubmoduleStmt)
661 READ_FEATURE(SubroutineStmt)
662 READ_FEATURE(SubroutineSubprogram)
663 READ_FEATURE(SubscriptTriplet)
664 READ_FEATURE(Substring)
665 READ_FEATURE(SubstringInquiry)
666 READ_FEATURE(SubstringRange)
667 READ_FEATURE(Suffix)
668 READ_FEATURE(SyncAllStmt)
669 READ_FEATURE(SyncImagesStmt)
670 READ_FEATURE(SyncImagesStmt::ImageSet)
671 READ_FEATURE(SyncMemoryStmt)
672 READ_FEATURE(SyncTeamStmt)
673 READ_FEATURE(Target)
674 READ_FEATURE(TargetStmt)
675 READ_FEATURE(TypeAttrSpec)
676 READ_FEATURE(TypeAttrSpec::BindC)
677 READ_FEATURE(TypeAttrSpec::Extends)
678 READ_FEATURE(TypeBoundGenericStmt)
679 READ_FEATURE(TypeBoundProcBinding)
680 READ_FEATURE(TypeBoundProcDecl)
681 READ_FEATURE(TypeBoundProcedurePart)
682 READ_FEATURE(TypeBoundProcedureStmt)
683 READ_FEATURE(TypeBoundProcedureStmt::WithInterface)
684 READ_FEATURE(TypeBoundProcedureStmt::WithoutInterface)
685 READ_FEATURE(TypeDeclarationStmt)
686 READ_FEATURE(TypeGuardStmt)
687 READ_FEATURE(TypeGuardStmt::Guard)
688 READ_FEATURE(TypeParamDecl)
689 READ_FEATURE(TypeParamDefStmt)
690 READ_FEATURE(common::TypeParamAttr)
691 READ_FEATURE(TypeParamSpec)
692 READ_FEATURE(TypeParamValue)
693 READ_FEATURE(TypeParamValue::Deferred)
694 READ_FEATURE(TypeSpec)
695 READ_FEATURE(Union)
696 READ_FEATURE(Union::EndUnionStmt)
697 READ_FEATURE(Union::UnionStmt)
698 READ_FEATURE(UnlockStmt)
699 READ_FEATURE(UseStmt)
700 READ_FEATURE(UseStmt::ModuleNature)
701 READ_FEATURE(Value)
702 READ_FEATURE(ValueStmt)
703 READ_FEATURE(Variable)
704 READ_FEATURE(Verbatim)
705 READ_FEATURE(Volatile)
706 READ_FEATURE(VolatileStmt)
707 READ_FEATURE(WaitSpec)
708 READ_FEATURE(WaitStmt)
709 READ_FEATURE(WhereBodyConstruct)
710 READ_FEATURE(WhereConstruct)
711 READ_FEATURE(WhereConstruct::Elsewhere)
712 READ_FEATURE(WhereConstruct::MaskedElsewhere)
713 READ_FEATURE(WhereConstructStmt)
714 READ_FEATURE(WhereStmt)
715 READ_FEATURE(WriteStmt)
716
717 READ_FEATURE(llvm::omp::Directive)
718 READ_FEATURE(llvm::omp::Clause)
719 READ_FEATURE(llvm::acc::Directive)
720 READ_FEATURE(llvm::acc::DefaultValue)
721
722 template <typename A> bool Pre(const A &) { return true; }
723 template <typename A> void Post(const A &) {}
724
725 template <typename T> bool Pre(const Statement<T> &) { return true; }
726 template <typename T> void Post(const Statement<T> &) {}
727
728 template <typename T> bool Pre(const UnlabeledStatement<T> &) { return true; }
729 template <typename T> void Post(const UnlabeledStatement<T> &) {}
730
731 template <typename T> bool Pre(const common::Indirection<T> &) {
732 return true;
733 }
734 template <typename T> void Post(const common::Indirection<T> &) {}
735
736 template <typename A> bool Pre(const Scalar<A> &) { return true; }
737 template <typename A> void Post(const Scalar<A> &) {}
738
739 template <typename A> bool Pre(const Constant<A> &) { return true; }
740 template <typename A> void Post(const Constant<A> &) {}
741
742 template <typename A> bool Pre(const Integer<A> &) { return true; }
743 template <typename A> void Post(const Integer<A> &) {}
744
745 template <typename A> bool Pre(const Logical<A> &) { return true; }
746 template <typename A> void Post(const Logical<A> &) {}
747
748 template <typename A> bool Pre(const DefaultChar<A> &) { return true; }
749 template <typename A> void Post(const DefaultChar<A> &) {}
750
751 template <typename... A> bool Pre(const std::tuple<A...> &) { return true; }
752 template <typename... A> void Post(const std::tuple<A...> &) {}
753
754 template <typename... A> bool Pre(const std::variant<A...> &) { return true; }
755 template <typename... A> void Post(const std::variant<A...> &) {}
756};
757
758bool sortNodes(std::pair<const char *, int> a, std::pair<const char *, int> b) {
759 return (a.second == b.second) ? (std::strcmp(s1: a.first, s2: b.first) < 0)
760 : a.second > b.second;
761}
762
763class FeatureListAction : public PluginParseTreeAction {
764 void executeAction() override {
765 NodeVisitor visitor;
766 Fortran::parser::Walk(getParsing().parseTree(), visitor);
767
768 const auto &frequencyMap = visitor.getFrequencies();
769 std::vector<std::pair<const char *, int>> frequencies(
770 frequencyMap.begin(), frequencyMap.end());
771
772 std::sort(first: frequencies.begin(), last: frequencies.end(), comp: sortNodes);
773 for (auto const &[feature, frequency] : frequencies) {
774 llvm::outs() << feature << ": " << frequency << "\n";
775 }
776 }
777
778 bool beginSourceFileAction() override { return runPrescan() && runParse(); }
779};
780
781static FrontendPluginRegistry::Add<FeatureListAction> X(
782 "feature-list", "List program features");
783

source code of flang/examples/FeatureList/FeatureList.cpp