mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 14:09:17 +02:00
pastojs: clean up, comments
git-svn-id: trunk@46724 -
This commit is contained in:
parent
13490e1af5
commit
37eb8c02f5
@ -472,7 +472,7 @@ uses
|
|||||||
{$endif}
|
{$endif}
|
||||||
Classes, SysUtils, math, contnrs,
|
Classes, SysUtils, math, contnrs,
|
||||||
jsbase, jstree, jswriter,
|
jsbase, jstree, jswriter,
|
||||||
PasTree, PScanner, PasResolveEval, PasResolver, PasUseAnalyzer;
|
PasTree, PScanner, PasResolveEval, PasResolver;
|
||||||
|
|
||||||
// message numbers
|
// message numbers
|
||||||
const
|
const
|
||||||
@ -621,7 +621,6 @@ type
|
|||||||
pbifnRecordAssign,
|
pbifnRecordAssign,
|
||||||
pbifnRecordClone,
|
pbifnRecordClone,
|
||||||
pbifnRecordCreateType,
|
pbifnRecordCreateType,
|
||||||
pbifnRecordCreateSpecializeType,
|
|
||||||
pbifnRecordEqual,
|
pbifnRecordEqual,
|
||||||
pbifnRecordNew,
|
pbifnRecordNew,
|
||||||
pbifnRTTIAddField, // typeinfos of tkclass and tkrecord have addField
|
pbifnRTTIAddField, // typeinfos of tkclass and tkrecord have addField
|
||||||
@ -802,7 +801,6 @@ const
|
|||||||
'$assign', // pbifnRecordAssign
|
'$assign', // pbifnRecordAssign
|
||||||
'$clone', // pbifnRecordClone
|
'$clone', // pbifnRecordClone
|
||||||
'recNewT', // pbifnRecordCreateType
|
'recNewT', // pbifnRecordCreateType
|
||||||
'recNewS', // pbifnRecordCreateSpecializeType
|
|
||||||
'$eq', // pbifnRecordEqual
|
'$eq', // pbifnRecordEqual
|
||||||
'$new', // pbifnRecordNew
|
'$new', // pbifnRecordNew
|
||||||
'addField', // pbifnRTTIAddField
|
'addField', // pbifnRTTIAddField
|
||||||
@ -1378,14 +1376,17 @@ type
|
|||||||
|
|
||||||
TPas2JSResolverHub = class(TPasResolverHub)
|
TPas2JSResolverHub = class(TPasResolverHub)
|
||||||
private
|
private
|
||||||
FJSSpecialized: TPasAnalyzerKeySet; // set of TPasGenericType
|
FJSDelaySpecialize: TFPList;// list of TPasGenericType
|
||||||
|
function GetJSDelaySpecializes(Index: integer): TPasGenericType;
|
||||||
public
|
public
|
||||||
constructor Create(TheOwner: TObject); override;
|
constructor Create(TheOwner: TObject); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure Reset; override;
|
procedure Reset; override;
|
||||||
// delayed type specialization
|
// delayed type specialization
|
||||||
procedure AddJSSpecialized(SpecType: TPasGenericType);
|
procedure AddJSDelaySpecialize(SpecType: TPasGenericType);
|
||||||
function IsJSSpecialized(SpecType: TPasGenericType): boolean;
|
function IsJSDelaySpecialize(SpecType: TPasGenericType): boolean;
|
||||||
|
function JSDelaySpecializeCount: integer;
|
||||||
|
property JSDelaySpecializes[Index: integer]: TPasGenericType read GetJSDelaySpecializes;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TPas2JSResolver }
|
{ TPas2JSResolver }
|
||||||
@ -1922,7 +1923,6 @@ type
|
|||||||
Function CreateVarStatement(const aName: String; Init: TJSElement;
|
Function CreateVarStatement(const aName: String; Init: TJSElement;
|
||||||
El: TPasElement): TJSVariableStatement; virtual;
|
El: TPasElement): TJSVariableStatement; virtual;
|
||||||
Function CreateVarDecl(const aName: String; Init: TJSElement; El: TPasElement): TJSVarDeclaration; virtual;
|
Function CreateVarDecl(const aName: String; Init: TJSElement; El: TPasElement): TJSVarDeclaration; virtual;
|
||||||
Procedure InitJSSpecialization(aType: TPasType; AContext: TConvertContext; ErrorEl: TPasElement); virtual;
|
|
||||||
// JS literals
|
// JS literals
|
||||||
Function CreateLiteralNumber(El: TPasElement; const n: TJSNumber): TJSLiteral; virtual;
|
Function CreateLiteralNumber(El: TPasElement; const n: TJSNumber): TJSLiteral; virtual;
|
||||||
Function CreateLiteralHexNumber(El: TPasElement; const n: TMaxPrecInt; Digits: byte): TJSLiteral; virtual;
|
Function CreateLiteralHexNumber(El: TPasElement; const n: TMaxPrecInt; Digits: byte): TJSLiteral; virtual;
|
||||||
@ -2335,32 +2335,45 @@ end;
|
|||||||
|
|
||||||
{ TPas2JSResolverHub }
|
{ TPas2JSResolverHub }
|
||||||
|
|
||||||
|
function TPas2JSResolverHub.GetJSDelaySpecializes(Index: integer
|
||||||
|
): TPasGenericType;
|
||||||
|
begin
|
||||||
|
Result:=TPasGenericType(FJSDelaySpecialize[Index]);
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TPas2JSResolverHub.Create(TheOwner: TObject);
|
constructor TPas2JSResolverHub.Create(TheOwner: TObject);
|
||||||
begin
|
begin
|
||||||
inherited Create(TheOwner);
|
inherited Create(TheOwner);
|
||||||
FJSSpecialized:=CreatePasElementSet;
|
FJSDelaySpecialize:=TFPList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TPas2JSResolverHub.Destroy;
|
destructor TPas2JSResolverHub.Destroy;
|
||||||
begin
|
begin
|
||||||
FreeAndNil(FJSSpecialized);
|
FreeAndNil(FJSDelaySpecialize);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPas2JSResolverHub.Reset;
|
procedure TPas2JSResolverHub.Reset;
|
||||||
begin
|
begin
|
||||||
inherited Reset;
|
inherited Reset;
|
||||||
|
FJSDelaySpecialize.Clear;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPas2JSResolverHub.AddJSSpecialized(SpecType: TPasGenericType);
|
procedure TPas2JSResolverHub.AddJSDelaySpecialize(SpecType: TPasGenericType);
|
||||||
begin
|
begin
|
||||||
if FJSSpecialized.FindItem(SpecType)=nil then
|
if FJSDelaySpecialize.IndexOf(SpecType)>=0 then
|
||||||
FJSSpecialized.Add(SpecType,false);
|
raise EPas2JS.Create('TPas2JSResolverHub.AddJSDelaySpecialize '+GetObjPath(SpecType));
|
||||||
|
FJSDelaySpecialize.Add(SpecType);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPas2JSResolverHub.IsJSSpecialized(SpecType: TPasGenericType): boolean;
|
function TPas2JSResolverHub.IsJSDelaySpecialize(SpecType: TPasGenericType): boolean;
|
||||||
begin
|
begin
|
||||||
Result:=FJSSpecialized.FindItem(SpecType)<>nil;
|
Result:=FJSDelaySpecialize.IndexOf(SpecType)>=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TPas2JSResolverHub.JSDelaySpecializeCount: integer;
|
||||||
|
begin
|
||||||
|
Result:=FJSDelaySpecialize.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TPas2JSModuleScope }
|
{ TPas2JSModuleScope }
|
||||||
@ -22624,53 +22637,6 @@ begin
|
|||||||
Result.Init:=Init;
|
Result.Init:=Init;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPasToJSConverter.InitJSSpecialization(aType: TPasType;
|
|
||||||
AContext: TConvertContext; ErrorEl: TPasElement);
|
|
||||||
var
|
|
||||||
aResolver: TPas2JSResolver;
|
|
||||||
SpecTypeData: TPasSpecializeTypeData;
|
|
||||||
Hub: TPas2JSResolverHub;
|
|
||||||
SpecType: TPasGenericType;
|
|
||||||
C: TClass;
|
|
||||||
FuncCtx: TFunctionContext;
|
|
||||||
SrcEl: TJSSourceElements;
|
|
||||||
begin
|
|
||||||
while aType<>nil do
|
|
||||||
begin
|
|
||||||
C:=aType.ClassType;
|
|
||||||
if C=TPasAliasType then
|
|
||||||
aType:=TPasAliasType(aType).DestType
|
|
||||||
else if C=TPasSpecializeType then
|
|
||||||
begin
|
|
||||||
// specialized type
|
|
||||||
SpecTypeData:=aType.CustomData as TPasSpecializeTypeData;
|
|
||||||
if SpecTypeData=nil then
|
|
||||||
RaiseNotSupported(aType,AContext,20200815210904);
|
|
||||||
aResolver:=AContext.Resolver;
|
|
||||||
Hub:=TPas2JSResolverHub(aResolver.Hub);
|
|
||||||
SpecType:=SpecTypeData.SpecializedType;
|
|
||||||
if Hub.IsJSSpecialized(SpecType) then exit;
|
|
||||||
Hub.AddJSSpecialized(SpecType);
|
|
||||||
FuncCtx:=AContext.GetGlobalFunc;
|
|
||||||
SrcEl:=FuncCtx.JSElement as TJSSourceElements;
|
|
||||||
|
|
||||||
if SrcEl=nil then ;
|
|
||||||
|
|
||||||
if SpecType is TPasRecordType then
|
|
||||||
begin
|
|
||||||
// add $mod.TAnt$G1();
|
|
||||||
//CreateReferencePath();
|
|
||||||
RaiseNotSupported(ErrorEl,AContext,20200815215652);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
RaiseNotSupported(ErrorEl,AContext,20200815215338);
|
|
||||||
exit;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TPasToJSConverter.CreateLiteralNumber(El: TPasElement;
|
function TPasToJSConverter.CreateLiteralNumber(El: TPasElement;
|
||||||
const n: TJSNumber): TJSLiteral;
|
const n: TJSNumber): TJSLiteral;
|
||||||
begin
|
begin
|
||||||
@ -24789,8 +24755,8 @@ begin
|
|||||||
if RecScope.SpecializedFromItem<>nil then
|
if RecScope.SpecializedFromItem<>nil then
|
||||||
begin
|
begin
|
||||||
// ToDo
|
// ToDo
|
||||||
//if aResolver.SpecializeNeedsDelay(RecScope.SpecializedFromItem)<>nil then
|
if aResolver.SpecializeNeedsDelay(RecScope.SpecializedFromItem)<>nil then
|
||||||
//bifn:=pbifnRecordCreateSpecializeType;
|
;//bifn:=pbifnRecordCreateSpecializeType;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),GetBIName(bifn)]);
|
Call.Expr:=CreateMemberExpression([GetBIName(pbivnRTL),GetBIName(bifn)]);
|
||||||
|
@ -30362,7 +30362,7 @@ begin
|
|||||||
ConvertProgram;
|
ConvertProgram;
|
||||||
CheckSource('TestRTTI_TypeInfo_ExtTypeInfoClasses2',
|
CheckSource('TestRTTI_TypeInfo_ExtTypeInfoClasses2',
|
||||||
LinesToStr([ // statements
|
LinesToStr([ // statements
|
||||||
' $mod.$rtti.$StaticArray("TStaticArr", {',
|
'$mod.$rtti.$StaticArray("TStaticArr", {',
|
||||||
' dims: [2],',
|
' dims: [2],',
|
||||||
' eltype: rtl.string',
|
' eltype: rtl.string',
|
||||||
'});',
|
'});',
|
||||||
|
9
utils/pas2js/dist/rtl.js
vendored
9
utils/pas2js/dist/rtl.js
vendored
@ -473,13 +473,6 @@ var rtl = {
|
|||||||
return t;
|
return t;
|
||||||
},
|
},
|
||||||
|
|
||||||
recNewS: function(parent,name,initfn,full){
|
|
||||||
// register specialized record type
|
|
||||||
parent[name] = function(){
|
|
||||||
rtl.recNewT(parent,name,initfn,full);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
is: function(instance,type){
|
is: function(instance,type){
|
||||||
return type.isPrototypeOf(instance) || (instance===type);
|
return type.isPrototypeOf(instance) || (instance===type);
|
||||||
},
|
},
|
||||||
@ -1006,7 +999,7 @@ var rtl = {
|
|||||||
|
|
||||||
arrayConcatN: function(){
|
arrayConcatN: function(){
|
||||||
var a = null;
|
var a = null;
|
||||||
for (var i=0; i<arguments.length; i++){
|
for (var i=1; i<arguments.length; i++){
|
||||||
var src = arguments[i];
|
var src = arguments[i];
|
||||||
if (src === null) continue;
|
if (src === null) continue;
|
||||||
if (a===null){
|
if (a===null){
|
||||||
|
@ -1947,7 +1947,7 @@ function(){
|
|||||||
<div class="section">
|
<div class="section">
|
||||||
<h2 id="attributes">Translating attributes</h2>
|
<h2 id="attributes">Translating attributes</h2>
|
||||||
Attributes are stored in the TTypeInfo objects as streams stored in an array.
|
Attributes are stored in the TTypeInfo objects as streams stored in an array.
|
||||||
See the <i>TypInfo</i> function <i>GetRTTIAttributes</i> for details.
|
See the function <i>GetRTTIAttributes</i> in unit <i>TypInfo</i> for details.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
@ -3326,6 +3326,7 @@ end.
|
|||||||
<li><i>function concat(string1,string2,...): string</i> since 1.3</li>
|
<li><i>function concat(string1,string2,...): string</i> since 1.3</li>
|
||||||
<li><i>$mode delphi: function lo|hi(integer): byte</i> since 1.3</li>
|
<li><i>$mode delphi: function lo|hi(integer): byte</i> since 1.3</li>
|
||||||
<li><i>$mode objfpc: function lo|hi(integer): byte|word|longword</i> since 1.3</li>
|
<li><i>$mode objfpc: function lo|hi(integer): byte|word|longword</i> since 1.3</li>
|
||||||
|
<li><i>function GetTypeKind(Type or Var): TTypeKind;</i> since 1.5</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user