pas2js: filer: add specs to gen type

git-svn-id: trunk@45349 -
This commit is contained in:
Mattias Gaertner 2020-05-12 21:12:14 +00:00
parent 7dbab3a78f
commit 6ffba8e2b6

View File

@ -45,13 +45,33 @@ Works:
- WPO uses Proc.References - WPO uses Proc.References
- gzipped json - gzipped json
- write final switches - write final switches
- srcmaps for precompiled js
ToDo: ToDo:
- generics:
- specializations are stored like external elements
- references of specialized types and their elements:
same as external references
- specialize:
- WriteSpecializeType: write aliastype+Params+SpecName(Name)
- WriteInlineSpecializeExpr: Name(=NameExpr)+Params
- TPCUWriter.IsExternalEl: true for specialized elements
- TPCUWriter.WriteExtRefSignature.WriteMemberIndex
- for specialized elements: writes 'Spec' array with Params
- TPCUWriter.WriteExternalReference
- add specializations to 'Specs' array of generic type,
Note that the generic type can be internal or external
- TPCUReader.AddPendingSpecialize
- TPCUReader.Set_SpecializeParam
- called when a Param of a spezialization was resolved,
- can trigger Resolver.GetSpecializedEl and ReadExternalReferences
- TPCUReader.ReadExternalSpecialized
-
- store used GUIDs - store used GUIDs
- distinguish reader errors in fatal and error - distinguish reader errors in fatal and error
- when pcu is bad, unload and use src - when pcu is bad, unload and use src
- replace GUID with crc - replace GUID with crc
- srcmaps for precompiled js
} }
unit Pas2JsFiler; unit Pas2JsFiler;
@ -463,7 +483,7 @@ const
PCUProcedureScopeFlagNames: array[TPasProcedureScopeFlag] of string = ( PCUProcedureScopeFlagNames: array[TPasProcedureScopeFlag] of string = (
'GrpOverload', 'GrpOverload',
'ppsfIsSpecialized' 'Specialized'
); );
PCUForLoopType: array[TLoopType] of string = ( PCUForLoopType: array[TLoopType] of string = (
@ -596,6 +616,7 @@ type
Pending: TPCUFilerPendingElRef; Pending: TPCUFilerPendingElRef;
Obj: TJSONObject; Obj: TJSONObject;
Elements: TJSONArray; // for external references Elements: TJSONArray; // for external references
Specs: TJSONArray; // for specializations
NextNewExt: TPCUFilerElementRef; // next new external reference NextNewExt: TPCUFilerElementRef; // next new external reference
procedure AddPending(Item: TPCUFilerPendingElRef); procedure AddPending(Item: TPCUFilerPendingElRef);
procedure Clear; procedure Clear;
@ -3289,27 +3310,28 @@ begin
//writeln('TPCUWriter.WriteExternalReference ',GetObjName(El)); //writeln('TPCUWriter.WriteExternalReference ',GetObjName(El));
// write Parent first // write Parent first
Parent:=El.Parent; Parent:=El.Parent;
if IsExternalEl(Parent) then if (El.CustomData is TPasGenericScope) then
begin SpecItem:=TPasGenericScope(El.CustomData).SpecializedFromItem
ParentRef:=WriteExternalReference(Parent,aContext); else
if ParentRef=nil then SpecItem:=nil;
if not (El is TPasModule) then
RaiseMsg(20180308174440,El,GetObjName(El)); if SpecItem<>nil then
end ParentRef:=WriteExternalReference(SpecItem.GenericEl,aContext)
else if IsExternalEl(Parent) then
ParentRef:=WriteExternalReference(Parent,aContext)
else else
begin begin
// El is external, Parent is not -> e.g. El is a specialization // El is external, Parent is not
RaiseMsg(20200328173009,El,GetObjName(El)); // ToDo RaiseMsg(20200328173009,El,GetObjName(El));
end; end;
if ParentRef=nil then
if not (El is TPasModule) then
RaiseMsg(20180308174440,El,GetObjName(El));
// check name // check name
NameEl:=El; NameEl:=El;
if (El.CustomData is TPasGenericScope) then if SpecItem<>nil then
begin NameEl:=SpecItem.GenericEl; // specialized -> use generic name
SpecItem:=TPasGenericScope(El.CustomData).SpecializedFromItem;
if SpecItem<>nil then
NameEl:=SpecItem.GenericEl; // specialized -> use generic name
end;
Name:=Resolver.GetOverloadName(NameEl); Name:=Resolver.GetOverloadName(NameEl);
if Name='' then if Name='' then
begin begin
@ -3324,12 +3346,24 @@ begin
begin begin
Ref.ParentRef:=ParentRef; Ref.ParentRef:=ParentRef;
// add to parent // add to parent
if ParentRef.Elements=nil then if SpecItem<>nil then
begin begin
ParentRef.Elements:=TJSONArray.Create; if ParentRef.Specs=nil then
ParentRef.Obj.Add('El',ParentRef.Elements); begin
ParentRef.Specs:=TJSONArray.Create;
ParentRef.Obj.Add('Specs',ParentRef.Elements);
end;
ParentRef.Specs.Add(Ref.Obj);
end
else
begin
if ParentRef.Elements=nil then
begin
ParentRef.Elements:=TJSONArray.Create;
ParentRef.Obj.Add('El',ParentRef.Elements);
end;
ParentRef.Elements.Add(Ref.Obj);
end; end;
ParentRef.Elements.Add(Ref.Obj);
//writeln('TPCUWriter.WriteExternalReference ',GetObjName(El),' WriteExtRefSignature...'); //writeln('TPCUWriter.WriteExternalReference ',GetObjName(El),' WriteExtRefSignature...');
WriteExtRefSignature(Ref,aContext); WriteExtRefSignature(Ref,aContext);
end end
@ -4445,7 +4479,7 @@ begin
if Scope.SpecializedFromItem<>nil then if Scope.SpecializedFromItem<>nil then
begin begin
// spezialiations are generated on the fly -> do not store // spezialiations are generated on the fly -> cannot be stored
RaiseMsg(20191120180305,El,GetObjPath(Scope.SpecializedFromItem.FirstSpecialize)); RaiseMsg(20191120180305,El,GetObjPath(Scope.SpecializedFromItem.FirstSpecialize));
end; end;