|
@@ -70,9 +70,11 @@ type
|
|
TPpuRef = class
|
|
TPpuRef = class
|
|
public
|
|
public
|
|
UnitIndex: word;
|
|
UnitIndex: word;
|
|
- Id: integer;
|
|
|
|
|
|
+ Id: cardinal;
|
|
constructor Create;
|
|
constructor Create;
|
|
procedure Write(Output: TPpuOutput; const RefName: string);
|
|
procedure Write(Output: TPpuOutput; const RefName: string);
|
|
|
|
+ function IsCurUnit: boolean; inline;
|
|
|
|
+ function IsNull: boolean; inline;
|
|
end;
|
|
end;
|
|
|
|
|
|
TPpuFilePos = record
|
|
TPpuFilePos = record
|
|
@@ -80,16 +82,19 @@ type
|
|
Line, Col: integer;
|
|
Line, Col: integer;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+ TPpuDefVisibility = (dvPublic, dvPublished, dvProtected, dvPrivate);
|
|
|
|
+
|
|
{ TPpuDef }
|
|
{ TPpuDef }
|
|
|
|
|
|
TPpuDef = class
|
|
TPpuDef = class
|
|
private
|
|
private
|
|
- FId: integer;
|
|
|
|
|
|
+ FId: cardinal;
|
|
FParent: TPpuContainerDef;
|
|
FParent: TPpuContainerDef;
|
|
FParentUnit: TPpuUnitDef;
|
|
FParentUnit: TPpuUnitDef;
|
|
function GetDefTypeName: string;
|
|
function GetDefTypeName: string;
|
|
|
|
+ function GetId: cardinal;
|
|
function GetParentUnit: TPpuUnitDef;
|
|
function GetParentUnit: TPpuUnitDef;
|
|
- procedure SetId(AValue: integer);
|
|
|
|
|
|
+ procedure SetId(AValue: cardinal);
|
|
|
|
|
|
protected
|
|
protected
|
|
procedure WriteDef(Output: TPpuOutput); virtual;
|
|
procedure WriteDef(Output: TPpuOutput); virtual;
|
|
@@ -98,13 +103,17 @@ type
|
|
DefType: TPpuDefType;
|
|
DefType: TPpuDefType;
|
|
Name: string;
|
|
Name: string;
|
|
FilePos: TPpuFilePos;
|
|
FilePos: TPpuFilePos;
|
|
|
|
+ // Symbol/definition reference
|
|
|
|
+ Ref: TPpuRef;
|
|
|
|
+ Visibility: TPpuDefVisibility;
|
|
|
|
|
|
constructor Create(AParent: TPpuContainerDef); virtual; reintroduce;
|
|
constructor Create(AParent: TPpuContainerDef); virtual; reintroduce;
|
|
destructor Destroy; override;
|
|
destructor Destroy; override;
|
|
procedure Write(Output: TPpuOutput);
|
|
procedure Write(Output: TPpuOutput);
|
|
|
|
+ procedure SetSymId(AId: integer);
|
|
property Parent: TPpuContainerDef read FParent;
|
|
property Parent: TPpuContainerDef read FParent;
|
|
property ParentUnit: TPpuUnitDef read GetParentUnit;
|
|
property ParentUnit: TPpuUnitDef read GetParentUnit;
|
|
- property Id: integer read FId write SetId;
|
|
|
|
|
|
+ property Id: cardinal read GetId write SetId;
|
|
property DefTypeName: string read GetDefTypeName;
|
|
property DefTypeName: string read GetDefTypeName;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -118,6 +127,7 @@ type
|
|
|
|
|
|
protected
|
|
protected
|
|
procedure WriteDef(Output: TPpuOutput); override;
|
|
procedure WriteDef(Output: TPpuOutput); override;
|
|
|
|
+ procedure BeforeWriteItems(Output: TPpuOutput); virtual;
|
|
|
|
|
|
public
|
|
public
|
|
ItemsName: string;
|
|
ItemsName: string;
|
|
@@ -145,7 +155,7 @@ type
|
|
|
|
|
|
constructor Create(AParent: TPpuContainerDef); override;
|
|
constructor Create(AParent: TPpuContainerDef); override;
|
|
destructor Destroy; override;
|
|
destructor Destroy; override;
|
|
- function FindById(AId: integer): TPpuDef;
|
|
|
|
|
|
+ function FindById(AId: integer; FindSym: boolean = False): TPpuDef;
|
|
end;
|
|
end;
|
|
|
|
|
|
{ TPpuSrcFile }
|
|
{ TPpuSrcFile }
|
|
@@ -156,12 +166,17 @@ type
|
|
FileTime: TDateTime;
|
|
FileTime: TDateTime;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+ TPpuProcOption = (poProcedure, poFunction, poConstructor, poDestructor, poOperator,
|
|
|
|
+ poClassMethod, poVirtual, poAbstract, poOverriding, poOverload, poInline);
|
|
|
|
+ TPpuProcOptions = set of TPpuProcOption;
|
|
|
|
+
|
|
{ TPpuProcDef }
|
|
{ TPpuProcDef }
|
|
TPpuProcDef = class(TPpuContainerDef)
|
|
TPpuProcDef = class(TPpuContainerDef)
|
|
protected
|
|
protected
|
|
- procedure WriteDef(Output: TPpuOutput); override;
|
|
|
|
|
|
+ procedure BeforeWriteItems(Output: TPpuOutput); override;
|
|
public
|
|
public
|
|
ReturnType: TPpuRef;
|
|
ReturnType: TPpuRef;
|
|
|
|
+ Options: TPpuProcOptions;
|
|
constructor Create(AParent: TPpuContainerDef); override;
|
|
constructor Create(AParent: TPpuContainerDef); override;
|
|
destructor Destroy; override;
|
|
destructor Destroy; override;
|
|
end;
|
|
end;
|
|
@@ -172,35 +187,125 @@ type
|
|
constructor Create(AParent: TPpuContainerDef); override;
|
|
constructor Create(AParent: TPpuContainerDef); override;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+ { TPpuVarDef }
|
|
|
|
+
|
|
|
|
+ TPpuVarDef = class(TPpuDef)
|
|
|
|
+ protected
|
|
|
|
+ procedure WriteDef(Output: TPpuOutput); override;
|
|
|
|
+ public
|
|
|
|
+ VarType: TPpuRef;
|
|
|
|
+ constructor Create(AParent: TPpuContainerDef); override;
|
|
|
|
+ destructor Destroy; override;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ { TPpuParamDef }
|
|
|
|
+
|
|
|
|
+ TPpuParamDef = class(TPpuVarDef)
|
|
|
|
+ public
|
|
|
|
+ constructor Create(AParent: TPpuContainerDef); override;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ { TPpuObjectDef }
|
|
|
|
+
|
|
|
|
+ TPpuObjectDef = class(TPpuContainerDef)
|
|
|
|
+ public
|
|
|
|
+ constructor Create(AParent: TPpuContainerDef); override;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+
|
|
implementation
|
|
implementation
|
|
|
|
|
|
const
|
|
const
|
|
DefTypeNames: array[TPpuDefType] of string =
|
|
DefTypeNames: array[TPpuDefType] of string =
|
|
- ('', 'unit', 'object', 'record', 'procedure', 'field', 'property', 'parameter', 'variable',
|
|
|
|
- 'type', 'constant', 'proctype', 'enum', 'set');
|
|
|
|
|
|
+ ('', 'unit', 'obj', 'rec', 'proc', 'field', 'prop', 'param', 'var',
|
|
|
|
+ 'type', 'const', 'proctype', 'enum', 'set');
|
|
|
|
+
|
|
|
|
+ ProcOptionNames: array[TPpuProcOption] of string =
|
|
|
|
+ ('Procedure', 'Function', 'Constructor', 'Destructor', 'Operator',
|
|
|
|
+ 'ClassMethod', 'Virtual', 'Abstract', 'Overriding', 'Overload', 'Inline');
|
|
|
|
+
|
|
|
|
+ DefVisibilityNames: array[TPpuDefVisibility] of string =
|
|
|
|
+ ('Public', 'Published', 'Protected', 'Private');
|
|
|
|
+
|
|
|
|
+ SymIdBit = $80000000;
|
|
|
|
+ InvalidId = cardinal(-1);
|
|
|
|
+ InvalidUnit = word(-1);
|
|
|
|
+
|
|
|
|
+function IsSymId(Id: cardinal): boolean; inline;
|
|
|
|
+begin
|
|
|
|
+ Result:=Id and SymIdBit <> 0;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+{ TPpuParamDef }
|
|
|
|
+
|
|
|
|
+constructor TPpuParamDef.Create(AParent: TPpuContainerDef);
|
|
|
|
+begin
|
|
|
|
+ inherited Create(AParent);
|
|
|
|
+ DefType:=dtParam;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+{ TPpuVarDef }
|
|
|
|
+
|
|
|
|
+procedure TPpuVarDef.WriteDef(Output: TPpuOutput);
|
|
|
|
+begin
|
|
|
|
+ inherited WriteDef(Output);
|
|
|
|
+ VarType.Write(Output, 'VarType');
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+constructor TPpuVarDef.Create(AParent: TPpuContainerDef);
|
|
|
|
+begin
|
|
|
|
+ inherited Create(AParent);
|
|
|
|
+ DefType:=dtVar;
|
|
|
|
+ VarType:=TPpuRef.Create;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+destructor TPpuVarDef.Destroy;
|
|
|
|
+begin
|
|
|
|
+ VarType.Free;
|
|
|
|
+ inherited Destroy;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+{ TPpuObjectDef }
|
|
|
|
+
|
|
|
|
+constructor TPpuObjectDef.Create(AParent: TPpuContainerDef);
|
|
|
|
+begin
|
|
|
|
+ inherited Create(AParent);
|
|
|
|
+ DefType:=dtObject;
|
|
|
|
+end;
|
|
|
|
|
|
{ TPpuRef }
|
|
{ TPpuRef }
|
|
|
|
|
|
constructor TPpuRef.Create;
|
|
constructor TPpuRef.Create;
|
|
begin
|
|
begin
|
|
- UnitIndex:=$FFFF;
|
|
|
|
- Id:=-1;
|
|
|
|
|
|
+ UnitIndex:=InvalidUnit;
|
|
|
|
+ Id:=InvalidId;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TPpuRef.Write(Output: TPpuOutput; const RefName: string);
|
|
procedure TPpuRef.Write(Output: TPpuOutput; const RefName: string);
|
|
begin
|
|
begin
|
|
with Output do
|
|
with Output do
|
|
- if Id < 0 then
|
|
|
|
|
|
+ if IsNull then
|
|
WriteNull(RefName)
|
|
WriteNull(RefName)
|
|
else begin
|
|
else begin
|
|
WriteObjectStart(RefName);
|
|
WriteObjectStart(RefName);
|
|
- if UnitIndex <> $FFFF then
|
|
|
|
- WriteInt('RefUnit', UnitIndex);
|
|
|
|
|
|
+ if not IsCurUnit then
|
|
|
|
+ WriteInt('Unit', UnitIndex);
|
|
WriteInt('Id', Id);
|
|
WriteInt('Id', Id);
|
|
WriteObjectEnd;
|
|
WriteObjectEnd;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TPpuRef.IsCurUnit: boolean;
|
|
|
|
+begin
|
|
|
|
+ Result:=UnitIndex = InvalidUnit;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TPpuRef.IsNull: boolean;
|
|
|
|
+begin
|
|
|
|
+ Result:=Id = InvalidId;
|
|
|
|
+end;
|
|
|
|
+
|
|
{ TPpuProcTypeDef }
|
|
{ TPpuProcTypeDef }
|
|
|
|
|
|
constructor TPpuProcTypeDef.Create(AParent: TPpuContainerDef);
|
|
constructor TPpuProcTypeDef.Create(AParent: TPpuContainerDef);
|
|
@@ -211,16 +316,27 @@ end;
|
|
|
|
|
|
{ TPpuProcDef }
|
|
{ TPpuProcDef }
|
|
|
|
|
|
-procedure TPpuProcDef.WriteDef(Output: TPpuOutput);
|
|
|
|
-begin
|
|
|
|
- inherited WriteDef(Output);
|
|
|
|
- ReturnType.Write(Output, 'ReturnType');
|
|
|
|
|
|
+procedure TPpuProcDef.BeforeWriteItems(Output: TPpuOutput);
|
|
|
|
+var
|
|
|
|
+ opt: TPpuProcOption;
|
|
|
|
+begin
|
|
|
|
+ inherited BeforeWriteItems(Output);
|
|
|
|
+ if Options <> [] then begin
|
|
|
|
+ Output.WriteArrayStart('Options');
|
|
|
|
+ for opt:=Low(TPpuProcOption) to High(TPpuProcOption) do
|
|
|
|
+ if opt in Options then
|
|
|
|
+ Output.WriteStr('', ProcOptionNames[opt]);
|
|
|
|
+ Output.WriteArrayEnd;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ ReturnType.Write(Output, 'RetType');
|
|
end;
|
|
end;
|
|
|
|
|
|
constructor TPpuProcDef.Create(AParent: TPpuContainerDef);
|
|
constructor TPpuProcDef.Create(AParent: TPpuContainerDef);
|
|
begin
|
|
begin
|
|
inherited Create(AParent);
|
|
inherited Create(AParent);
|
|
DefType:=dtProc;
|
|
DefType:=dtProc;
|
|
|
|
+ ItemsName:='Params';
|
|
ReturnType:=TPpuRef.Create;
|
|
ReturnType:=TPpuRef.Create;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -367,7 +483,7 @@ begin
|
|
WriteStr('InterfaceCRC', hexStr(IntfCrc, 8));
|
|
WriteStr('InterfaceCRC', hexStr(IntfCrc, 8));
|
|
UsedUnits.WriteDef(Output);
|
|
UsedUnits.WriteDef(Output);
|
|
if Length(RefUnits) > 0 then begin
|
|
if Length(RefUnits) > 0 then begin
|
|
- WriteArrayStart('RefUnits');
|
|
|
|
|
|
+ WriteArrayStart('Units');
|
|
for i:=0 to High(RefUnits) do
|
|
for i:=0 to High(RefUnits) do
|
|
WriteStr('', RefUnits[i]);
|
|
WriteStr('', RefUnits[i]);
|
|
WriteArrayEnd;
|
|
WriteArrayEnd;
|
|
@@ -384,10 +500,10 @@ begin
|
|
ItemsName:='Interface';
|
|
ItemsName:='Interface';
|
|
UsedUnits:=TPpuContainerDef.Create(nil);
|
|
UsedUnits:=TPpuContainerDef.Create(nil);
|
|
UsedUnits.FParent:=Self;
|
|
UsedUnits.FParent:=Self;
|
|
- UsedUnits.ItemsName:='UsedUnits';
|
|
|
|
|
|
+ UsedUnits.ItemsName:='Uses';
|
|
SourceFiles:=TPpuContainerDef.Create(nil);
|
|
SourceFiles:=TPpuContainerDef.Create(nil);
|
|
SourceFiles.FParent:=Self;
|
|
SourceFiles.FParent:=Self;
|
|
- SourceFiles.ItemsName:='SrcFiles';
|
|
|
|
|
|
+ SourceFiles.ItemsName:='Files';
|
|
FIndexById:=THashSet.Create(64, True, False);
|
|
FIndexById:=THashSet.Create(64, True, False);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -399,11 +515,18 @@ begin
|
|
inherited Destroy;
|
|
inherited Destroy;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TPpuUnitDef.FindById(AId: integer): TPpuDef;
|
|
|
|
|
|
+function TPpuUnitDef.FindById(AId: integer; FindSym: boolean): TPpuDef;
|
|
var
|
|
var
|
|
h: PHashSetItem;
|
|
h: PHashSetItem;
|
|
|
|
+ i: cardinal;
|
|
begin
|
|
begin
|
|
- h:=FIndexById.Find(@AId, SizeOf(AId));
|
|
|
|
|
|
+ Result:=nil;
|
|
|
|
+ if AId = -1 then
|
|
|
|
+ exit;
|
|
|
|
+ i:=AId;
|
|
|
|
+ if FindSym then
|
|
|
|
+ i:=i or SymIdBit;
|
|
|
|
+ h:=FIndexById.Find(@i, SizeOf(i));
|
|
if h <> nil then
|
|
if h <> nil then
|
|
Result:=TPpuDef(h^.Data)
|
|
Result:=TPpuDef(h^.Data)
|
|
else
|
|
else
|
|
@@ -433,6 +556,7 @@ var
|
|
i: integer;
|
|
i: integer;
|
|
begin
|
|
begin
|
|
inherited WriteDef(Output);
|
|
inherited WriteDef(Output);
|
|
|
|
+ BeforeWriteItems(Output);
|
|
if Count = 0 then
|
|
if Count = 0 then
|
|
exit;
|
|
exit;
|
|
Output.WriteArrayStart(ItemsName);
|
|
Output.WriteArrayStart(ItemsName);
|
|
@@ -441,6 +565,10 @@ begin
|
|
Output.WriteArrayEnd;
|
|
Output.WriteArrayEnd;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TPpuContainerDef.BeforeWriteItems(Output: TPpuOutput);
|
|
|
|
+begin
|
|
|
|
+end;
|
|
|
|
+
|
|
constructor TPpuContainerDef.Create(AParent: TPpuContainerDef);
|
|
constructor TPpuContainerDef.Create(AParent: TPpuContainerDef);
|
|
begin
|
|
begin
|
|
inherited Create(AParent);
|
|
inherited Create(AParent);
|
|
@@ -471,6 +599,14 @@ begin
|
|
Result:=DefTypeNames[DefType];
|
|
Result:=DefTypeNames[DefType];
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TPpuDef.GetId: cardinal;
|
|
|
|
+begin
|
|
|
|
+ if FId = InvalidId then
|
|
|
|
+ Result:=InvalidId
|
|
|
|
+ else
|
|
|
|
+ Result:=FId and not SymIdBit;
|
|
|
|
+end;
|
|
|
|
+
|
|
function TPpuDef.GetParentUnit: TPpuUnitDef;
|
|
function TPpuDef.GetParentUnit: TPpuUnitDef;
|
|
var
|
|
var
|
|
d: TPpuContainerDef;
|
|
d: TPpuContainerDef;
|
|
@@ -484,49 +620,66 @@ begin
|
|
Result:=FParentUnit;
|
|
Result:=FParentUnit;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TPpuDef.SetId(AValue: integer);
|
|
|
|
|
|
+procedure TPpuDef.SetId(AValue: cardinal);
|
|
var
|
|
var
|
|
h: PHashSetItem;
|
|
h: PHashSetItem;
|
|
u: TPpuUnitDef;
|
|
u: TPpuUnitDef;
|
|
begin
|
|
begin
|
|
if FId = AValue then Exit;
|
|
if FId = AValue then Exit;
|
|
u:=ParentUnit;
|
|
u:=ParentUnit;
|
|
- if (FId <> -1) and (u <> nil) then begin
|
|
|
|
|
|
+ if (FId <> InvalidId) and (u <> nil) then begin
|
|
h:=u.FIndexById.Find(@FId, SizeOf(FId));
|
|
h:=u.FIndexById.Find(@FId, SizeOf(FId));
|
|
if h <> nil then
|
|
if h <> nil then
|
|
u.FIndexById.Remove(h);
|
|
u.FIndexById.Remove(h);
|
|
end;
|
|
end;
|
|
FId:=AValue;
|
|
FId:=AValue;
|
|
- if (FId <> -1) and (u <> nil) then begin;
|
|
|
|
|
|
+ if (FId <> InvalidId) and (u <> nil) then begin;
|
|
h:=u.FIndexById.FindOrAdd(@FId, SizeOf(FId));
|
|
h:=u.FIndexById.FindOrAdd(@FId, SizeOf(FId));
|
|
h^.Data:=Self;
|
|
h^.Data:=Self;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TPpuDef.SetSymId(AId: integer);
|
|
|
|
+begin
|
|
|
|
+ Id:=cardinal(AId) or SymIdBit;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TPpuDef.WriteDef(Output: TPpuOutput);
|
|
procedure TPpuDef.WriteDef(Output: TPpuOutput);
|
|
begin
|
|
begin
|
|
with Output do begin
|
|
with Output do begin
|
|
- if Id >= 0 then
|
|
|
|
- WriteInt('Id', Id);
|
|
|
|
|
|
+ if FId <> InvalidId then
|
|
|
|
+ if IsSymId(FId) then
|
|
|
|
+ WriteInt('SymId', Id)
|
|
|
|
+ else begin
|
|
|
|
+ WriteInt('Id', Id);
|
|
|
|
+ if not Ref.IsNull then
|
|
|
|
+ WriteInt('SymId', Ref.Id);
|
|
|
|
+ end;
|
|
if FilePos.Line > 0 then begin
|
|
if FilePos.Line > 0 then begin
|
|
- WriteObjectStart('SrcPos');
|
|
|
|
- WriteInt('SrcFile', FilePos.FileIndex);
|
|
|
|
|
|
+ WriteObjectStart('Pos');
|
|
|
|
+ if FilePos.FileIndex > 0 then
|
|
|
|
+ WriteInt('File', FilePos.FileIndex);
|
|
WriteInt('Line', FilePos.Line);
|
|
WriteInt('Line', FilePos.Line);
|
|
WriteInt('Col', FilePos.Col);
|
|
WriteInt('Col', FilePos.Col);
|
|
WriteObjectEnd;
|
|
WriteObjectEnd;
|
|
end;
|
|
end;
|
|
|
|
+ if Visibility <> dvPublic then
|
|
|
|
+ WriteStr('Visibility', DefVisibilityNames[Visibility]);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
constructor TPpuDef.Create(AParent: TPpuContainerDef);
|
|
constructor TPpuDef.Create(AParent: TPpuContainerDef);
|
|
begin
|
|
begin
|
|
- FId:=-1;
|
|
|
|
|
|
+ FId:=InvalidId;
|
|
|
|
+ Ref:=TPpuRef.Create;
|
|
|
|
+ Visibility:=dvPublic;
|
|
if AParent <> nil then
|
|
if AParent <> nil then
|
|
AParent.Add(Self);
|
|
AParent.Add(Self);
|
|
end;
|
|
end;
|
|
|
|
|
|
destructor TPpuDef.Destroy;
|
|
destructor TPpuDef.Destroy;
|
|
begin
|
|
begin
|
|
|
|
+ Ref.Free;
|
|
inherited Destroy;
|
|
inherited Destroy;
|
|
end;
|
|
end;
|
|
|
|
|