Skip to content

Commit 23af861

Browse files
committed
@TetzkatLipHoka Feature extension
@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
1 parent c94f1d9 commit 23af861

File tree

1 file changed

+118
-5
lines changed

1 file changed

+118
-5
lines changed

Source/uPSCompiler.pas

Lines changed: 118 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ uPSCompiler.pas } // version: 2022.1123.1400
1+
{ uPSCompiler.pas } // version: 2022.1123.1500
22
{----------------------------------------------------------------------------}
33
{ RemObjects Pascal Script }
44
{----------------------------------------------------------------------------}
@@ -939,8 +939,31 @@ TPSPascalCompiler = class
939939
function AddTypeS(const Name, Decl: tbtString): TPSType;
940940
function AddTypeCopy(const Name: tbtString; TypeNo: TPSType): TPSType;
941941
function AddTypeCopyN(const Name, FType: tbtString): TPSType;
942-
function AddConstant(const Name: tbtString; FType: TPSType): TPSConstant;
942+
function AddConstant(const Name: tbtString; FType: TPSType): TPSConstant; overload;
943943
function AddConstantN(const Name, FType: tbtString): TPSConstant;
944+
945+
// function AddConstant(const Name: tbtString; const Value ): TPSConstant; overload;
946+
function AddConstant(const Name: tbtString; const Value: Integer): TPSConstant; overload;
947+
function AddConstant(const Name: tbtString; const Value: Cardinal): TPSConstant; overload;
948+
{$IFNDEF PS_NOINT64}
949+
function AddConstant(const Name: tbtString; const Value: Int64): TPSConstant; overload;
950+
{$ENDIF PS_NOINT64}
951+
// {$IFNDEF PS_NOUINT64}
952+
// function AddConstant(const Name: tbtString; const Value: UInt64): TPSConstant; overload;
953+
// {$ENDIF PS_NOUINT64}
954+
function AddConstant(const Name: tbtString; const Value: tbtString): TPSConstant; overload;
955+
function AddConstant(const Name: tbtString; const Value: tbtChar): TPSConstant; overload;
956+
{$IFNDEF PS_NOWIDESTRING}
957+
{$if defined(UNICODE) and not defined(PS_BTSTRINGNATIVE)} // WideChar == tbtChar
958+
function AddConstant(const Name: tbtString; const Value: WideChar): TPSConstant; overload;
959+
{$ifend}
960+
function AddConstant(const Name: tbtString; const Value: tbtWideString): TPSConstant; overload;
961+
{$IFDEF UNICODE}
962+
function AddConstant(const Name: tbtString; const Value: tbtUnicodeString): TPSConstant; overload;
963+
{$ENDIF}
964+
{$ENDIF PS_NOWIDESTRING}
965+
function AddConstant(const Name: tbtString; const Value: Extended): TPSConstant; overload;
966+
944967
function AddVariable(const Name: tbtString; FType: TPSType): TPSVar;
945968
function AddVariableN(const Name, FType: tbtString): TPSVar;
946969
function AddUsedVariable(const Name: tbtString; FType: TPSType): TPSVar;
@@ -11280,7 +11303,7 @@ function TPSPascalCompiler.Compile(const s: TbtString): Boolean;
1128011303
end;
1128111304
fUnit.AddUses(S);
1128211305
if Parse then begin
11283-
{$ENDIF PS_USESSUPPORT}
11306+
//{$ENDIF PS_USESSUPPORT}
1128411307
FUses.Add(s);
1128511308
if @FOnUses <> nil then begin
1128611309
try
@@ -11315,9 +11338,13 @@ function TPSPascalCompiler.Compile(const s: TbtString): Boolean;
1131511338
end;
1131611339
end;
1131711340
end;
11318-
{$IFDEF PS_USESSUPPORT}
11341+
//{$IFDEF PS_USESSUPPORT}
1131911342
end;
11320-
{$ENDIF}
11343+
{$ELSE ! PS_USESSUPPORT}
11344+
MakeError('', ecUnknownIdentifier, S);
11345+
Result := False;
11346+
Exit;
11347+
{$ENDIF ! PS_USESSUPPORT}
1132111348
FParser.Next;
1132211349
if FParser.CurrTokenID = CSTI_Semicolon then
1132311350
Break
@@ -11724,6 +11751,7 @@ procedure TPSPascalCompiler.DefineStandardTypes;
1172411751
i: Longint;
1172511752
begin
1172611753
AddType('Byte', btU8);
11754+
AddTypeCopyN('UCHAR', 'Byte'); // Unsigned Char
1172711755
FDefaultBoolType := AddTypeS('Boolean', '(False, True)');
1172811756
FDefaultBoolType.ExportName := True;
1172911757

@@ -11807,25 +11835,36 @@ procedure TPSPascalCompiler.DefineStandardTypes;
1180711835
FAnyMethod := AddTypeS('AnyMethod', 'procedure');
1180811836
AddType('ShortInt', btS8);
1180911837
AddType('Word', btU16);
11838+
AddTypeCopyN('USHORT', 'Word');
1181011839
AddType('SmallInt', btS16);
11840+
AddTypeCopyN('SHORT', 'SmallInt');
1181111841
AddType('LongInt', btS32);
11842+
AddTypeCopyN('LONG', 'LongInt');
1181211843
at2ut(AddType('___Pointer', btPointer));
1181311844
AddType('LongWord', btU32);
1181411845
AddTypeCopyN('Integer', 'LongInt');
11846+
AddTypeCopyN('FixedInt', 'LongInt');
1181511847
AddTypeCopyN('Cardinal', 'LongWord');
1181611848
{+} {+.}
11849+
AddTypeCopyN('UINT', 'LongWord');
11850+
AddTypeCopyN('ULONG', 'LongWord');
11851+
AddTypeCopyN('ULONG32', 'LongWord');
1181711852
{$IFNDEF PS_NOINT64}
1181811853
AddType('Int64', btS64);
1181911854
AddType('UInt64', btU64);
11855+
AddTypeCopyN('LONG64', 'Int64');
11856+
AddTypeCopyN('LONGLONG', 'Int64');
1182011857
{$ENDIF}
1182111858
{+}
1182211859
//PointerSize = IPointer({$IFDEF CPU64}8{$ELSE}4{$ENDIF});
1182311860
{$IFNDEF PS_NOINT64}
1182411861
AddType('NativeInt', {$IFDEF CPU64}btS64{$ELSE}btS32{$ENDIF});
1182511862
AddType('NativeUInt', {$IFDEF CPU64}btU64{$ELSE}btU32{$ENDIF});
11863+
//AddTypeCopyN('THandle', 'Int64'); //unit uPSC_classes
1182611864
{$ELSE}
1182711865
AddType('NativeInt', btS32);
1182811866
AddType('NativeUInt', btU32);
11867+
//AddTypeCopyN('THandle', 'LongWord'); //unit uPSC_classes
1182911868
{$ENDIF}
1183011869
//AddType('Pointer', btPointer);
1183111870
AddTypeCopyN('Pointer', 'NativeUInt');
@@ -12846,6 +12885,80 @@ function TPSPascalCompiler.AddConstantN(const Name, FType: tbtString): TPSConsta
1284612885
Result := AddConstant(Name, FindType(FType)); // is handle nil type
1284712886
end;
1284812887

12888+
//function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value ): TPSConstant;
12889+
//begin
12890+
// Result := AddConstant(Name, FindType('Set') );
12891+
// Result.SetSet(Value);
12892+
//end;
12893+
12894+
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: Integer): TPSConstant;
12895+
begin
12896+
Result := AddConstant(Name, FindType('Integer') ); // LONGINT
12897+
Result.SetInt(Value);
12898+
end;
12899+
12900+
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: Cardinal): TPSConstant;
12901+
begin
12902+
Result := AddConstant(Name, FindType('Cardinal') ); // LONGWORD
12903+
Result.SetUInt(Value);
12904+
end;
12905+
12906+
{$IFNDEF PS_NOINT64}
12907+
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: Int64): TPSConstant;
12908+
begin
12909+
Result := AddConstant(Name, FindType('Int64') ); // INT64
12910+
Result.SetInt64(Value);
12911+
end;
12912+
{$ENDIF PS_NOINT64}
12913+
12914+
//{$IFNDEF PS_NOUINT64}
12915+
//function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: UInt64): TPSConstant;
12916+
//begin
12917+
// Result := AddConstant(Name, FindType('UInt64') ); // UINT64
12918+
// Result.SetUInt64(Value);
12919+
//end;
12920+
//{$ENDIF PS_NOUINT64}
12921+
12922+
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: tbtString): TPSConstant;
12923+
begin
12924+
Result := AddConstant(Name, FindType('String') ); // STRING
12925+
Result.SetString(Value);
12926+
end;
12927+
12928+
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: tbtChar): TPSConstant;
12929+
begin
12930+
Result := AddConstant(Name, FindType('Char') ); // ANSICHAR
12931+
Result.SetChar(Value);
12932+
end;
12933+
12934+
{$IFNDEF PS_NOWIDESTRING}
12935+
{$if defined(UNICODE) and not defined(PS_BTSTRINGNATIVE)} // WideChar == tbtChar
12936+
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: WideChar): TPSConstant;
12937+
begin
12938+
Result := AddConstant(Name, FindType('WideChar') ); // WIDECHAR
12939+
Result.SetWideChar(Value);
12940+
end;
12941+
{$ifend}
12942+
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: tbtWideString): TPSConstant;
12943+
begin
12944+
Result := AddConstant(Name, FindType('WideString') ); // WIDESTRING
12945+
Result.SetWideString(Value);
12946+
end;
12947+
{$IFDEF UNICODE}
12948+
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: tbtUnicodeString): TPSConstant;
12949+
begin
12950+
Result := AddConstant(Name, FindType('UnicodeString') ); // UNICODESTRING
12951+
Result.SetUnicodeString(Value);
12952+
end;
12953+
{$ENDIF UNICODE}
12954+
{$ENDIF PS_NOWIDESTRING}
12955+
12956+
function TPSPascalCompiler.AddConstant(const Name: tbtString; const Value: Extended): TPSConstant;
12957+
begin
12958+
Result := AddConstant(Name, FindType('Extended') ); // EXTENDED
12959+
Result.SetExtended(Value);
12960+
end;
12961+
1284912962
function TPSPascalCompiler.AddTypeCopy(const Name: tbtString; TypeNo: TPSType): TPSType;
1285012963
begin
1285112964
if FProcs = nil then

0 commit comments

Comments
 (0)