pastojs: filer: TPasProcedure.NameParts

git-svn-id: trunk@42454 -
This commit is contained in:
Mattias Gaertner 2019-07-18 09:57:29 +00:00
parent c6aaa3f1e6
commit 41fa84a355
2 changed files with 106 additions and 0 deletions

View File

@ -774,6 +774,7 @@ type
procedure WritePropertyScope(Obj: TJSONObject; Scope: TPasPropertyScope; aContext: TPCUWriterContext); virtual;
procedure WriteProperty(Obj: TJSONObject; El: TPasProperty; aContext: TPCUWriterContext); virtual;
procedure WriteMethodResolution(Obj: TJSONObject; El: TPasMethodResolution; aContext: TPCUWriterContext); virtual;
procedure WriteProcedureNameParts(Obj: TJSONObject; El: TPasProcedure; aContext: TPCUWriterContext); virtual;
procedure WriteProcedureModifiers(Obj: TJSONObject; const PropName: string; const Value, DefaultValue: TProcedureModifiers); virtual;
procedure WriteProcScopeFlags(Obj: TJSONObject; const PropName: string; const Value, DefaultValue: TPasProcedureScopeFlags); virtual;
procedure WriteProcedureScope(Obj: TJSONObject; Scope: TPas2JSProcedureScope; aContext: TPCUWriterContext); virtual;
@ -986,6 +987,7 @@ type
procedure ReadPropertyScope(Obj: TJSONObject; Scope: TPasPropertyScope; aContext: TPCUReaderContext); virtual;
procedure ReadProperty(Obj: TJSONObject; El: TPasProperty; aContext: TPCUReaderContext); virtual;
procedure ReadMethodResolution(Obj: TJSONObject; El: TPasMethodResolution; aContext: TPCUReaderContext); virtual;
procedure ReadProcedureNameParts(Obj: TJSONObject; El: TPasProcedure; aContext: TPCUReaderContext); virtual;
function ReadProcedureModifiers(Obj: TJSONObject; El: TPasElement;
const PropName: string; const DefaultValue: TProcedureModifiers): TProcedureModifiers; virtual;
function ReadProcScopeFlags(Obj: TJSONObject; El: TPasElement;
@ -3721,6 +3723,43 @@ begin
WriteExpr(Obj,El,'ImplementationProc',El.ImplementationProc,aContext);
end;
procedure TPCUWriter.WriteProcedureNameParts(Obj: TJSONObject;
El: TPasProcedure; aContext: TPCUWriterContext);
var
Arr, TemplArr: TJSONArray;
NamePartObj, TemplObj: TJSONObject;
i, j: Integer;
GenType: TPasGenericTemplateType;
NameParts: TProcedureNameParts;
begin
NameParts:=El.NameParts;
if length(NameParts)=0 then exit;
Arr:=TJSONArray.Create;
Obj.Add('NameParts',Arr);
for i:=0 to length(NameParts)-1 do
begin
NamePartObj:=TJSONObject.Create;
Arr.Add(NamePartObj);
with NameParts[i] do
begin
NamePartObj.Add('Name',Name);
if Templates<>nil then
begin
TemplArr:=TJSONArray.Create;
NamePartObj.Add('Templates',TemplArr);
for j:=0 to Templates.Count-1 do
begin
GenType:=TPasGenericTemplateType(Templates[j]);
TemplObj:=TJSONObject.Create;
TemplArr.Add(TemplObj);
TemplObj.Add('Name',GenType.Name);
WritePasExprArray(TemplObj,El,'Constraints',GenType.Constraints,aContext);
end;
end;
end;
end;
end;
procedure TPCUWriter.WriteProcedureModifiers(Obj: TJSONObject;
const PropName: string; const Value, DefaultValue: TProcedureModifiers);
var
@ -3783,6 +3822,8 @@ begin
//writeln('TPCUWriter.WriteProcedure ',GetObjName(El),' ',GetObjName(Scope),' ',Resolver.GetElementSourcePosStr(El));
if Scope.DeclarationProc=nil then
begin
// declaration
WriteProcedureNameParts(Obj,El,aContext);
WriteElementProperty(Obj,El,'ProcType',El.ProcType,aContext);
WriteExpr(Obj,El,'Public',El.PublicName,aContext);
// e.g. external LibraryExpr name LibrarySymbolName;
@ -3804,6 +3845,7 @@ begin
end
else
begin
// implementation
AddReferenceToObj(Obj,'DeclarationProc',Scope.DeclarationProc);
end;
@ -7365,6 +7407,44 @@ begin
El.ImplementationProc:=ReadExpr(Obj,El,'ImplementationProc',aContext);
end;
procedure TPCUReader.ReadProcedureNameParts(Obj: TJSONObject;
El: TPasProcedure; aContext: TPCUReaderContext);
var
Arr, TemplArr: TJSONArray;
i, j: Integer;
NamePartObj, TemplObj: TJSONObject;
GenTypeName: string;
GenType: TPasGenericTemplateType;
begin
ReleaseProcNameParts(El.NameParts);
if ReadArray(Obj,'NameParts',Arr,El) then
begin
SetLength(El.NameParts,Arr.Count);
for i:=0 to Arr.Count-1 do
begin
NamePartObj:=CheckJSONObject(Arr[i],20190718113441);
with El.NameParts[i] do
begin
if not ReadString(NamePartObj,'Name',Name,El) then
RaiseMsg(20190718113739,El,IntToStr(i));
if not ReadArray(NamePartObj,'Templates',TemplArr,El) then
continue; // Templates=nil
Templates:=TFPList.Create;
for j:=0 to TemplArr.Count-1 do
begin
TemplObj:=CheckJSONObject(TemplArr[j],20190718114058);
if not ReadString(TemplObj,'Name',GenTypeName,El) or (GenTypeName='') then
RaiseMsg(20190718114244,El,IntToStr(i)+','+IntToStr(j));
GenType:=TPasGenericTemplateType(CreateElement(TPasGenericTemplateType,GenTypeName,El));
Templates.Add(GenType);
ReadPasExprArray(TemplObj,El,'Constraints',GenType.Constraints,aContext);
end;
end;
end;
end;
if aContext=nil then ;
end;
function TPCUReader.ReadProcedureModifiers(Obj: TJSONObject; El: TPasElement;
const PropName: string; const DefaultValue: TProcedureModifiers
): TProcedureModifiers;
@ -7561,6 +7641,7 @@ begin
else
begin
// declarationproc
ReadProcedureNameParts(Obj,El,aContext);
El.PublicName:=ReadExpr(Obj,El,'Public',aContext);
// e.g. external LibraryExpr name LibrarySymbolName;
El.LibraryExpr:=ReadExpr(Obj,El,'Lib',aContext);

View File

@ -119,6 +119,7 @@ type
procedure CheckRestoredConst(const Path: string; Orig, Rest: TPasConst); virtual;
procedure CheckRestoredProperty(const Path: string; Orig, Rest: TPasProperty); virtual;
procedure CheckRestoredMethodResolution(const Path: string; Orig, Rest: TPasMethodResolution); virtual;
procedure CheckRestoredProcNameParts(const Path: string; Orig, Rest: TPasProcedure); virtual;
procedure CheckRestoredProcedure(const Path: string; Orig, Rest: TPasProcedure); virtual;
procedure CheckRestoredOperator(const Path: string; Orig, Rest: TPasOperator); virtual;
procedure CheckRestoredAttributes(const Path: string; Orig, Rest: TPasAttributes); virtual;
@ -1535,6 +1536,29 @@ begin
CheckRestoredElement(Path+'.ImplementationProc',Orig.ImplementationProc,Rest.ImplementationProc);
end;
procedure TCustomTestPrecompile.CheckRestoredProcNameParts(const Path: string;
Orig, Rest: TPasProcedure);
var
OrigNameParts, RestNameParts: TProcedureNameParts;
i: Integer;
SubPath: String;
OrigTemplates, RestTemplates: TFPList;
begin
OrigNameParts:=Orig.NameParts;
RestNameParts:=Rest.NameParts;
AssertEquals(Path+'.NameParts length',length(OrigNameParts),length(RestNameParts));
for i:=0 to length(OrigNameParts)-1 do
begin
SubPath:=Path+'.NameParts['+IntToStr(i)+']';
AssertEquals(SubPath+'.Name',OrigNameParts[i].Name,RestNameParts[i].Name);
OrigTemplates:=OrigNameParts[i].Templates;
RestTemplates:=RestNameParts[i].Templates;
CheckRestoredObject(SubPath+'.Templates',OrigTemplates,RestTemplates);
if OrigTemplates=nil then continue;
CheckRestoredElementList(SubPath+'.Templates',OrigTemplates,RestTemplates);
end;
end;
procedure TCustomTestPrecompile.CheckRestoredProcedure(const Path: string;
Orig, Rest: TPasProcedure);
var
@ -1550,6 +1574,7 @@ begin
AssertEquals(Path+'.CustomData[TPas2JSProcedureScope].ResultVarName',OrigScope.ResultVarName,RestScope.ResultVarName);
if RestScope.DeclarationProc=nil then
begin
CheckRestoredProcNameParts(Path,Orig,Rest);
CheckRestoredElement(Path+'.ProcType',Orig.ProcType,Rest.ProcType);
CheckRestoredElement(Path+'.PublicName',Orig.PublicName,Rest.PublicName);
CheckRestoredElement(Path+'.LibrarySymbolName',Orig.LibrarySymbolName,Rest.LibrarySymbolName);