Repository navigation
Expand file tree
/
Copy pathProblemChecker.pas
More file actions
134 lines (110 loc) · 4.39 KB
/
Copy pathProblemChecker.pas
File metadata and controls
134 lines (110 loc) · 4.39 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
namespace ProHolz.SourceChecker;
interface
uses ProHolz.Ast;
type
// Alias shoud be in PascalParser
SNT = TSyntaxNodeType;
TSyntaxNodeList = List<TSyntaxNode>;
type
TProblemChecker = sealed class( IProblemChecker, IProblem_Log)
private
fProbsList: tProbsList;
fProbSolver : Dictionary<eEleCheck, ISingleProbSolver>;
fResolver : ISyntaxNodeSolver;
private // Interface
method check(const syntaxTree: TSyntaxNode): Boolean;
method FoundProblems: Boolean;
method GetProblemsText: String;
method Problem_At(aCheck : eEleCheck; Line : Integer; Pos : Integer; const Name : String := '');
public
constructor (aEleCheck : sequence of eEleCheck);
end;
implementation
{ TProblemChecker }
constructor TProblemChecker(aEleCheck : sequence of eEleCheck);
begin
inherited Create;
fProbsList := new tProbsList();
fProbSolver := new Dictionary<eEleCheck, ISingleProbSolver>;
fResolver := new TSyntaxNodeResolver();
// Prepare the solvers
for each check in aEleCheck do
begin
case check of
eEleCheck.eDfm : fProbSolver.Add(check, new TProblem_DFM);
eEleCheck.eWith : fProbSolver.Add(check, new TProblem_With);
eEleCheck.eInitializations : fProbSolver.Add(check, new TProblem_Initialization);
eEleCheck.eFinalizations : fProbSolver.Add(check, new TProblem_Finalization);
eEleCheck.ePublicVars : fProbSolver.Add(check, new TProblem_GlobVars);
eEleCheck.eGlobalMethods : fProbSolver.Add(check, new TProblem_GlobMethods);
eEleCheck.eDestructors : fProbSolver.Add(check, new TProblem_Destructors);
eEleCheck.eMultiConstructors : fProbSolver.Add(check, new TProblem_MultiContructors);
eEleCheck.eMoreThenOneClass : fProbSolver.Add(check, new TProblem_MoreThanOneClass);
eEleCheck.eInterfaceandImplement : fProbSolver.Add(check, new TProblem_InterFaceAndImplement);
eEleCheck.eVariantRecord : fProbSolver.Add(check, new TProblem_VariantRecord);
eEleCheck.ePublicEnums : fProbSolver.Add(check, new TProblem_Enums);
eEleCheck.eClassDeclImpl : fProbSolver.Add(check, new TProblem_ClassInImplementation);
eEleCheck.eConstRecord : fProbSolver.Add(check, new TProblem_HasConstRecords);
eEleCheck.eHasResources : fProbSolver.Add(check, new TProblem_RES);
eEleCheck.eHasResourceStrings : fProbSolver.Add(check, new TProblem_ResString);
eEleCheck.eVarsWithTypes : fProbSolver.Add(check, new TProblem_VarTypes);
eEleCheck.eTypesInMethods : fProbSolver.Add(check, new TProblem_TypesInMethods);
eEleCheck.eAsm : fProbSolver.Add(check, new TProblem_Asm);
eEleCheck.eTypeinType : fProbSolver.Add(check, new TProblem_TypeInTypes);
end;
end;
end;
method TProblemChecker.check(const syntaxTree: TSyntaxNode): boolean;
begin
result := false;
if (syntaxTree <> nil) and (syntaxTree.Typ = TSyntaxNodeType.ntUnit) then
begin
var lName := syntaxTree.AttribName.ToLower;
// The unit should only b parsed once
if not fProbsList.ContainsKey(lName) then
begin
var factual := new tPasSource();
factual.FileName := lName;
for each check in fProbSolver.Values do
begin
if check.CheckForProblem(syntaxTree, fResolver, factual) then
begin
// This is only needed if the check dont write anything himself in the factual
factual.AddProblem(check.CheckTyp);
end;
end;
if (factual.Problems.Count > 0) then
begin
fProbsList.Add(lName, factual);
result := true;
end;
end
end;
end;
method TProblemChecker.FoundProblems: boolean;
begin
result := fProbsList.Count > 0;
end;
method TProblemChecker.GetProblemsText: String;
var
ltext: StringBuilder;
begin
if fProbsList.Count = 0 then
exit('');
ltext := new StringBuilder();
for lact in fProbsList.Values do
begin
ltext.AppendLine(lact.FileName + '.pas');
for lLoop in lact.Problems.Keys do
begin
// ltext.AppendLine(' ' + cEleProbsnames[lLoop]);
ltext.AppendLine(lact.getProblemsPos(lLoop));
end;
ltext.AppendLine('====').AppendLine;
end;
result := ltext.ToString;
end;
method TProblemChecker.Problem_At(aCheck: eEleCheck; Line: Integer; Pos: Integer; const Name : String := '');
begin
end;
end.