|
@@ -74,9 +74,9 @@ Type
|
|
Function FindInNodes(aNodes: TJSElementNodes; const aName: String): TJSTypeDeclaration;
|
|
Function FindInNodes(aNodes: TJSElementNodes; const aName: String): TJSTypeDeclaration;
|
|
Function FindInScope(aScope: TJSSourceElements; const aName: String): TJSTypeDef;
|
|
Function FindInScope(aScope: TJSSourceElements; const aName: String): TJSTypeDef;
|
|
Function FindTypeDef(const aName : String) : TJSTypeDef;
|
|
Function FindTypeDef(const aName : String) : TJSTypeDef;
|
|
- Function FindTypeAlias(aName : jsbase.TJSString) : String;
|
|
|
|
- Procedure AddToTypeMap(aName : UTF8String; const aPasName : String);
|
|
|
|
- Procedure AddToTypeMap(aName : jsbase.TJSString; const aPasName : String);
|
|
|
|
|
|
+ Function FindTypeAlias(const aName : jsbase.TJSString) : String;
|
|
|
|
+ Procedure AddToTypeMap(const aName : UTF8String; const aPasName : String);
|
|
|
|
+ Procedure AddToTypeMap(const aName : jsbase.TJSString; const aPasName : String);
|
|
Procedure AddToTypeMap(aType : TJSElement);
|
|
Procedure AddToTypeMap(aType : TJSElement);
|
|
Procedure RemoveFromTypeMap(aType : TJSElement);
|
|
Procedure RemoveFromTypeMap(aType : TJSElement);
|
|
Property TypeMap : TFPObjectHashTable Read FTypeMap;
|
|
Property TypeMap : TFPObjectHashTable Read FTypeMap;
|
|
@@ -148,8 +148,8 @@ Type
|
|
function GetFixedValueTypeName(ATypeDef: TJSFixedValueReference): String;
|
|
function GetFixedValueTypeName(ATypeDef: TJSFixedValueReference): String;
|
|
function GetIsRaw: Boolean;
|
|
function GetIsRaw: Boolean;
|
|
function HasReadOnlyPropFields(aTypeDef: TJSObjectTypeDef): Boolean;
|
|
function HasReadOnlyPropFields(aTypeDef: TJSObjectTypeDef): Boolean;
|
|
- function HaveClass(aName: TJSString): Boolean;
|
|
|
|
- function HaveModule(aName: TJSString): Boolean;
|
|
|
|
|
|
+ function HaveClass(const aName: TJSString): Boolean;
|
|
|
|
+ function HaveModule(const aName: TJSString): Boolean;
|
|
function NamespaceExtendsClass(aNs: TJSNamespaceDeclaration): Boolean;
|
|
function NamespaceExtendsClass(aNs: TJSNamespaceDeclaration): Boolean;
|
|
function NamespaceExtendsModule(aNs: TJSNamespaceDeclaration): Boolean;
|
|
function NamespaceExtendsModule(aNs: TJSNamespaceDeclaration): Boolean;
|
|
function ResolveTypeRef(D: TJSTypeDef): TJSTypeDef;
|
|
function ResolveTypeRef(D: TJSTypeDef): TJSTypeDef;
|
|
@@ -195,7 +195,7 @@ Type
|
|
// Overload handling
|
|
// Overload handling
|
|
function GetOverloads(const aDefs: TJSFuncDefArray): TFunctionOverLoadArgumentsList;
|
|
function GetOverloads(const aDefs: TJSFuncDefArray): TFunctionOverLoadArgumentsList;
|
|
procedure AddOverloadParams(aList: TFunctionOverLoadArgumentsList; adef: TJSFuncDef; aIdx: Integer);
|
|
procedure AddOverloadParams(aList: TFunctionOverLoadArgumentsList; adef: TJSFuncDef; aIdx: Integer);
|
|
- procedure AddUnionOverloads(aList: TFunctionOverLoadArgumentsList; AName: TJSString; UT: TJSUnionTypeDef);
|
|
|
|
|
|
+ procedure AddUnionOverloads(aList: TFunctionOverLoadArgumentsList; const AName: TJSString; UT: TJSUnionTypeDef);
|
|
procedure AddParameterToOverloads(aList: TFunctionOverLoadArgumentsList; const AName: TJSString; ATypeDef: TJSTypeDef);
|
|
procedure AddParameterToOverloads(aList: TFunctionOverLoadArgumentsList; const AName: TJSString; ATypeDef: TJSTypeDef);
|
|
procedure AddParameterToOverloads(aList: TFunctionOverLoadArgumentsList; const aParam : TJSTypedParam);
|
|
procedure AddParameterToOverloads(aList: TFunctionOverLoadArgumentsList; const aParam : TJSTypedParam);
|
|
function CloneNonPartialParameterList(aList: TFunctionOverLoadArgumentsList; ADest: TFunctionOverLoadArgumentsList = Nil; AsPartial: Boolean = True): integer;
|
|
function CloneNonPartialParameterList(aList: TFunctionOverLoadArgumentsList; ADest: TFunctionOverLoadArgumentsList = Nil; AsPartial: Boolean = True): integer;
|
|
@@ -211,7 +211,7 @@ Type
|
|
function WriteReadonlyProperty(aProp: TJSPropertyDeclaration): Boolean;
|
|
function WriteReadonlyProperty(aProp: TJSPropertyDeclaration): Boolean;
|
|
function WritePropertyDef(aProp: TJSPropertyDeclaration): Boolean;
|
|
function WritePropertyDef(aProp: TJSPropertyDeclaration): Boolean;
|
|
function WriteReadOnlyPropFields(aTypeDef: TJSObjectTypeDef): Integer;
|
|
function WriteReadOnlyPropFields(aTypeDef: TJSObjectTypeDef): Integer;
|
|
- function WriteAmbientClassDef(aPasName: String; aOrgName: TJSString; aTypeParams: TJSElementNodes; aClass: TJSAmbientClassDeclarationArray): Boolean;
|
|
|
|
|
|
+ function WriteAmbientClassDef(const aPasName: String; aOrgName: TJSString; aTypeParams: TJSElementNodes; aClass: TJSAmbientClassDeclarationArray): Boolean;
|
|
function WriteClassDefs(aClasses: TJSElementNodes) : Integer;
|
|
function WriteClassDefs(aClasses: TJSElementNodes) : Integer;
|
|
|
|
|
|
// Forwards
|
|
// Forwards
|
|
@@ -280,8 +280,8 @@ Type
|
|
function WriteIndirectTypeDefs(aParams: TJStypedParams): Integer; overload; virtual;
|
|
function WriteIndirectTypeDefs(aParams: TJStypedParams): Integer; overload; virtual;
|
|
Function WriteIndirectTypeDefs(aElements : TJSElementNodes) : Integer; overload; virtual;
|
|
Function WriteIndirectTypeDefs(aElements : TJSElementNodes) : Integer; overload; virtual;
|
|
function WriteClassIndirectTypeDefs(aElements: TJSElementNodes; isClassLocal: Boolean): Integer;
|
|
function WriteClassIndirectTypeDefs(aElements: TJSElementNodes; isClassLocal: Boolean): Integer;
|
|
- function WritePropertyTypeDefs(aElements: TJSElementNodes; SectionName: String=''): Integer;
|
|
|
|
- function WriteMethodParameterDefs(aElements: TJSElementNodes; SectionName : String = ''): Integer;
|
|
|
|
|
|
+ function WritePropertyTypeDefs(aElements: TJSElementNodes; Const SectionName: String=''): Integer;
|
|
|
|
+ function WriteMethodParameterDefs(aElements: TJSElementNodes; Const SectionName : String = ''): Integer;
|
|
|
|
|
|
// List of identifiers: global, namespace or class
|
|
// List of identifiers: global, namespace or class
|
|
procedure WriteSourceElements(SourceElements: TJSSourceElements; aNamespace: TJSString);
|
|
procedure WriteSourceElements(SourceElements: TJSSourceElements; aNamespace: TJSString);
|
|
@@ -318,6 +318,33 @@ implementation
|
|
|
|
|
|
uses typinfo, strutils;
|
|
uses typinfo, strutils;
|
|
|
|
|
|
|
|
+Resourcestring
|
|
|
|
+ SErrorCannotPopNilScope = 'Cannot pop nil scope';
|
|
|
|
+ SErrCannotPushNilScope = 'Cannot push nil scope';
|
|
|
|
+ SErrCanOnlyPopToplevelScope = 'Can only pop toplevel scope/forwards';
|
|
|
|
+ SErrIgnoringDuplicateTypeName = 'Ignoring duplicate type name %s -> %s (%s)';
|
|
|
|
+ SErrParseResultIsNotFunctionBody = 'Parse result is not a function body';
|
|
|
|
+ SErrCannotGetTypeNameFromType = 'Cannot get type name from %s at row %d, col %d.';
|
|
|
|
+ SErrUnsupportedNamedParamType = 'Unsupported named type parameter: "%s"';
|
|
|
|
+ ResUnsupportedTypeParameter = 'Unsupported type parameter: "%s"';
|
|
|
|
+ SCommentImportFile = 'Import file : %s';
|
|
|
|
+ SCommentRequiredImportFile = 'Import (require) file : ';
|
|
|
|
+ SLogRenamedType = 'Renamed %s to %s';
|
|
|
|
+ SLogRenamingUnitCompile = 'Renaming unit %s to %s to allow compilation.';
|
|
|
|
+ SErrRenamingUnitConflict = 'Renaming unit %s to %s to avoid name conflict.';
|
|
|
|
+ SLogParsedNDefinitions = 'Parsed %d type definitions.';
|
|
|
|
+ SErrUnsupportedTupleElementType = 'Unsupported tuple element type: %s';
|
|
|
|
+ SCommentIgnoringDuplicateType = 'Ignoring duplicate type %s (%s)';
|
|
|
|
+ SErrUnsupportedType = '%s (%s) has unsupported type "%s" : ';
|
|
|
|
+ SErrNoNameAllocatedForFunctionResult = 'No name allocated for function %s (%d,%d) result type %s';
|
|
|
|
+ SErrElementWithoutTypeName = 'Element without allocated typename: %s %s';
|
|
|
|
+ SLogFoldingClassDefinitions = 'Folding %d definitions to 1 class for %s';
|
|
|
|
+ SLogIgnoringEmptyMethod = 'Ignoring empty method';
|
|
|
|
+ SLogIgnoringEmptyFunction = 'Ignoring empty function definition';
|
|
|
|
+ SLogIgnoreDoubleClassDefinition = 'Ignore double class definition: "%s"';
|
|
|
|
+ SForwardClassDefinitions = 'Forward class definitions';
|
|
|
|
+ SLogFoldingInterfaceDefinitions = 'Folding %d definitions to 1 interface for %s';
|
|
|
|
+
|
|
{ TFunctionOverLoadArgumentsList }
|
|
{ TFunctionOverLoadArgumentsList }
|
|
|
|
|
|
procedure TFunctionOverLoadArgumentsList.AddOverload(aTypedParams: TJSTypedParams);
|
|
procedure TFunctionOverLoadArgumentsList.AddOverload(aTypedParams: TJSTypedParams);
|
|
@@ -465,7 +492,7 @@ end;
|
|
procedure TTSContext.PushScope(aScope: TJSSourceElements; aForwards : TStringList);
|
|
procedure TTSContext.PushScope(aScope: TJSSourceElements; aForwards : TStringList);
|
|
begin
|
|
begin
|
|
if aScope=Nil then
|
|
if aScope=Nil then
|
|
- Raise ETSToPas.Create('Cannot push nil scope');
|
|
|
|
|
|
+ raise ETSToPas.Create(SErrCannotPushNilScope);
|
|
Inc(FCurrentScopeIdx);
|
|
Inc(FCurrentScopeIdx);
|
|
if FCurrentScopeIdx>=Length(FScopes) then
|
|
if FCurrentScopeIdx>=Length(FScopes) then
|
|
SetLength(FScopes,Length(FScopes)*2);
|
|
SetLength(FScopes,Length(FScopes)*2);
|
|
@@ -473,12 +500,13 @@ begin
|
|
FScopes[FCurrentScopeIdx].Forwards:=aForwards;
|
|
FScopes[FCurrentScopeIdx].Forwards:=aForwards;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+
|
|
procedure TTSContext.PopScope(aScope: TJSSourceElements; aForwards : TStringList);
|
|
procedure TTSContext.PopScope(aScope: TJSSourceElements; aForwards : TStringList);
|
|
begin
|
|
begin
|
|
if (aScope=Nil) then
|
|
if (aScope=Nil) then
|
|
- Raise ETSToPas.Create('Cannot pop nil scope');
|
|
|
|
- if aScope<>CurrentScope then
|
|
|
|
- Raise ETSToPas.Create('Can only pop toplevel scope');
|
|
|
|
|
|
+ Raise ETSToPas.Create(SErrorCannotPopNilScope);
|
|
|
|
+ if (aScope<>CurrentScope) or (aForwards<>CurrentForwards) then
|
|
|
|
+ raise ETSToPas.Create(SErrCanOnlyPopToplevelScope);
|
|
Dec(FCurrentScopeIdx);
|
|
Dec(FCurrentScopeIdx);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -600,7 +628,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TTSContext.FindTypeAlias(aName: jsbase.TJSString): String;
|
|
|
|
|
|
+function TTSContext.FindTypeAlias(const aName: jsbase.TJSString): String;
|
|
|
|
|
|
Var
|
|
Var
|
|
S : UTF8String;
|
|
S : UTF8String;
|
|
@@ -646,7 +674,7 @@ begin
|
|
begin
|
|
begin
|
|
N:=UTF8Encode(TPasData(El.Data).OriginalName);
|
|
N:=UTF8Encode(TPasData(El.Data).OriginalName);
|
|
if FTypeMap.Find(N)<>Nil then
|
|
if FTypeMap.Find(N)<>Nil then
|
|
- FConverter.DoLog('Ignoring duplicate type name %s -> %s (%s)',[N,TPasData(El.Data).PasName,EL.ClassName])
|
|
|
|
|
|
+ FConverter.DoLog(SErrIgnoringDuplicateTypeName, [N, TPasData(El.Data).PasName, EL.ClassName])
|
|
else
|
|
else
|
|
FTypeMap.Add(N,El.Data) ;
|
|
FTypeMap.Add(N,El.Data) ;
|
|
end;
|
|
end;
|
|
@@ -677,12 +705,12 @@ begin
|
|
FTypeDeclarations.Extract(aEl);
|
|
FTypeDeclarations.Extract(aEl);
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TTSContext.AddToTypeMap(aName: UTF8String; const aPasName: String);
|
|
|
|
|
|
+procedure TTSContext.AddToTypeMap(const aName: UTF8String; const aPasName: String);
|
|
begin
|
|
begin
|
|
FTypeMap.Add(aName,FConverter.CreatePasName(UTF8Decode(aName),aPasName));
|
|
FTypeMap.Add(aName,FConverter.CreatePasName(UTF8Decode(aName),aPasName));
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TTSContext.AddToTypeMap(aName: jsbase.TJSString; const aPasName: String);
|
|
|
|
|
|
+procedure TTSContext.AddToTypeMap(const aName: jsbase.TJSString; const aPasName: String);
|
|
begin
|
|
begin
|
|
AddToTypeMap(UTF8Encode(aName),aPasName);
|
|
AddToTypeMap(UTF8Encode(aName),aPasName);
|
|
end;
|
|
end;
|
|
@@ -808,7 +836,7 @@ begin
|
|
if not (El is TJSFunctionBody) then
|
|
if not (El is TJSFunctionBody) then
|
|
begin
|
|
begin
|
|
EL.Free;
|
|
EL.Free;
|
|
- Raise ETStoPas.Create('Parse result is not a function body');
|
|
|
|
|
|
+ raise ETStoPas.Create(SErrParseResultIsNotFunctionBody);
|
|
end;
|
|
end;
|
|
FElements:=El as TJSFunctionBody;
|
|
FElements:=El as TJSFunctionBody;
|
|
// DumpElements;
|
|
// DumpElements;
|
|
@@ -914,7 +942,7 @@ begin
|
|
else if ATypeDef is TJSFixedValueReference then
|
|
else if ATypeDef is TJSFixedValueReference then
|
|
Result:=GetFixedValueTypeName(ATypeDef as TJSFixedValueReference)
|
|
Result:=GetFixedValueTypeName(ATypeDef as TJSFixedValueReference)
|
|
else
|
|
else
|
|
- Raise ETSToPas.CreateFmt('Cannot get type name from %s at row %d, col %d.',[aTypeDef.ClassName,aTypeDef.Line,aTypeDef.Column]);
|
|
|
|
|
|
+ raise ETSToPas.CreateFmt(SErrCannotGetTypeNameFromType, [aTypeDef.ClassName, aTypeDef.Line, aTypeDef.Column]);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -1000,13 +1028,13 @@ begin
|
|
if (N is TJSTypeReference) then
|
|
if (N is TJSTypeReference) then
|
|
aName:=(N as TJSTypeReference).Name
|
|
aName:=(N as TJSTypeReference).Name
|
|
else
|
|
else
|
|
- Raise ETSToPas.CreateFmt('Unsupported named type parameter: "%s"',[ATypeParams[I].Node.ClassName]);
|
|
|
|
|
|
+ raise ETSToPas.CreateFmt(SErrUnsupportedNamedParamType, [ATypeParams[I].Node.ClassName]);
|
|
if Result<>'' then
|
|
if Result<>'' then
|
|
Result:=Result+',';
|
|
Result:=Result+',';
|
|
Result:=Result+UTF8Encode(aName);
|
|
Result:=Result+UTF8Encode(aName);
|
|
end
|
|
end
|
|
else
|
|
else
|
|
- Raise ETSToPas.CreateFmt('Unsupported type parameter: "%s"',[ATypeParams[I].Node.ClassName]);
|
|
|
|
|
|
+ raise ETSToPas.CreateFmt(ResUnsupportedTypeParameter, [ATypeParams[I].Node.ClassName]);
|
|
if Result<>'' then
|
|
if Result<>'' then
|
|
Result:='<'+Result+'>';
|
|
Result:='<'+Result+'>';
|
|
end;
|
|
end;
|
|
@@ -1291,12 +1319,12 @@ begin
|
|
and (CE.Args.Count=1)
|
|
and (CE.Args.Count=1)
|
|
and (CE.Args.Elements[0].Expr is TJSLiteral) then
|
|
and (CE.Args.Elements[0].Expr is TJSLiteral) then
|
|
begin
|
|
begin
|
|
- Comment('Import (require) file : '+(CE.Args.Elements[0].expr as TJSLiteral).Value.AsString);
|
|
|
|
|
|
+ Comment(SCommentRequiredImportFile+Utf8Encode((CE.Args.Elements[0].expr as TJSLiteral).Value.AsString));
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end
|
|
end
|
|
else
|
|
else
|
|
- Comment('Import file : '+Imps.ModuleName)
|
|
|
|
|
|
+ Comment(Format(SCommentImportFile, [Imps.ModuleName]))
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -1437,7 +1465,7 @@ begin
|
|
begin
|
|
begin
|
|
if (ParentName<>'') then
|
|
if (ParentName<>'') then
|
|
ParentName:=ParentName+'.';
|
|
ParentName:=ParentName+'.';
|
|
- DoLog('Renamed %s to %s',[ParentName+UTF8Encode(Org),TPasData(D.Data).PasName]);
|
|
|
|
|
|
+ DoLog(SLogRenamedType, [ParentName+UTF8Encode(Org), TPasData(D.Data).PasName]);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -1714,14 +1742,14 @@ begin
|
|
NN:=OutputUnitName;
|
|
NN:=OutputUnitName;
|
|
if (NN<>'') and (NN[1] in ['0'..'9']) then
|
|
if (NN<>'') and (NN[1] in ['0'..'9']) then
|
|
begin
|
|
begin
|
|
- Dolog('Renaming unit %s to %s to allow compilation.',[OutputUnitName,NN]);
|
|
|
|
|
|
+ Dolog(SLogRenamingUnitCompile, [OutputUnitName, NN]);
|
|
NN:='_'+NN;
|
|
NN:='_'+NN;
|
|
end;
|
|
end;
|
|
For I:=0 to SourceElements.Functions.Count-1 do
|
|
For I:=0 to SourceElements.Functions.Count-1 do
|
|
- if (SourceElements.Functions[i].Node as TJSFunctionStatement).AFunction.Name=OutputUnitName then
|
|
|
|
|
|
+ if UTF8Encode((SourceElements.Functions[i].Node as TJSFunctionStatement).AFunction.Name)=OutputUnitName then
|
|
begin
|
|
begin
|
|
NN:=NN+'_';
|
|
NN:=NN+'_';
|
|
- Dolog('Renaming unit %s to %s to avoid name conflict.',[OutputUnitName,NN]);
|
|
|
|
|
|
+ Dolog(SErrRenamingUnitConflict, [OutputUnitName, NN]);
|
|
end;
|
|
end;
|
|
if OutputUnitName<>NN then
|
|
if OutputUnitName<>NN then
|
|
OutputUnitName:=NN;
|
|
OutputUnitName:=NN;
|
|
@@ -1746,7 +1774,7 @@ begin
|
|
CheckUnitName(SourceElements);
|
|
CheckUnitName(SourceElements);
|
|
FContext.TypesToMap;
|
|
FContext.TypesToMap;
|
|
if Verbose then
|
|
if Verbose then
|
|
- DoLog('Parsed %d type definitions.',[FContext.FTypeMap.Count]);
|
|
|
|
|
|
+ DoLog(SLogParsedNDefinitions, [FContext.FTypeMap.Count]);
|
|
finally
|
|
finally
|
|
Context.PopScope(SourceElements,Fwds);
|
|
Context.PopScope(SourceElements,Fwds);
|
|
end;
|
|
end;
|
|
@@ -1922,7 +1950,7 @@ begin
|
|
Result:=Format('Array[0..%d] of %s',[aTypeDef.Values.Count-1,elName]);
|
|
Result:=Format('Array[0..%d] of %s',[aTypeDef.Values.Count-1,elName]);
|
|
end
|
|
end
|
|
else
|
|
else
|
|
- Raise ETSToPas.Create('Unsupported tuple element type');
|
|
|
|
|
|
+ raise ETSToPas.CreateFmt(SErrUnsupportedTupleElementType, [aTypeDef.Values[0].Node.ClassName]);
|
|
end;
|
|
end;
|
|
procedure TTypescriptToPas.WriteTupleTypeDef(const aPasName: string; const aOrgName: jsBase.TJSString;
|
|
procedure TTypescriptToPas.WriteTupleTypeDef(const aPasName: string; const aOrgName: jsBase.TJSString;
|
|
aTypeParams: TJSElementNodes; aTypeDef: TJSTupleTypeDef);
|
|
aTypeParams: TJSElementNodes; aTypeDef: TJSTupleTypeDef);
|
|
@@ -1985,7 +2013,7 @@ Procedure TTypescriptToPas.WriteTypeDef(const aPasName : string; const aOrgName
|
|
begin
|
|
begin
|
|
if NameScopeHas(aPasName) then
|
|
if NameScopeHas(aPasName) then
|
|
begin
|
|
begin
|
|
- Comment(Format('Ignoring duplicate type %s (%s)',[aPasName,UTF8Encode(aOrgName)]));
|
|
|
|
|
|
+ Comment(Format(SCommentIgnoringDuplicateType, [aPasName, UTF8Encode(aOrgName)]));
|
|
exit;
|
|
exit;
|
|
end;
|
|
end;
|
|
AddToNameScope(aPasName,aOrgName);
|
|
AddToNameScope(aPasName,aOrgName);
|
|
@@ -2006,7 +2034,7 @@ begin
|
|
else if aTypeDef is TJSTupleTypeDef then
|
|
else if aTypeDef is TJSTupleTypeDef then
|
|
WriteTupleTypedef(aPasName,aOrgName,aTypeParams,TJSTupleTypeDef(aTypeDef))
|
|
WriteTupleTypedef(aPasName,aOrgName,aTypeParams,TJSTupleTypeDef(aTypeDef))
|
|
else
|
|
else
|
|
- AddLn('%s (%s) has unsupported type "%s" : ',[aPasName,aOrgName,aTypeDef.ClassName]);
|
|
|
|
|
|
+ Comment(Format(SErrUnsupportedType, [aPasName, aOrgName, aTypeDef.ClassName]));
|
|
end;
|
|
end;
|
|
|
|
|
|
function TTypescriptToPas.WriteIndirectTypeDefs(aParams: TJStypedParams): Integer;
|
|
function TTypescriptToPas.WriteIndirectTypeDefs(aParams: TJStypedParams): Integer;
|
|
@@ -2136,7 +2164,8 @@ begin
|
|
WriteIndirectTypeDefs(FD.ResultType);
|
|
WriteIndirectTypeDefs(FD.ResultType);
|
|
PD:=TPasData(FD.ResultType.Data);
|
|
PD:=TPasData(FD.ResultType.Data);
|
|
if PD=Nil then
|
|
if PD=Nil then
|
|
- Raise ETSToPas.CreateFmt('No name allocated for function %s (%d,%d) result type %s',[FD.Name,FD.ResultType.Line,FD.ResultType.Column,FD.ResultType.ClassName]);
|
|
|
|
|
|
+ raise ETSToPas.CreateFmt(SErrNoNameAllocatedForFunctionResult, [FD.Name, FD.ResultType.Line, FD.ResultType.Column,
|
|
|
|
+ FD.ResultType.ClassName]);
|
|
WriteTypeDef(PD.PasName,PD.OriginalName,nil,FD.ResultType);
|
|
WriteTypeDef(PD.PasName,PD.OriginalName,nil,FD.ResultType);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -2163,11 +2192,11 @@ begin
|
|
WritePropertyTypeDefs(aElements,'');
|
|
WritePropertyTypeDefs(aElements,'');
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TTypescriptToPas.WritePropertyTypeDefs(aElements: TJSElementNodes; SectionName : String = ''): Integer;
|
|
|
|
|
|
+function TTypescriptToPas.WritePropertyTypeDefs(aElements: TJSElementNodes; const SectionName: String): Integer;
|
|
|
|
|
|
Var
|
|
Var
|
|
P : TJSPropertyDeclaration;
|
|
P : TJSPropertyDeclaration;
|
|
- aName : String;
|
|
|
|
|
|
+ aName : TJSString;
|
|
PD : TPasData;
|
|
PD : TPasData;
|
|
EN : TJSElementNode;
|
|
EN : TJSElementNode;
|
|
TD : TJSTypeDef;
|
|
TD : TJSTypeDef;
|
|
@@ -2211,7 +2240,7 @@ begin
|
|
else if TD is TJSObjectTypeDef then
|
|
else if TD is TJSObjectTypeDef then
|
|
Result:=Result+WriteIndirectTypeDefs((TD as TJSObjectTypeDef).Values);
|
|
Result:=Result+WriteIndirectTypeDefs((TD as TJSObjectTypeDef).Values);
|
|
if PD=Nil then
|
|
if PD=Nil then
|
|
- Raise ETSToPas.CreateFmt('Element without allocated typename: %s %s',[aName,TD.ClassName]);
|
|
|
|
|
|
+ raise ETSToPas.CreateFmt(SErrElementWithoutTypeName, [aName, TD.ClassName]);
|
|
WriteTypeDef(PD.PasName,PD.OriginalName,Nil,TD);
|
|
WriteTypeDef(PD.PasName,PD.OriginalName,Nil,TD);
|
|
Inc(Result);
|
|
Inc(Result);
|
|
end;
|
|
end;
|
|
@@ -2223,13 +2252,12 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TTypescriptToPas.WriteMethodParameterDefs(aElements: TJSElementNodes; SectionName : String = ''): Integer;
|
|
|
|
|
|
+function TTypescriptToPas.WriteMethodParameterDefs(aElements: TJSElementNodes; const SectionName: String): Integer;
|
|
|
|
|
|
var
|
|
var
|
|
EN : TJSElementNode;
|
|
EN : TJSElementNode;
|
|
FD : TJSFuncDef;
|
|
FD : TJSFuncDef;
|
|
Didindent : Boolean;
|
|
Didindent : Boolean;
|
|
- PD : TPasData;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
Result:=0;
|
|
Result:=0;
|
|
@@ -2373,7 +2401,8 @@ begin
|
|
Result:=Result+WritePropertyTypeDefs(aElements,Sect);
|
|
Result:=Result+WritePropertyTypeDefs(aElements,Sect);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
-function TTypescriptToPas.WriteAmbientClassDef(aPasName : String; aOrgName : TJSString; aTypeParams: TJSElementNodes; aClass: TJSAmbientClassDeclarationArray): Boolean;
|
|
|
|
|
|
+function TTypescriptToPas.WriteAmbientClassDef(const aPasName: String; aOrgName: TJSString; aTypeParams: TJSElementNodes;
|
|
|
|
+ aClass: TJSAmbientClassDeclarationArray): Boolean;
|
|
|
|
|
|
Type
|
|
Type
|
|
TMembers = array of TJSSourceElements;
|
|
TMembers = array of TJSSourceElements;
|
|
@@ -2398,7 +2427,7 @@ Type
|
|
|
|
|
|
|
|
|
|
Var
|
|
Var
|
|
- Sect,aParentName : string;
|
|
|
|
|
|
+ aParentName : string;
|
|
aCount : Integer;
|
|
aCount : Integer;
|
|
Members : TMembers;
|
|
Members : TMembers;
|
|
M : TJSSourceElements;
|
|
M : TJSSourceElements;
|
|
@@ -2444,7 +2473,7 @@ end;
|
|
|
|
|
|
function TTypescriptToPas.WriteClassDefs(aClasses: TJSElementNodes): Integer;
|
|
function TTypescriptToPas.WriteClassDefs(aClasses: TJSElementNodes): Integer;
|
|
|
|
|
|
- Function GetClasses(aName : TJSString) : TJSAmbientClassDeclarationArray;
|
|
|
|
|
|
+ Function GetClasses(const aName : String) : TJSAmbientClassDeclarationArray;
|
|
|
|
|
|
Var
|
|
Var
|
|
I,aCount : Integer;
|
|
I,aCount : Integer;
|
|
@@ -2452,6 +2481,7 @@ function TTypescriptToPas.WriteClassDefs(aClasses: TJSElementNodes): Integer;
|
|
|
|
|
|
begin
|
|
begin
|
|
aCount:=0;
|
|
aCount:=0;
|
|
|
|
+ Result:=[];
|
|
SetLength(Result,aClasses.Count);
|
|
SetLength(Result,aClasses.Count);
|
|
For I:=0 to aClasses.Count-1 do
|
|
For I:=0 to aClasses.Count-1 do
|
|
begin
|
|
begin
|
|
@@ -2496,7 +2526,7 @@ begin
|
|
if Length(AmbientDecl)>0 then
|
|
if Length(AmbientDecl)>0 then
|
|
begin
|
|
begin
|
|
if Length(AmbientDecl)>1 then
|
|
if Length(AmbientDecl)>1 then
|
|
- DoLog('Folding %d definitions to 1 class for %s',[Length(AmbientDecl),aName]);
|
|
|
|
|
|
+ DoLog(SLogFoldingClassDefinitions, [Length(AmbientDecl), aName]);
|
|
if WriteAmbientClassDef(aName, AmbientDecl[0].Name, AmbientDecl[0].TypeParams, AmbientDecl) then
|
|
if WriteAmbientClassDef(aName, AmbientDecl[0].Name, AmbientDecl[0].TypeParams, AmbientDecl) then
|
|
Inc(Result);
|
|
Inc(Result);
|
|
end;
|
|
end;
|
|
@@ -2572,7 +2602,7 @@ begin
|
|
(GetName(aTypeDef.Elements[I])=FN) then
|
|
(GetName(aTypeDef.Elements[I])=FN) then
|
|
begin
|
|
begin
|
|
if TJSMethodDeclaration(aTypeDef.Elements[I]).FuncDef=nil then
|
|
if TJSMethodDeclaration(aTypeDef.Elements[I]).FuncDef=nil then
|
|
- DoLog('Ignoring empty method')
|
|
|
|
|
|
+ DoLog(SLogIgnoringEmptyMethod)
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
aDefs[aCount]:=TJSMethodDeclaration(aTypeDef.Elements[I]).FuncDef;
|
|
aDefs[aCount]:=TJSMethodDeclaration(aTypeDef.Elements[I]).FuncDef;
|
|
@@ -2709,7 +2739,7 @@ Type
|
|
TJSPartialParams = Class(TJSTypedParams);
|
|
TJSPartialParams = Class(TJSTypedParams);
|
|
|
|
|
|
|
|
|
|
-procedure TTypescriptToPas.AddUnionOverloads(aList: TFunctionOverLoadArgumentsList; AName : TJSString; UT : TJSUnionTypeDef);
|
|
|
|
|
|
+procedure TTypescriptToPas.AddUnionOverloads(aList: TFunctionOverLoadArgumentsList; const AName: TJSString; UT: TJSUnionTypeDef);
|
|
|
|
|
|
Var
|
|
Var
|
|
L,L2 : TFunctionOverLoadArgumentsList;
|
|
L,L2 : TFunctionOverLoadArgumentsList;
|
|
@@ -2858,10 +2888,9 @@ function TTypescriptToPas.GetOverloads(const aDefs: TJSFuncDefArray): TFunctionO
|
|
Var
|
|
Var
|
|
aDef : TJSFuncDef;
|
|
aDef : TJSFuncDef;
|
|
aFunc : TFunctionOverLoadArgumentsList;
|
|
aFunc : TFunctionOverLoadArgumentsList;
|
|
- Len,I : Integer;
|
|
|
|
|
|
+ I : Integer;
|
|
|
|
|
|
begin
|
|
begin
|
|
- Len:=Length(aDefs);
|
|
|
|
Result:=TFunctionOverLoadArgumentsList.Create;
|
|
Result:=TFunctionOverLoadArgumentsList.Create;
|
|
try
|
|
try
|
|
aFunc:=TFunctionOverLoadArgumentsList.Create(False);
|
|
aFunc:=TFunctionOverLoadArgumentsList.Create(False);
|
|
@@ -2984,7 +3013,7 @@ begin
|
|
if ExportNode(EN) and (GetName(EN.Node)=FN) then
|
|
if ExportNode(EN) and (GetName(EN.Node)=FN) then
|
|
begin
|
|
begin
|
|
if (EN.Node as TJSFunctionDeclarationStatement).AFunction = Nil then
|
|
if (EN.Node as TJSFunctionDeclarationStatement).AFunction = Nil then
|
|
- DoLog('Ignoring empty function definition')
|
|
|
|
|
|
+ DoLog(SLogIgnoringEmptyFunction)
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
aDefs[aCount]:=(EN.Node as TJSFunctionDeclarationStatement).AFunction;
|
|
aDefs[aCount]:=(EN.Node as TJSFunctionDeclarationStatement).AFunction;
|
|
@@ -3012,7 +3041,7 @@ begin
|
|
if Result then
|
|
if Result then
|
|
AddLn('%s = Class;',[aName])
|
|
AddLn('%s = Class;',[aName])
|
|
else
|
|
else
|
|
- DoLog('Ignore double class definition: "%s"',[aName]);
|
|
|
|
|
|
+ DoLog(SLogIgnoreDoubleClassDefinition, [aName]);
|
|
end;
|
|
end;
|
|
|
|
|
|
function TTypescriptToPas.WriteForwardClassDef(aIntf: TJSInterfaceDeclaration): Boolean;
|
|
function TTypescriptToPas.WriteForwardClassDef(aIntf: TJSInterfaceDeclaration): Boolean;
|
|
@@ -3057,7 +3086,7 @@ function TTypescriptToPas.WriteForwardClassDefs(aClassList: TJSElementNodes): In
|
|
Procedure MaybeComment;
|
|
Procedure MaybeComment;
|
|
begin
|
|
begin
|
|
if Result=0 then
|
|
if Result=0 then
|
|
- Comment('Forward class definitions');
|
|
|
|
|
|
+ Comment(SForwardClassDefinitions);
|
|
end;
|
|
end;
|
|
|
|
|
|
Var
|
|
Var
|
|
@@ -3139,7 +3168,7 @@ begin
|
|
Result:=HaveModule(aNS.Name);
|
|
Result:=HaveModule(aNS.Name);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TTypescriptToPas.HaveClass(aName : TJSString) : Boolean;
|
|
|
|
|
|
+function TTypescriptToPas.HaveClass(const aName: TJSString): Boolean;
|
|
|
|
|
|
Var
|
|
Var
|
|
I : Integer;
|
|
I : Integer;
|
|
@@ -3154,7 +3183,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TTypescriptToPas.HaveModule(aName: TJSString): Boolean;
|
|
|
|
|
|
+function TTypescriptToPas.HaveModule(const aName: TJSString): Boolean;
|
|
Var
|
|
Var
|
|
I : Integer;
|
|
I : Integer;
|
|
|
|
|
|
@@ -3324,7 +3353,7 @@ end;
|
|
|
|
|
|
function TTypescriptToPas.WriteInterfaceDefs(aList: TJSElementNodes): Integer;
|
|
function TTypescriptToPas.WriteInterfaceDefs(aList: TJSElementNodes): Integer;
|
|
|
|
|
|
- Function GetInterfaces(aName : TJSString) : TJSInterfaceDeclarationArray;
|
|
|
|
|
|
+ Function GetInterfaces(aName : String) : TJSInterfaceDeclarationArray;
|
|
|
|
|
|
Var
|
|
Var
|
|
I,aCount : Integer;
|
|
I,aCount : Integer;
|
|
@@ -3332,6 +3361,7 @@ function TTypescriptToPas.WriteInterfaceDefs(aList: TJSElementNodes): Integer;
|
|
|
|
|
|
begin
|
|
begin
|
|
aCount:=0;
|
|
aCount:=0;
|
|
|
|
+ Result:=[];
|
|
SetLength(Result,aList.Count);
|
|
SetLength(Result,aList.Count);
|
|
For I:=0 to aList.Count-1 do
|
|
For I:=0 to aList.Count-1 do
|
|
begin
|
|
begin
|
|
@@ -3375,7 +3405,7 @@ begin
|
|
if Length(IntfDecl)>0 then
|
|
if Length(IntfDecl)>0 then
|
|
begin
|
|
begin
|
|
if Length(IntfDecl)>1 then
|
|
if Length(IntfDecl)>1 then
|
|
- DoLog('Folding %d definitions to 1 interface for %s',[Length(IntfDecl),aName]);
|
|
|
|
|
|
+ DoLog(SLogFoldingInterfaceDefinitions, [Length(IntfDecl), aName]);
|
|
if WriteInterfaceDef(IntfDecl) then
|
|
if WriteInterfaceDef(IntfDecl) then
|
|
Inc(Result);
|
|
Inc(Result);
|
|
end;
|
|
end;
|