* Fix compilation with pas2js

This commit is contained in:
Michaël Van Canneyt 2023-10-22 17:35:47 +02:00
parent 74c995c06b
commit b4ccac8def
8 changed files with 48 additions and 9 deletions

View File

@ -68,6 +68,11 @@ uses
;
{$ENDIF FPC_DOTTEDUNITS}
{$IFDEF PAS2JS}
Type
AnsiString = String;
{$ENDIF}
const
Base64Chars = AnsiString('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');

View File

@ -39,6 +39,7 @@ uses
Type
{$ifdef pas2js}
TJSWriterString = UnicodeString;
AnsiChar = char;
{$else}
TJSWriterString = AnsiString;
{$endif}
@ -2283,11 +2284,15 @@ end;
function TTextWriter.WriteLn(const S: TJSWriterString): Integer;
begin
Result:=Write(S);
{$IFDEF PAS2JS}
Result:=Result+Write(LineBreak);
{$ELSE}
{$IF SIZEOF(Char)=1}
Result:=Result+Write(LineBreak);
{$else}
Result:=Result+Write(UTF8Encode(LineBreak));
{$ENDIF}
{$ENDIF}
end;
function TTextWriter.Write(const Fmt: TJSWriterString;

View File

@ -4295,7 +4295,7 @@ var
end;
{$ENDIF}
procedure AddSrc(h: AnsiString);
procedure AddSrc(h: {$IFDEF PAS2JS}String{$ELSE}AnsiString{$ENDIF});
{$ifdef FPC_HAS_CPSTRING}
var
ValueAnsi: TResEvalString;

View File

@ -15029,7 +15029,11 @@ begin
else
if (l=3) and (Value[3]='''') then
if Ord(Value[2])<128 then
{$IFNDEF PAS2JS}
Result:=btAnsiChar // e.g. 'a'
{$ELSE}
Result:=btWideChar
{$ENDIF}
else
Result:=btWideChar; // e.g. 'a'
end;

View File

@ -4702,7 +4702,7 @@ end;
function TPasVariable.GetDeclaration (full : boolean) : TPasTreeString;
Const
Seps : Array[Boolean] of AnsiChar = ('=',':');
Seps : Array[Boolean] of Char = ('=',':');
begin
If Assigned(VarType) then

View File

@ -1539,6 +1539,8 @@ function TPasParser.TryErrorRecovery(const aContext: TRecoveryContext): boolean;
var
StopAt : TTokens;
Obj : TObject;
begin
Inc(FErrorCount);
Result:=FErrorCount<FMaxErrorCount;
@ -1556,7 +1558,10 @@ begin
// Destroy element if engine allows it.
if Assigned(aContext.Element) then
if Engine.HandleResultOnError(aContext.Element) then
aContext.Element.Free;
begin
Obj:=aContext.Element;
Obj.Free;
end;
// ParseExc recorded the error message, force display
LogLastMessage;
StopAt:=aContext.RestartTokens;

View File

@ -127,13 +127,20 @@ resourcestring
SWarnIgnoringLinkLib = 'Ignoring LINKLIB directive %s -> %s (Options: %s)';
type
{$IF NOT DECLARED(RTLSTRING)}
RTLString = ansistring;
{$IFDEF PAS2JS}
RTLString = string;
TRTLStringDynArray = array of RTLString;
TPasScannerString = String;
AnsiChar = Char;
{$ELSE}
{$IF NOT DECLARED(RTLSTRING) }
RTLString = ansistring;
TRTLStringDynArray = array of RTLString;
{$ENDIF}
// String used for scanning
TPasScannerString = RawByteString;
{$ENDIF}
// String used for scanning
TPasScannerString = RawByteString;
// String used for interfacing with PasTree
TPasTreeString = String;
@ -490,7 +497,11 @@ type
TStreamLineReader = class(TLineReader)
private
{$ifndef pas2js}
FContent: RawByteString;
{$ELSE}
FContent: String;
{$ENDIF}
FPos : Integer;
public
{$ifdef HasStreams}
@ -2828,10 +2839,14 @@ end;
procedure TStreamLineReader.InitFromString(const s: TPasScannerString);
begin
{$IFDEF PAS2JS}
FContent:=S;
{$ELSE}
{$IF SIZEOF(CHAR)=2}
FContent:=UTF8Encode(s);
{$ELSE}
FContent:=S;
{$ENDIF}
{$ENDIF}
FPos:=0;
end;
@ -3728,7 +3743,7 @@ begin
else
begin
// skip identifier
if FTokenPos[0]='@' then
if {$ifdef UsePChar}FTokenPos[0]='@'{$ELSE} (FTokenPos<=l) and (s[FTokenPos]='@'){$ENDIF} then
inc(FTokenPos);
while {$ifdef UsePChar}FTokenPos[0] in IdentChars{$else}(FTokenPos<=l) and (s[FTokenPos] in IdentChars){$endif} do
inc(FTokenPos);
@ -5828,11 +5843,15 @@ end;
function TPascalScanner.GetTokenString: TPasTreeString;
begin
{$IFDEF PAS2JS}
Result:=RawCurTokenString;
{$ELSE}
{$IF SIZEOF(Char)=2}
Result:=UTF8Decode(RawCurTokenString);
{$ELSE}
Result:=RawCurTokenString;
{$ENDIF}
{$ENDIF}
end;
function TPascalScanner.IndexOfWarnMsgState(Number: integer; InsertPos: boolean

View File

@ -76,7 +76,8 @@ const
type
{$IFDEF Pas2JS}
Ansistring = String;
{ TPas2jsStream }
TPas2jsStream = class