-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsepreprocessed.h
More file actions
94 lines (74 loc) · 2.02 KB
/
Copy pathparsepreprocessed.h
File metadata and controls
94 lines (74 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include <QByteArray>
#include <QRegularExpression>
#include <QTextStream>
struct SourceFile
{
SourceFile() : startLine(0), endLine(0), netLines(0), indirectLines(0) { }
QString fileName;
int startLine; // start of this file in the preprocessed source
int endLine;
int netLines; // all source lines this file directly contributes
int indirectLines; // LOC caused by includes from this file
QVector<SourceFile> includes;
};
enum class LineType
{
Text,
Goto,
Return,
OtherMarker
};
struct LineFragments
{
LineFragments() : lineType(LineType::Text) {}
QString header;
int line;
LineType lineType;
};
struct SourceFileContribution
{
SourceFileContribution() : direct(0), indirect(0) {}
QString fileName;
int direct;
int indirect;
};
class ParsePreprocessed
{
public:
ParsePreprocessed(const QByteArray &input);
SourceFile sourceFile();
private:
LineFragments splitLine(const QString &line);
SourceFile makeSourceFile(const QStringList &lines);
QByteArray m_input;
QRegularExpression m_regex;
};
struct HeaderContribution
{
QString headerName;
int contributionTotal() const;
QVector<SourceFileContribution> sourceContributions;
};
struct AllContribution
{
void add(const QString fileName, const QString headerName, int direct, int indirect);
void sort();
QVector<HeaderContribution> contributors;
};
void printRecursive(const SourceFile &sourceFile, int depth, QTextStream &stream);
AllContribution mostUsed(const QVector<SourceFile> &sourceFiles);
void printMostUsed(const AllContribution &allContribution);
void printTotal(const QVector<SourceFile> &sourceFiles);
template <typename T>
void recursiveRun( const SourceFile &sourceFile, int depth, T callback, int maxDepth=0)
{
depth++;
if( (maxDepth >0) && (depth > maxDepth) ){
return;
}
callback(sourceFile, depth);
for(const auto &include: sourceFile.includes){
recursiveRun(include, depth, callback, maxDepth);
}
}