Skip to content

Commit c0a213a

Browse files
FIX: LineIndex after {$I ...} was wrong
1 parent ad218cd commit c0a213a

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

src/ufpcparser.pas

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
classes, SysUtils, upascallexer;
2323

2424
Const
25-
LookbackCnt = 10; // wie viele sollten das denn sein ??
25+
LookbackCnt = 10; // Speichert die Historie der letzten "X" geparsten Tokens, 10 ist dabei ein empirisch ermittelter Wert.
2626

2727
Type
2828

@@ -118,7 +118,7 @@ , sInClassStart // Wir haben "= class" gefunden -> Entscheiden ob wir das in
118118

119119
Uses Dialogs, FileUtil;
120120

121-
Procedure Nop();
121+
Procedure Nop(); // Nur zum Debuggen
122122
Begin
123123

124124
End;
@@ -497,7 +497,7 @@ * "= class"
497497
lastCodeLine := 0;
498498
lastCommentLine := 0;
499499
lexer.LexFile(aFilename);
500-
fFileInfo.NumberOfTotalLines := lexer.TotalLineCount - 1;
500+
fFileInfo.NumberOfTotalLines := lexer.TotalParsedLineCount - 1;
501501
fFileInfo.NumberOfEmptyLines := lexer.EmptyLineCount - 1;
502502
lexer.free;
503503
result := true;

src/unit1.pas

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
(* implementation, nor anything other that could happen *)
2121
(* or go wrong, use at your own risk. *)
2222
(* *)
23-
(* Known Issues: none *)
24-
(* *)
2523
(* History : 0.01 - Initialversion (dependency graph, Klass Analysis, *)
2624
(* Statistik) *)
2725
(* 0.02 - Counter ersetzt durch FPCParser *)
@@ -65,12 +63,10 @@
6563
(* ADD: more infos to chart statistics *)
6664
(* 0.25 - ADD: Code preview / review feature *)
6765
(* ADD: Mark nodes with comments *)
66+
(* 0.26 - FIX: Line index after {$I ...} *)
6867
(* *)
6968
(* Known Bugs : - if a project holds 2 units with the same name *)
7069
(* the dependency graph will merge them to one *)
71-
(* - if a file contains a .inc file that is included, all "Line"*)
72-
(* informations, after that .inc file are offsetted by the *)
73-
(* length of the .inc files content *)
7470
(* *)
7571
(* Missing : - Callgraphen (über Klassen, über Echte Methoden, *)
7672
(* über Units ..) *)

src/upascallexer.pas

+30-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(******************************************************************************)
22
(* upascallexer 19.04.2023 *)
33
(* *)
4-
(* Version : 0.04 *)
4+
(* Version : 0.05 *)
55
(* *)
66
(* Author : Uwe Schächterle (Corpsman) *)
77
(* *)
@@ -26,6 +26,7 @@
2626
(* 0.02 - Add Total Line Counter, Empty Line Counter *)
2727
(* 0.03 - Start with unittests, fix "invalid" ( * Parsing *)
2828
(* 0.04 - Berücksichtigen von {$I ...} *)
29+
(* 0.05 - Fix Linecounting von {$I ...} *)
2930
(* *)
3031
(******************************************************************************)
3132
Unit upascallexer;
@@ -52,7 +53,7 @@
5253

5354
TToken = Record
5455
Value: String;
55-
Line: integer;
56+
Line: integer; // Die Zeile in der Datei (Alles was via {$I ...} inkludiert wird, landet in der selben Zeile in der das {$I ...} steht
5657
Kind: TTokenKind;
5758
End;
5859

@@ -65,6 +66,7 @@
6566
private
6667
aToken: String;
6768
aLine: Integer;
69+
aParsedLine: Integer;
6870
aEmptyLine: integer;
6971
Procedure HandleToken();
7072
Procedure DoLex(Const Stream: TStream);
@@ -73,7 +75,8 @@
7375

7476
OnHandleToken: TOnHandleToken;
7577

76-
Property TotalLineCount: integer read aLine;
78+
Property TotalFileLineCount: integer read aLine; // Anzahl an Zeilen innerhalb der Datei
79+
Property TotalParsedLineCount: integer read aParsedLine; // Tatsächliche Anzahl an geparsten Zeilen (wenn die Datei ein {$I ...} token hat, dann unterscheiden sich die beiden Line counts)
7780
Property EmptyLineCount: integer read aEmptyLine;
7881

7982
Constructor Create(); virtual;
@@ -353,8 +356,21 @@
353356

354357
Procedure TPascalLexer.DoLex(Const Stream: TStream);
355358

356-
Procedure HToken()Inline;
359+
Var
360+
BlockLineCounting: Boolean; // Wenn True, dann werden die ZeilenNummern nicht "Erhöht" wenn CRT gelesen wird.
361+
362+
Procedure HToken(); //Inline;
357363
Begin
364+
If atoken = '~DisableLineCounter~' Then Begin
365+
BlockLineCounting := true;
366+
atoken := '';
367+
exit;
368+
End;
369+
If atoken = '~EnableLineCounter~' Then Begin
370+
BlockLineCounting := false;
371+
atoken := '';
372+
exit;
373+
End;
358374
If atoken <> '' Then Begin // Der Token vor dem ersten erkannten Token ist in der Regel leer -> Raus werfen.
359375
HandleToken();
360376
aToken := '';
@@ -388,11 +404,13 @@
388404
i, mSize: Int64;
389405
Begin
390406
aToken := '';
407+
BlockLineCounting := false;
391408
State := sCollectToken;
392409
CommentDetphCounter := 0;
393410
pc := #0;
394411
c := #0;
395412
aLine := 1; // Textdateien sind 1 Basiert
413+
aParsedLine := 1;
396414
aEmptyLine := 0;
397415
i := 0;
398416
mSize := Stream.Size;
@@ -653,8 +671,11 @@
653671
If (c = lb) And ((pc = lb) Or ((ppc = lb) And (pc In [#10, #13]))) Then Begin
654672
inc(aEmptyLine);
655673
End;
656-
If c = LB Then Begin
657-
inc(aLine);
674+
If (c = LB) Then Begin
675+
If (Not BlockLineCounting) Then Begin
676+
inc(aLine);
677+
End;
678+
inc(aParsedLine);
658679
End;
659680
inc(i);
660681
End;
@@ -673,7 +694,7 @@
673694
m: TMemoryStream;
674695
sl2, sl: TStringList;
675696
i: integer;
676-
s: String;
697+
s, t: String;
677698
Begin
678699
sl := TStringList.Create;
679700
Try
@@ -684,13 +705,14 @@
684705
If pos('{$I ', sl[i]) <> 0 Then Begin
685706
s := sl[i];
686707
s := copy(s, pos('{$I ', s) + 4, length(s));
708+
t := copy(s, pos('}', s) + 1, length(s)); // Retten dessen was nach dem Include kommt.
687709
s := copy(s, 1, pos('}', s) - 1);
688710
s := trim(s);
689711
s := OnResolveFileRequest(self, s);
690712
If s <> '' Then Begin
691713
sl2 := TStringList.Create;
692714
sl2.LoadFromFile(s);
693-
sl[i] := sl2.Text; // TODO: das funktioniert nur, wenn in der Zeile sonst nichts anderes Steht
715+
sl[i] := ' ~DisableLineCounter~ ' + sl2.Text + ' ~EnableLineCounter~ ' + t;
694716
sl2.free;
695717
End;
696718
End;

0 commit comments

Comments
 (0)