Skip to content

Commit

Permalink
@TetzkatLipHoka Feature extension
Browse files Browse the repository at this point in the history
@TetzkatLipHoka: Feature extension remobjects#265

Added/Enabled PS_USESSUPPORT define
Fixed an issue with uses error handling
Added AddConstant overloads for easier adding
Added Next-Gen Delphi basic types with AddTypeCopyN - to extend support of 'native' Delphi units via uses
  • Loading branch information
pult committed Nov 23, 2022
1 parent c94f1d9 commit 23af861
Showing 1 changed file with 118 additions and 5 deletions.
123 changes: 118 additions & 5 deletions Source/uPSCompiler.pas
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ uPSCompiler.pas } // version: 2022.1123.1400
{ uPSCompiler.pas } // version: 2022.1123.1500
{----------------------------------------------------------------------------}
{ RemObjects Pascal Script }
{----------------------------------------------------------------------------}
Expand Down Expand Up @@ -939,8 +939,31 @@ TPSPascalCompiler = class
function AddTypeS(const Name, Decl: tbtString): TPSType;
function AddTypeCopy(const Name: tbtString; TypeNo: TPSType): TPSType;
function AddTypeCopyN(const Name, FType: tbtString): TPSType;
function AddConstant(const Name: tbtString; FType: TPSType): TPSConstant;
function AddConstant(const Name: tbtString; FType: TPSType): TPSConstant; overload;
function AddConstantN(const Name, FType: tbtString): TPSConstant;

// function AddConstant(const Name: tbtString; const Value ): TPSConstant; overload;
function AddConstant(const Name: tbtString; const Value: Integer): TPSConstant; overload;
function AddConstant(const Name: tbtString; const Value: Cardinal): TPSConstant; overload;
{$IFNDEF PS_NOINT64}
function AddConstant(const Name: tbtString; const Value: Int64): TPSConstant; overload;
{$ENDIF PS_NOINT64}
// {$IFNDEF PS_NOUINT64}
// function AddConstant(const Name: tbtString; const Value: UInt64): TPSConstant; overload;
// {$ENDIF PS_NOUINT64}
function AddConstant(const Name: tbtString; const Value: tbtString): TPSConstant; overload;
function AddConstant(const Name: tbtString; const Value: tbtChar): TPSConstant; overload;
{$IFNDEF PS_NOWIDESTRING}
{$if defined(UNICODE) and not defined(PS_BTSTRINGNATIVE)} // WideChar == tbtChar
function AddConstant(const Name: tbtString; const Value: WideChar): TPSConstant; overload;
{$ifend}
function AddConstant(const Name: tbtString; const Value: tbtWideString): TPSConstant; overload;
{$IFDEF UNICODE}
function AddConstant(const Name: tbtString; const Value: tbtUnicodeString): TPSConstant; overload;
{$ENDIF}
{$ENDIF PS_NOWIDESTRING}
function AddConstant(const Name: tbtString; const Value: Extended): TPSConstant; overload;

function AddVariable(const Name: tbtString; FType: TPSType): TPSVar;
function AddVariableN(const Name, FType: tbtString): TPSVar;
function AddUsedVariable(const Name: tbtString; FType: TPSType): TPSVar;
Expand Down Expand Up @@ -11280,7 +11303,7 @@ function TPSPascalCompiler.Compile(const s: TbtString): Boolean;
end;
fUnit.AddUses(S);
if Parse then begin
{$ENDIF PS_USESSUPPORT}
//{$ENDIF PS_USESSUPPORT}
FUses.Add(s);
if @FOnUses <> nil then begin
try
Expand Down Expand Up @@ -11315,9 +11338,13 @@ function TPSPascalCompiler.Compile(const s: TbtString): Boolean;
end;
end;
end;
{$IFDEF PS_USESSUPPORT}
//{$IFDEF PS_USESSUPPORT}
end;
{$ENDIF}
{$ELSE ! PS_USESSUPPORT}
MakeError('', ecUnknownIdentifier, S);
Result := False;
Exit;
{$ENDIF ! PS_USESSUPPORT}
FParser.Next;
if FParser.CurrTokenID = CSTI_Semicolon then
Break
Expand Down Expand Up @@ -11724,6 +11751,7 @@ procedure TPSPascalCompiler.DefineStandardTypes;
i: Longint;
begin
AddType('Byte', btU8);
AddTypeCopyN('UCHAR', 'Byte'); // Unsigned Char
FDefaultBoolType := AddTypeS('Boolean', '(False, True)');
FDefaultBoolType.ExportName := True;

Expand Down Expand Up @@ -11807,25 +11835,36 @@ procedure TPSPascalCompiler.DefineStandardTypes;
FAnyMethod := AddTypeS('AnyMethod', 'procedure');
AddType('ShortInt', btS8);
AddType('Word', btU16);
AddTypeCopyN('USHORT', 'Word');
AddType('SmallInt', btS16);
AddTypeCopyN('SHORT', 'SmallInt');
AddType('LongInt', btS32);
AddTypeCopyN('LONG', 'LongInt');
at2ut(AddType('___Pointer', btPointer));
AddType('LongWord', btU32);
AddTypeCopyN('Integer', 'LongInt');
AddTypeCopyN('FixedInt', 'LongInt');
AddTypeCopyN('Cardinal', 'LongWord');
{+} {+.}
AddTypeCopyN('UINT', 'LongWord');
AddTypeCopyN('ULONG', 'LongWord');
AddTypeCopyN('ULONG32', 'LongWord');
{$IFNDEF PS_NOINT64}
AddType('Int64', btS64);
AddType('UInt64', btU64);
AddTypeCopyN('LONG64', 'Int64');
AddTypeCopyN('LONGLONG', 'Int64');
{$ENDIF}
{+}
//PointerSize = IPointer({$IFDEF CPU64}8{$ELSE}4{$ENDIF});
{$IFNDEF PS_NOINT64}
AddType('NativeInt', {$IFDEF CPU64}btS64{$ELSE}btS32{$ENDIF});
AddType('NativeUInt', {$IFDEF CPU64}btU64{$ELSE}btU32{$ENDIF});
//AddTypeCopyN('THandle', 'Int64'); //unit uPSC_classes
{$ELSE}
AddType('NativeInt', btS32);
AddType('NativeUInt', btU32);
//AddTypeCopyN('THandle', 'LongWord'); //unit uPSC_classes
{$ENDIF}
//AddType('Pointer', btPointer);
AddTypeCopyN('Pointer', 'NativeUInt');
Expand Down Expand Up @@ -12846,6 +12885,80 @@ function TPSPascalCompiler.AddConstantN(const Name, FType: tbtString): TPSConsta
Result := AddConstant(Name, FindType(FType)); // is handle nil type
end;

//function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value ): TPSConstant;
//begin
// Result := AddConstant(Name, FindType('Set') );
// Result.SetSet(Value);
//end;

function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: Integer): TPSConstant;
begin
Result := AddConstant(Name, FindType('Integer') ); // LONGINT
Result.SetInt(Value);
end;

function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: Cardinal): TPSConstant;
begin
Result := AddConstant(Name, FindType('Cardinal') ); // LONGWORD
Result.SetUInt(Value);
end;

{$IFNDEF PS_NOINT64}
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: Int64): TPSConstant;
begin
Result := AddConstant(Name, FindType('Int64') ); // INT64
Result.SetInt64(Value);
end;
{$ENDIF PS_NOINT64}

//{$IFNDEF PS_NOUINT64}
//function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: UInt64): TPSConstant;
//begin
// Result := AddConstant(Name, FindType('UInt64') ); // UINT64
// Result.SetUInt64(Value);
//end;
//{$ENDIF PS_NOUINT64}

function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: tbtString): TPSConstant;
begin
Result := AddConstant(Name, FindType('String') ); // STRING
Result.SetString(Value);
end;

function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: tbtChar): TPSConstant;
begin
Result := AddConstant(Name, FindType('Char') ); // ANSICHAR
Result.SetChar(Value);
end;

{$IFNDEF PS_NOWIDESTRING}
{$if defined(UNICODE) and not defined(PS_BTSTRINGNATIVE)} // WideChar == tbtChar
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: WideChar): TPSConstant;
begin
Result := AddConstant(Name, FindType('WideChar') ); // WIDECHAR
Result.SetWideChar(Value);
end;
{$ifend}
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: tbtWideString): TPSConstant;
begin
Result := AddConstant(Name, FindType('WideString') ); // WIDESTRING
Result.SetWideString(Value);
end;
{$IFDEF UNICODE}
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: tbtUnicodeString): TPSConstant;
begin
Result := AddConstant(Name, FindType('UnicodeString') ); // UNICODESTRING
Result.SetUnicodeString(Value);
end;
{$ENDIF UNICODE}
{$ENDIF PS_NOWIDESTRING}

function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: Extended): TPSConstant;
begin
Result := AddConstant(Name, FindType('Extended') ); // EXTENDED
Result.SetExtended(Value);
end;

function TPSPascalCompiler.AddTypeCopy(const Name: tbtString; TypeNo: TPSType): TPSType;
begin
if FProcs = nil then
Expand Down

0 comments on commit 23af861

Please sign in to comment.