Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions Package/pascalast.lpk
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="5">
<PathDelim Value="\"/>
<Name Value="PascalAST"/>
<Type Value="RunAndDesignTime"/>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="..\Source\SimpleParser"/>
<OtherUnitFiles Value="..\Source;..\Source\FreePascalSupport;..\Source\FreePascalSupport\FPC_StringBuilder;..\Source\FreePascalSupport\FPC_StringBuilder\Src;..\Source\SimpleParser"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<SyntaxMode Value="Delphi"/>
</SyntaxOptions>
</Parsing>
</CompilerOptions>
<Files>
<Item>
<Filename Value="..\Source\DelphiAST.Writer.pas"/>
<UnitName Value="DelphiAST.Writer"/>
</Item>
<Item>
<Filename Value="..\Source\StringPool.pas"/>
<UnitName Value="StringPool"/>
</Item>
<Item>
<Filename Value="..\Source\DelphiAST.Consts.pas"/>
<UnitName Value="DelphiAST.Consts"/>
</Item>
<Item>
<Filename Value="..\Source\DelphiAST.pas"/>
<UnitName Value="DelphiAST"/>
</Item>
<Item>
<Filename Value="..\Source\DelphiAST.ProjectIndexer.pas"/>
<UnitName Value="DelphiAST.ProjectIndexer"/>
</Item>
<Item>
<Filename Value="..\Source\DelphiAST.Serialize.Binary.pas"/>
<UnitName Value="DelphiAST.Serialize.Binary"/>
</Item>
<Item>
<Filename Value="..\Source\DelphiAST.SimpleParserEx.pas"/>
<UnitName Value="DelphiAST.SimpleParserEx"/>
</Item>
<Item>
<Filename Value="..\Source\FreePascalSupport\Diagnostics.pas"/>
<UnitName Value="Diagnostics"/>
</Item>
<Item>
<Filename Value="..\Source\FreePascalSupport\IOUtils.pas"/>
<UnitName Value="IOUtils"/>
</Item>
<Item>
<Filename Value="..\Source\SimpleParser\SimpleParser.Types.pas"/>
<UnitName Value="SimpleParser.Types"/>
</Item>
<Item>
<Filename Value="..\Source\SimpleParser\SimpleParser.Lexer.pas"/>
<UnitName Value="SimpleParser.Lexer"/>
</Item>
<Item>
<Filename Value="..\Source\SimpleParser\SimpleParser.Lexer.Types.pas"/>
<UnitName Value="SimpleParser.Lexer.Types"/>
</Item>
<Item>
<Filename Value="..\Source\SimpleParser\SimpleParser.pas"/>
<UnitName Value="SimpleParser"/>
</Item>
<Item>
<Filename Value="..\Source\SimpleParser\SimplerParser.Lexer.Config.pas"/>
<UnitName Value="SimplerParser.Lexer.Config"/>
</Item>
</Files>
<RequiredPkgs>
<Item>
<PackageName Value="LazUtils"/>
</Item>
<Item>
<PackageName Value="FCL"/>
</Item>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
</Package>
</CONFIG>
25 changes: 25 additions & 0 deletions Package/pascalast.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install the package.
}

unit PascalAST;

{$warn 5023 off : no warning about unused units}
interface

uses
DelphiAST.Writer, StringPool, DelphiAST.Consts, DelphiAST,
DelphiAST.ProjectIndexer, DelphiAST.Serialize.Binary,
DelphiAST.SimpleParserEx, Diagnostics, IOUtils, SimpleParser.Types,
SimpleParser.Lexer, SimpleParser.Lexer.Types, SimpleParser,
SimplerParser.Lexer.Config, LazarusPackageIntf;

implementation

procedure Register;
begin
end;

initialization
RegisterPackage('PascalAST', @Register);
end.
54 changes: 39 additions & 15 deletions Source/DelphiAST.ProjectIndexer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ TUnitInfo = record
end;
end;

TUnitComparer = class (TComparer<TUnitInfo>)
public
function Compare(constref ALeft, ARight: TUnitInfo): Integer; override;
end;

TParsedUnits = class(TList<TUnitInfo>)
protected
procedure Initialize(parsedUnits: TParsedUnitsCache; unitPaths: TUnitPathsCache);
Expand All @@ -52,6 +57,11 @@ TIncludeFileInfo = record
Path: string;
end;

TIncludeFileComparer = class (TComparer<TIncludeFileInfo>)
public
function Compare(constref ALeft, ARight: TIncludeFileInfo): Integer; override;
end;

TIncludeFiles = class(TList<TIncludeFileInfo>)
protected
procedure Initialize(includeCache: TIncludeCache);
Expand All @@ -72,9 +82,9 @@ TProblems = class(TList<TProblemInfo>)
strict private type
TIncludeHandler = class(TInterfacedObject, IIncludeHandler)
strict private
[weak] FIncludeCache: TIncludeCache;
[weak] FIndexer : TProjectIndexer;
[weak] FProblems : TProblems;
FIncludeCache: TIncludeCache;
FIndexer : TProjectIndexer;
FProblems : TProblems;
FUnitFile : string;
FUnitFileFolder : string;
public
Expand Down Expand Up @@ -141,6 +151,30 @@ implementation
SysUtils,
SimpleParser;

function IsRelativePath(s : String) : boolean;
begin
{$IFDEF WINDOWS}
result := not (s.contains(':'));
{$ELSE}
result := not s.startsWith('\');
{$ENDIF}
end;

{ TProjectIndexer.TUnitComparer }

function TProjectIndexer.TUnitComparer.Compare(constref ALeft, ARight: TUnitInfo): Integer;
begin
Result := TOrdinalIStringComparer(TIStringComparer.Ordinal).Compare(ALeft.Name, ARight.Name);
end;

{ TProjectIndexer.TIncludeFileComparer }

function TProjectIndexer.TIncludeFileComparer.Compare(constref ALeft, ARight: TIncludeFileInfo): Integer;
begin
Result := TOrdinalIStringComparer(TIStringComparer.Ordinal).Compare(ALeft.Name, ARight.Name);
end;


{ TProjectIndexer.TParsedUnits }

procedure TProjectIndexer.TParsedUnits.Initialize(parsedUnits: TParsedUnitsCache;
Expand Down Expand Up @@ -168,12 +202,7 @@ procedure TProjectIndexer.TParsedUnits.Initialize(parsedUnits: TParsedUnitsCache
end;

TrimExcess;
Sort(
TComparer<TUnitInfo>.Construct(
function(const Left, Right: TUnitInfo): integer
begin
Result := TOrdinalIStringComparer(TIStringComparer.Ordinal).Compare(Left.Name, Right.Name);
end));
Sort(TUnitComparer.create);
end;

{ TProjectIndexer.TIncludeFiles }
Expand All @@ -198,12 +227,7 @@ procedure TProjectIndexer.TIncludeFiles.Initialize(includeCache: TIncludeCache);
end;

TrimExcess;
Sort(
TComparer<TIncludeFileInfo>.Construct(
function(const Left, Right: TIncludeFileInfo): integer
begin
Result := TOrdinalIStringComparer(TIStringComparer.Ordinal).Compare(Left.Name, Right.Name);
end));
Sort(TIncludeFileComparer.create);
end;

{ TProjectIndexer.TProblems }
Expand Down
7 changes: 7 additions & 0 deletions Source/DelphiAST.Serialize.Binary.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ implementation
uses
SysUtils;

{$IFDEF FPC}
function UTF8ToUnicodeString(s : String) : String;
begin
result := s;
end;
{$ENDIF}

var
CSignature: AnsiString = 'DAST binary file'#26;

Expand Down
8 changes: 7 additions & 1 deletion Source/FreePascalSupport/Diagnostics.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ interface
{$IFDEF LINUX}
,unixtype, linux
{$ENDIF LINUX}
{$IFDEF DARWIN}
, unixtype
{$ENDIF}
;

type
Expand All @@ -43,7 +46,10 @@ TStopWatch = record
Int64;
{$ENDIF WINDOWS}
{$IFDEF LINUX}
TTimeSpec;
TTimeSpec;
{$ENDIF LINUX}
{$IFDEF DARWIN}
TTimeSpec;
{$ENDIF LINUX}
strict private
class var FFrequency : Int64;
Expand Down
1 change: 1 addition & 0 deletions Source/SimpleParser/SimpleParser.Lexer.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ interface
ptExit,
ptExport,
ptExports,
ptExtdecl,
ptExtended,
ptExternal,
ptFar,
Expand Down
Loading