diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp index caa8755ffc..4710b0819b 100644 --- a/packages/pastojs/src/fppas2js.pp +++ b/packages/pastojs/src/fppas2js.pp @@ -41,6 +41,8 @@ Works: - untyped parameter - varargs - modifier public to protect from removing by optimizer + - choose overloads based on type and precision + - fail overload on multiple with loss of precision or one used default param - assign statements - char - literals @@ -88,7 +90,10 @@ Works: - virtual, override, abstract - "is" operator - "as" operator - - call inherited "inherited;", "inherited funcname;" + - call inherited + - "inherited;", + - "inherited funcname(params);" + - in nested proc - call class method - read/write class var - property @@ -238,6 +243,8 @@ Works: - use 0o for octal literals ToDos: +- documentation: $mod, Self, createCallBack on method,proc,nested +- reference to - RTTI - open array param - codetools function typeinfo @@ -342,6 +349,7 @@ const nBracketAccessorOfExternalClassMustHaveOneParameter = 4020; nTypeXCannotBePublished = 4021; nNotSupportedX = 4022; + nNestedInheritedNeedsParameters = 4023; // resourcestring patterns of messages resourcestring sPasElementNotSupported = 'Pascal element not supported: %s'; @@ -366,6 +374,7 @@ resourcestring sBracketAccessorOfExternalClassMustHaveOneParameter = 'Bracket accessor of external class must have one parameter'; sTypeXCannotBePublished = 'Type "%s" cannot be published'; sNotSupportedX = 'Not supported: %s'; + sNestedInheritedNeedsParameters = 'nested inherited needs parameters'; const ExtClassBracketAccessor = '[]'; // external name '[]' marks the array param getter/setter @@ -426,6 +435,7 @@ type pbivnExceptObject, pbivnImplementation, pbivnLoopEnd, + pbivnModule, pbivnModules, pbivnPtrClass, pbivnRTL, @@ -444,6 +454,7 @@ type pbivnRTTIPropDefault, pbivnRTTIPropStored, pbivnRTTISet_CompType, + pbivnSelf, pbivnWith, pbitnAnonymousPostfix, pbitnTI, @@ -516,6 +527,7 @@ const '$e', '$impl', '$loopend', + '$mod', 'pas', '$class', 'rtl', @@ -534,6 +546,7 @@ const 'defaultvalue', 'stored', 'comptype', + 'Self', '$with', '$a', 'tTypeInfo', @@ -869,13 +882,6 @@ type //------------------------------------------------------------------------------ // TConvertContext type - TCtxJSElementKind = ( - cjkRoot, - cjkObject, - cjkFunction, - cjkArray, - cjkDot); - TCtxAccess = ( caRead, // normal read caAssign, // needs setter @@ -893,47 +899,66 @@ type JSElement: TJSElement; Resolver: TPas2JSResolver; Parent: TConvertContext; - Kind: TCtxJSElementKind; - IsSingleton: boolean; + IsGlobal: boolean; // can hold constants and types Access: TCtxAccess; AccessContext: TConvertContext; TmpVarCount: integer; constructor Create(PasEl: TPasElement; JSEl: TJSElement; aParent: TConvertContext); virtual; function GetRootModule: TPasModule; - function GetThis: TPasElement; - function GetThisContext: TFunctionContext; + function GetFunctionContext: TFunctionContext; + function GetLocalName(El: TPasElement): string; virtual; + function GetSelfContext: TFunctionContext; function GetContextOfType(aType: TConvertContextClass): TConvertContext; function CreateLocalIdentifier(const Prefix: string): string; function CurrentModeswitches: TModeSwitches; - function GetSingletonFunc: TFunctionContext; + function GetGlobalFunc: TFunctionContext; procedure WriteStack; - function ToString: ansistring; override; + procedure DoWriteStack(Index: integer); virtual; + function ToString: string; override; end; { TRootContext } TRootContext = Class(TConvertContext) - public - constructor Create(PasEl: TPasElement; JSEl: TJSElement; aParent: TConvertContext); override; end; - { TFunctionContext } + { TFCLocalVar } + + TFCLocalVar = class + public + Element: TPasElement; + Name: string; + constructor Create(const aName: string; TheEl: TPasElement); + end; + TFCLocalVars = array of TFCLocalVar; + + { TFunctionContext + Module Function: PasElement is TPasProcedure, ThisPas=nil + Method: PasElement is TPasProcedure, ThisPas is TPasClassType } TFunctionContext = Class(TConvertContext) public - This: TPasElement; - constructor Create(PasEl: TPasElement; JSEl: TJSElement; aParent: TConvertContext); override; - function ToString: ansistring; override; + LocalVars: TFCLocalVars; + ThisPas: TPasElement; + destructor Destroy; override; + procedure AddLocalVar(const aName: string; El: TPasElement); + function ToString: string; override; + function GetLocalName(El: TPasElement): string; override; + function IndexOfLocalVar(const aName: string): integer; + function IndexOfLocalVar(El: TPasElement): integer; + function FindLocalVar(const aName: string): TFCLocalVar; + function FindLocalVar(El: TPasElement): TFCLocalVar; + procedure DoWriteStack(Index: integer); override; end; { TObjectContext } TObjectContext = Class(TConvertContext) - public - constructor Create(PasEl: TPasElement; JSEl: TJSElement; aParent: TConvertContext); override; end; - { TSectionContext - interface/implementation/program/library } + { TSectionContext - interface/implementation/program/library + interface/program/library: PasElement is TPasModule, ThisPas is TPasModule + implementation: PasElement is TImplementationSection, ThisPas is TPasModule } TSectionContext = Class(TFunctionContext) public @@ -945,7 +970,6 @@ type TDotContext = Class(TConvertContext) public LeftResolved: TPasResolverResult; - constructor Create(PasEl: TPasElement; JSEl: TJSElement; aParent: TConvertContext); override; end; { TAssignContext - used for left side of an assign statement } @@ -1058,7 +1082,7 @@ type FTargetPlatform: TPasToJsPlatform; FTargetProcessor: TPasToJsProcessor; Function CreateBuiltInIdentifierExpr(AName: string): TJSPrimaryExpressionIdent; - Function CreateDeclNameExpression(El: TPasElement; const Name: string; + Function CreateSubDeclNameExpr(El: TPasElement; const Name: string; AContext: TConvertContext): TJSPrimaryExpressionIdent; Function CreateIdentifierExpr(AName: string; El: TPasElement; AContext: TConvertContext): TJSPrimaryExpressionIdent; Function CreateSwitchStatement(El: TPasImplCaseOf; AContext: TConvertContext): TJSElement; @@ -1220,7 +1244,7 @@ type Function ConvertSubIdentExpression(El: TBinaryExpr; AContext: TConvertContext): TJSElement; virtual; Function ConvertBoolConstExpression(El: TBoolConstExpr; AContext: TConvertContext): TJSElement; virtual; Function ConvertPrimitiveExpression(El: TPrimitiveExpr; AContext: TConvertContext): TJSElement; virtual; - Function ConvertIdentifierExpr(El: TPrimitiveExpr; AContext : TConvertContext): TJSElement; virtual; + Function ConvertIdentifierExpr(El: TPasExpr; const aName: string; AContext : TConvertContext): TJSElement; virtual; Function ConvertUnaryExpression(El: TUnaryExpr; AContext: TConvertContext): TJSElement; virtual; // Convert declarations Function ConvertElement(El : TPasElement; AContext: TConvertContext) : TJSElement; virtual; @@ -1328,6 +1352,14 @@ begin while (Result>0) and (s[Result]<>c) do dec(Result); end; +{ TFCLocalVar } + +constructor TFCLocalVar.Create(const aName: string; TheEl: TPasElement); +begin + Name:=aName; + Element:=TheEl; +end; + { TPas2JSResolver } // inline @@ -2960,54 +2992,112 @@ begin AccessContext:=Self; end; -{ TDotContext } - -constructor TDotContext.Create(PasEl: TPasElement; JSEl: TJSElement; - aParent: TConvertContext); -begin - inherited Create(PasEl, JSEl, aParent); - Kind:=cjkDot; -end; - { TSectionContext } constructor TSectionContext.Create(PasEl: TPasElement; JSEl: TJSElement; aParent: TConvertContext); begin inherited; - IsSingleton:=true; -end; - -{ TObjectContext } - -constructor TObjectContext.Create(PasEl: TPasElement; JSEl: TJSElement; - aParent: TConvertContext); -begin - inherited; - Kind:=cjkObject; + IsGlobal:=true; end; { TFunctionContext } -constructor TFunctionContext.Create(PasEl: TPasElement; JSEl: TJSElement; - aParent: TConvertContext); +destructor TFunctionContext.Destroy; +var + i: Integer; begin - inherited; - Kind:=cjkFunction; + for i:=0 to length(LocalVars)-1 do + FreeAndNil(LocalVars[i]); + inherited Destroy; end; -function TFunctionContext.ToString: ansistring; +procedure TFunctionContext.AddLocalVar(const aName: string; El: TPasElement); +var + l: Integer; begin - Result:=inherited ToString+' This='+GetObjName(This); + l:=length(LocalVars); + SetLength(LocalVars,l+1); + LocalVars[l]:=TFCLocalVar.Create(aName,El); end; -{ TRootContext } - -constructor TRootContext.Create(PasEl: TPasElement; JSEl: TJSElement; - aParent: TConvertContext); +function TFunctionContext.ToString: string; +var + V: TFCLocalVar; begin - inherited; - Kind:=cjkRoot; + Result:=inherited ToString; + if ThisPas<>nil then + begin + Result:=Result+' this'; + V:=FindLocalVar(ThisPas); + if V<>nil then + Result:=Result+'="'+V.Name+'"'; + Result:=Result+'='+GetObjName(ThisPas); + end; +end; + +function TFunctionContext.GetLocalName(El: TPasElement): string; +var + V: TFCLocalVar; +begin + if El=nil then exit(''); + V:=FindLocalVar(El); + if V<>nil then + Result:=V.Name + else if El=ThisPas then + Result:='this' + else + Result:=inherited GetLocalName(El); +end; + +function TFunctionContext.IndexOfLocalVar(const aName: string): integer; +var + i: Integer; +begin + for i:=0 to length(LocalVars)-1 do + if LocalVars[i].Name=aName then exit(i); + Result:=-1; +end; + +function TFunctionContext.IndexOfLocalVar(El: TPasElement): integer; +var + i: Integer; +begin + if El=nil then exit(-1); + for i:=0 to length(LocalVars)-1 do + if LocalVars[i].Element=El then exit(i); + Result:=-1; +end; + +function TFunctionContext.FindLocalVar(const aName: string): TFCLocalVar; +var + i: Integer; +begin + i:=IndexOfLocalVar(aName); + if i>=0 then + Result:=LocalVars[i] + else + Result:=nil; +end; + +function TFunctionContext.FindLocalVar(El: TPasElement): TFCLocalVar; +var + i: Integer; +begin + i:=IndexOfLocalVar(El); + if i>=0 then + Result:=LocalVars[i] + else + Result:=nil; +end; + +procedure TFunctionContext.DoWriteStack(Index: integer); +var + i: Integer; +begin + inherited DoWriteStack(Index); + for i:=0 to length(LocalVars)-1 do + writeln(' ',i,' ',LocalVars[i].Name,': ',GetObjName(LocalVars[i].Element)); end; { TConvertContext } @@ -3039,22 +3129,33 @@ begin Result:=nil; end; -function TConvertContext.GetThis: TPasElement; -var - ctx: TFunctionContext; -begin - ctx:=GetThisContext; - if ctx<>nil then - Result:=ctx.This - else - Result:=nil; -end; - -function TConvertContext.GetThisContext: TFunctionContext; +function TConvertContext.GetFunctionContext: TFunctionContext; begin Result:=TFunctionContext(GetContextOfType(TFunctionContext)); end; +function TConvertContext.GetLocalName(El: TPasElement): string; +begin + if Parent<>nil then + Result:=Parent.GetLocalName(El) + else + Result:=''; +end; + +function TConvertContext.GetSelfContext: TFunctionContext; +var + Ctx: TConvertContext; +begin + Ctx:=Self; + while Ctx<>nil do + begin + if (Ctx is TFunctionContext) and (TFunctionContext(Ctx).ThisPas is TPasClassType) then + exit(TFunctionContext(Ctx)); + Ctx:=Ctx.Parent; + end; + Result:=nil; +end; + function TConvertContext.GetContextOfType(aType: TConvertContextClass ): TConvertContext; var @@ -3083,14 +3184,14 @@ begin Result:=Resolver.CurrentParser.CurrentModeswitches; end; -function TConvertContext.GetSingletonFunc: TFunctionContext; +function TConvertContext.GetGlobalFunc: TFunctionContext; var Ctx: TConvertContext; begin Ctx:=Self; while (Ctx<>nil) do begin - if Ctx.IsSingleton and (Ctx.JSElement<>nil) and (Ctx is TFunctionContext) then + if Ctx.IsGlobal and (Ctx.JSElement<>nil) and (Ctx is TFunctionContext) then exit(TFunctionContext(Ctx)); Ctx:=Ctx.Parent; end; @@ -3100,7 +3201,7 @@ procedure TConvertContext.WriteStack; procedure W(Index: integer; AContext: TConvertContext); begin - writeln(' ',Index,' ',AContext.ToString); + AContext.DoWriteStack(Index); if AContext.Parent<>nil then W(Index+1,AContext.Parent); end; @@ -3110,12 +3211,17 @@ begin W(1,Self); end; -function TConvertContext.ToString: ansistring; +procedure TConvertContext.DoWriteStack(Index: integer); +begin + writeln(' ',Index,' ',ToString); +end; + +function TConvertContext.ToString: string; begin Result:='['+ClassName+']' +' pas='+GetObjName(PasElement) +' js='+GetObjName(JSElement) - +' Singleton='+BoolToStr(IsSingleton,true); + +' Global='+BoolToStr(IsGlobal,true); end; { TPasToJSConverter } @@ -3240,7 +3346,7 @@ Var UsesList: TFPList; FunDecl, ImplFunc: TJSFunctionDeclarationStatement; UsesSection: TPasSection; - ModuleName: String; + ModuleName, ModVarName: String; IntfContext: TSectionContext; ImplVarSt: TJSVariableStatement; HasImplUsesList: Boolean; @@ -3283,7 +3389,13 @@ begin IntfContext:=TSectionContext.Create(El,Src,AContext); try - IntfContext.This:=El; + // add "var $mod = this;" + IntfContext.ThisPas:=El; + ModVarName:=FBuiltInNames[pbivnModule]; + IntfContext.AddLocalVar(ModVarName,El); + AddToSourceElements(Src,CreateVarStatement(ModVarName, + CreateBuiltInIdentifierExpr('this'),El)); + if (El is TPasProgram) then begin // program if Assigned(TPasProgram(El).ProgramSection) then @@ -3298,13 +3410,14 @@ begin end else begin // unit - // add implementation object at top, so the interface elemwnts can add stuff if Assigned(El.ImplementationSection) then begin - // add var $impl = this.$impl + // add var $impl = $mod.$impl ImplVarSt:=CreateVarStatement(FBuiltInNames[pbivnImplementation], - CreateMemberExpression(['this',FBuiltInNames[pbivnImplementation]]),El); + CreateMemberExpression([ModVarName,FBuiltInNames[pbivnImplementation]]),El); AddToSourceElements(Src,ImplVarSt); + // register local var $impl + IntfContext.AddLocalVar(FBuiltInNames[pbivnImplementation],El.ImplementationSection); end; if Assigned(El.InterfaceSection) then AddToSourceElements(Src,ConvertDeclarations(El.InterfaceSection,IntfContext)); @@ -4083,16 +4196,16 @@ begin Result:=I; end; -function TPasToJSConverter.CreateDeclNameExpression(El: TPasElement; +function TPasToJSConverter.CreateSubDeclNameExpr(El: TPasElement; const Name: string; AContext: TConvertContext): TJSPrimaryExpressionIdent; var - CurName: String; + CurName, ParentName: String; begin CurName:=TransformVariableName(El,Name,AContext); - if El.Parent.ClassType=TImplementationSection then - CurName:=FBuiltInNames[pbivnImplementation]+'.'+CurName - else - CurName:='this.'+CurName; + ParentName:=AContext.GetLocalName(El.Parent); + if ParentName='' then + ParentName:='this'; + CurName:=ParentName+'.'+CurName; Result:=TJSPrimaryExpressionIdent(CreateElement(TJSPrimaryExpressionIdent,El)); Result.Name:=TJSString(CurName); end; @@ -4167,14 +4280,22 @@ begin Result:=L; end; pekIdent: - Result:=ConvertIdentifierExpr(El,AContext); + Result:=ConvertIdentifierExpr(El,El.Value,AContext); else RaiseNotSupported(El,AContext,20161024222543); end; end; -function TPasToJSConverter.ConvertIdentifierExpr(El: TPrimitiveExpr; - AContext: TConvertContext): TJSElement; +function TPasToJSConverter.ConvertIdentifierExpr(El: TPasExpr; + const aName: string; AContext: TConvertContext): TJSElement; + + function IsClassSelf(Decl: TPasElement): boolean; + begin + if (Decl.ClassType<>TPasClassType) or (CompareText(aName,'Self')<>0) then + exit(false); + Result:=AContext.GetSelfContext<>nil; + end; + var Decl: TPasElement; Name: String; @@ -4190,189 +4311,196 @@ var ProcType: TPasProcedureType; begin Result:=nil; - if AContext=nil then ; - if El.Kind<>pekIdent then - RaiseInconsistency(20161024191255); - if El.CustomData is TResolvedReference then + if not (El.CustomData is TResolvedReference) then begin - Ref:=TResolvedReference(El.CustomData); - Decl:=Ref.Declaration; + if AContext.Resolver<>nil then + RaiseIdentifierNotFound(aName,El,20161024191306) + else + // simple mode + Result:=CreateIdentifierExpr(aName,El,AContext); + exit; + end; - if IsExternalClassConstructor(Decl) then - begin - // create external object/function - Result:=ConvertExternalConstructor(nil,Ref,nil,AContext); - exit; - end; + Ref:=TResolvedReference(El.CustomData); + Decl:=Ref.Declaration; - if [rrfNewInstance,rrfFreeInstance]*Ref.Flags<>[] then - begin - // call constructor, destructor - Result:=CreateFreeOrNewInstanceExpr(Ref,AContext); - exit; - end; + if IsExternalClassConstructor(Decl) then + begin + // create external object/function + Result:=ConvertExternalConstructor(nil,Ref,nil,AContext); + exit; + end; - Prop:=nil; - AssignContext:=nil; - ImplicitCall:=rrfImplicitCallWithoutParams in Ref.Flags; + if [rrfNewInstance,rrfFreeInstance]*Ref.Flags<>[] then + begin + // call constructor, destructor + Result:=CreateFreeOrNewInstanceExpr(Ref,AContext); + exit; + end; - if Decl.ClassType=TPasProperty then - begin - // Decl is a property -> redirect to getter/setter - Prop:=TPasProperty(Decl); - case AContext.Access of - caAssign: + Prop:=nil; + AssignContext:=nil; + ImplicitCall:=rrfImplicitCallWithoutParams in Ref.Flags; + + if Decl.ClassType=TPasProperty then + begin + // Decl is a property -> redirect to getter/setter + Prop:=TPasProperty(Decl); + case AContext.Access of + caAssign: + begin + Decl:=AContext.Resolver.GetPasPropertySetter(Prop); + if Decl is TPasProcedure then begin - Decl:=AContext.Resolver.GetPasPropertySetter(Prop); - if Decl is TPasProcedure then - begin - AssignContext:=AContext.AccessContext as TAssignContext; - if AssignContext.Call<>nil then - RaiseNotSupported(El,AContext,20170206000310); - AssignContext.PropertyEl:=Prop; - AssignContext.Setter:=Decl; - // Setter - Call:=CreateCallExpression(El); - AssignContext.Call:=Call; - Call.Expr:=CreateReferencePathExpr(Decl,AContext,false,Ref); - Call.AddArg(AssignContext.RightSide); - AssignContext.RightSide:=nil; - Result:=Call; - exit; - end; + AssignContext:=AContext.AccessContext as TAssignContext; + if AssignContext.Call<>nil then + RaiseNotSupported(El,AContext,20170206000310); + AssignContext.PropertyEl:=Prop; + AssignContext.Setter:=Decl; + // Setter + Call:=CreateCallExpression(El); + AssignContext.Call:=Call; + Call.Expr:=CreateReferencePathExpr(Decl,AContext,false,Ref); + Call.AddArg(AssignContext.RightSide); + AssignContext.RightSide:=nil; + Result:=Call; + exit; end; + end; + caRead: + begin + Decl:=AContext.Resolver.GetPasPropertyGetter(Prop); + if (Decl is TPasFunction) and (Prop.Args.Count=0) then + ImplicitCall:=true; + end; + else + RaiseNotSupported(El,AContext,20170213212623); + end; + end + else if Decl.ClassType=TPasArgument then + begin + Arg:=TPasArgument(Decl); + if Arg.Access in [argVar,argOut] then + begin + // Arg is a reference object + case AContext.Access of caRead: begin - Decl:=AContext.Resolver.GetPasPropertyGetter(Prop); - if (Decl is TPasFunction) and (Prop.Args.Count=0) then - ImplicitCall:=true; + // create arg.get() + Call:=CreateCallExpression(El); + Call.Expr:=CreateDotExpression(El, + CreateIdentifierExpr(Arg.Name,Arg,AContext), + CreateBuiltInIdentifierExpr(TempRefObjGetterName)); + Result:=Call; + exit; + end; + caAssign: + begin + // create arg.set(RHS) + AssignContext:=AContext.AccessContext as TAssignContext; + if AssignContext.Call<>nil then + RaiseNotSupported(El,AContext,20170214120606); + Call:=CreateCallExpression(El); + AssignContext.Call:=Call; + Call.Expr:=CreateDotExpression(El, + CreateIdentifierExpr(Arg.Name,Arg,AContext), + CreateBuiltInIdentifierExpr(TempRefObjSetterName)); + Call.AddArg(AssignContext.RightSide); + AssignContext.RightSide:=nil; + Result:=Call; + exit; + end; + caByReference: + begin + // simply pass the reference + ParamContext:=AContext.AccessContext as TParamContext; + ParamContext.ReusingReference:=true; + Result:=CreateIdentifierExpr(Arg.Name,Arg,AContext); + exit; end; else - RaiseNotSupported(El,AContext,20170213212623); + RaiseNotSupported(El,AContext,20170214120739); end; - end - else if Decl.ClassType=TPasArgument then - begin - Arg:=TPasArgument(Decl); - if Arg.Access in [argVar,argOut] then - begin - // Arg is a reference object - case AContext.Access of - caRead: - begin - // create arg.get() - Call:=CreateCallExpression(El); - Call.Expr:=CreateDotExpression(El, - CreateIdentifierExpr(Arg.Name,Arg,AContext), - CreateBuiltInIdentifierExpr(TempRefObjGetterName)); - Result:=Call; - exit; - end; - caAssign: - begin - // create arg.set(RHS) - AssignContext:=AContext.AccessContext as TAssignContext; - if AssignContext.Call<>nil then - RaiseNotSupported(El,AContext,20170214120606); - Call:=CreateCallExpression(El); - AssignContext.Call:=Call; - Call.Expr:=CreateDotExpression(El, - CreateIdentifierExpr(Arg.Name,Arg,AContext), - CreateBuiltInIdentifierExpr(TempRefObjSetterName)); - Call.AddArg(AssignContext.RightSide); - AssignContext.RightSide:=nil; - Result:=Call; - exit; - end; - caByReference: - begin - // simply pass the reference - ParamContext:=AContext.AccessContext as TParamContext; - ParamContext.ReusingReference:=true; - Result:=CreateIdentifierExpr(Arg.Name,Arg,AContext); - exit; - end; - else - RaiseNotSupported(El,AContext,20170214120739); - end; - end; - end; - - //writeln('TPasToJSConverter.ConvertPrimitiveExpression pekIdent TResolvedReference ',GetObjName(Ref.Declaration),' ',GetObjName(Ref.Declaration.CustomData)); - if Decl.CustomData is TResElDataBuiltInProc then - begin - BuiltInProc:=TResElDataBuiltInProc(Decl.CustomData); - {$IFDEF VerbosePas2JS} - writeln('TPasToJSConverter.ConvertPrimitiveExpression ',Decl.Name,' ',ResolverBuiltInProcNames[BuiltInProc.BuiltIn]); - {$ENDIF} - case BuiltInProc.BuiltIn of - bfBreak: Result:=ConvertBuiltInBreak(El,AContext); - bfContinue: Result:=ConvertBuiltInContinue(El,AContext); - bfExit: Result:=ConvertBuiltIn_Exit(El,AContext); - else - RaiseNotSupported(El,AContext,20161130164955,'built in proc '+ResolverBuiltInProcNames[BuiltInProc.BuiltIn]); - end; - if Result=nil then - RaiseInconsistency(20170214120048); - exit; end; + end; + //writeln('TPasToJSConverter.ConvertPrimitiveExpression pekIdent TResolvedReference ',GetObjName(Ref.Declaration),' ',GetObjName(Ref.Declaration.CustomData)); + if Decl.CustomData is TResElDataBuiltInProc then + begin + BuiltInProc:=TResElDataBuiltInProc(Decl.CustomData); {$IFDEF VerbosePas2JS} - writeln('TPasToJSConverter.ConvertIdentifierExpr ',GetObjName(El),' Decl=',GetObjName(Decl),' Decl.Parent=',GetObjName(Decl.Parent)); + writeln('TPasToJSConverter.ConvertPrimitiveExpression ',Decl.Name,' ',ResolverBuiltInProcNames[BuiltInProc.BuiltIn]); {$ENDIF} - if Decl is TPasModule then - Name:=TransformModuleName(TPasModule(Decl),true,AContext) - else if (Decl is TPasFunctionType) and (CompareText(ResolverResultVar,El.Value)=0) then - Name:=ResolverResultVar - else if Decl.ClassType=TPasEnumValue then + case BuiltInProc.BuiltIn of + bfBreak: Result:=ConvertBuiltInBreak(El,AContext); + bfContinue: Result:=ConvertBuiltInContinue(El,AContext); + bfExit: Result:=ConvertBuiltIn_Exit(El,AContext); + else + RaiseNotSupported(El,AContext,20161130164955,'built in proc '+ResolverBuiltInProcNames[BuiltInProc.BuiltIn]); + end; + if Result=nil then + RaiseInconsistency(20170214120048); + exit; + end; + + {$IFDEF VerbosePas2JS} + writeln('TPasToJSConverter.ConvertIdentifierExpr ',GetObjName(El),' Decl=',GetObjName(Decl),' Decl.Parent=',GetObjName(Decl.Parent)); + //if CompareText(aName,'Self')=0 then + // begin + // writeln('TPasToJSConverter.ConvertIdentifierExpr AContext=',GetObjName(AContext),' SelfContext=',GetObjName(AContext.GetSelfContext),' LocalVar=',AContext.GetLocalName(Decl),' ',GetObjName(Decl)); + // AContext.WriteStack; + // end; + {$ENDIF} + + if Decl is TPasModule then + Name:=TransformModuleName(TPasModule(Decl),true,AContext) + else if (Decl is TPasFunctionType) and (CompareText(ResolverResultVar,aName)=0) then + Name:=ResolverResultVar + else if Decl.ClassType=TPasEnumValue then + begin + if UseEnumNumbers then begin - if UseEnumNumbers then - begin - Result:=CreateLiteralNumber(El,(Decl.Parent as TPasEnumType).Values.IndexOf(Decl)); - exit; - end - else - begin - // enums always need the full path - Name:=CreateReferencePath(Decl,AContext,rpkPathAndName,true); - end; + Result:=CreateLiteralNumber(El,(Decl.Parent as TPasEnumType).Values.IndexOf(Decl)); + exit; end else - Name:=CreateReferencePath(Decl,AContext,rpkPathAndName,false,Ref); - if Result=nil then - Result:=CreateBuiltInIdentifierExpr(Name); - - if ImplicitCall then begin - // create a call with default parameters - ProcType:=nil; - if Decl is TPasProcedure then - ProcType:=TPasProcedure(Decl).ProcType - else - begin - AContext.Resolver.ComputeElement(El,ResolvedEl,[rcNoImplicitProc]); - if ResolvedEl.TypeEl is TPasProcedureType then - ProcType:=TPasProcedureType(ResolvedEl.TypeEl) - else - RaiseNotSupported(El,AContext,20170217005025); - end; - - Call:=nil; - try - CreateProcedureCall(Call,nil,ProcType,AContext); - Call.Expr:=Result; - Result:=Call; - finally - if Result<>Call then - Call.Free; - end; + // enums always need the full path + Name:=CreateReferencePath(Decl,AContext,rpkPathAndName,true); end; end - else if AContext.Resolver<>nil then - RaiseIdentifierNotFound(El.Value,El,20161024191306) + else if (CompareText(aName,'Self')=0) and (AContext.GetSelfContext<>nil) then + Name:=AContext.GetLocalName(Decl) else - // simple mode - Result:=CreateIdentifierExpr(El.Value,El,AContext); + Name:=CreateReferencePath(Decl,AContext,rpkPathAndName,false,Ref); + if Result=nil then + Result:=CreateBuiltInIdentifierExpr(Name); + + if ImplicitCall then + begin + // create a call with default parameters + ProcType:=nil; + if Decl is TPasProcedure then + ProcType:=TPasProcedure(Decl).ProcType + else + begin + AContext.Resolver.ComputeElement(El,ResolvedEl,[rcNoImplicitProc]); + if ResolvedEl.TypeEl is TPasProcedureType then + ProcType:=TPasProcedureType(ResolvedEl.TypeEl) + else + RaiseNotSupported(El,AContext,20170217005025); + end; + + Call:=nil; + try + CreateProcedureCall(Call,nil,ProcType,AContext); + Call.Expr:=Result; + Result:=Call; + finally + if Result<>Call then + Call.Free; + end; + end; end; function TPasToJSConverter.ConvertBoolConstExpression(El: TBoolConstExpr; @@ -4396,27 +4524,32 @@ function TPasToJSConverter.ConvertInheritedExpression(El: TInheritedExpr; function CreateAncestorCall(ParentEl: TPasElement; Apply: boolean; AncestorProc: TPasProcedure; ParamsExpr: TParamsExpr): TJSElement; var - FunName: String; + FunName, SelfName: String; Call: TJSCallExpression; - ThisContext: TFunctionContext; - Proc: TPasProcedure; - ProcScope: TPasProcedureScope; + SelfContext: TFunctionContext; ClassScope, AncestorScope: TPasClassScope; - AncestorClass: TPasClassType; + AncestorClass, aClass: TPasClassType; begin Result:=nil; + SelfContext:=AContext.GetSelfContext; + if SelfContext=nil then + RaiseInconsistency(20170418114702); + SelfName:=SelfContext.GetLocalName(SelfContext.ThisPas); + + if Apply and (SelfContext<>AContext) then + DoError(20170418204325,nNestedInheritedNeedsParameters,sNestedInheritedNeedsParameters, + [],El); + if (AncestorProc.Parent is TPasClassType) and TPasClassType(AncestorProc.Parent).IsExternal then begin // ancestor is in an external class // They could be overriden, without a Pascal declaration // -> use the direct ancestor class of the current proc - ThisContext:=AContext.GetThisContext; - Proc:=ThisContext.PasElement as TPasProcedure; - ProcScope:=TPasProcedureScope(Proc.CustomData); - ClassScope:=ProcScope.ClassScope; - if ClassScope=nil then + aClass:=SelfContext.ThisPas as TPasClassType; + if aClass.CustomData=nil then RaiseInconsistency(20170323111252); + ClassScope:=TPasClassScope(aClass.CustomData); AncestorScope:=ClassScope.AncestorScope; if AncestorScope=nil then RaiseInconsistency(20170323111306); @@ -4426,7 +4559,7 @@ function TPasToJSConverter.ConvertInheritedExpression(El: TInheritedExpr; end else FunName:=CreateReferencePath(AncestorProc,AContext,rpkPathAndName,true); - if Apply then + if Apply and (SelfContext=AContext) then // create "ancestor.funcname.apply(this,arguments)" FunName:=FunName+'.apply' else @@ -4436,10 +4569,12 @@ function TPasToJSConverter.ConvertInheritedExpression(El: TInheritedExpr; try Call:=CreateCallExpression(ParentEl); Call.Expr:=CreateBuiltInIdentifierExpr(FunName); - Call.AddArg(CreateBuiltInIdentifierExpr('this')); + Call.AddArg(CreateBuiltInIdentifierExpr(SelfName)); if Apply then + // "inherited;" -> pass the arguments Call.AddArg(CreateBuiltInIdentifierExpr('arguments')) else + // "inherited Name(...)" -> pass the user arguments CreateProcedureCall(Call,ParamsExpr,AncestorProc.ProcType,AContext); Result:=Call; finally @@ -4493,7 +4628,10 @@ begin PrimExpr:=TPrimitiveExpr(ParamsExpr.Value); Ref:=PrimExpr.CustomData as TResolvedReference; AncestorProc:=Ref.Declaration as TPasProcedure; - end; + end + else + DoError(20170418205802,nXExpectedButYFound,sXExpectedButYFound, + ['inherited name()',ParamsExpr.Value.ElementTypeName],ParamsExpr.Value); end else begin @@ -4502,6 +4640,14 @@ begin Result:=ConvertElement(Right,AContext); exit; end; + end + else + begin + {$IFDEF VerbosePas2JS} + writeln('TPasToJSConverter.ConvertInheritedExpression Parent=',GetTreeDesc(El.Parent,2)); + {$ENDIF} + DoError(20170418205955,nXExpectedButYFound,sXExpectedButYFound, + ['inherited name()',Right.ElementTypeName],Right); end; if AncestorProc=nil then begin @@ -4527,10 +4673,8 @@ end; function TPasToJSConverter.ConvertSelfExpression(El: TSelfExpr; AContext: TConvertContext): TJSElement; - begin - if AContext=nil then ; - Result:=TJSPrimaryExpressionThis(CreateElement(TJSPrimaryExpressionThis,El)); + Result:=ConvertIdentifierExpr(El,'Self',AContext); end; function TPasToJSConverter.ConvertParamsExpression(El: TParamsExpr; @@ -6737,12 +6881,12 @@ begin ObjLit.Name:=TJSString(TransformVariableName(El,AContext)); ObjLit.Expr:=CreateVarInit(El,AContext); end - else if AContext.IsSingleton then + else if AContext.IsGlobal then begin // create 'this.A=initvalue' AssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El)); Result:=AssignSt; - AssignSt.LHS:=CreateDeclNameExpression(El,El.Name,AContext); + AssignSt.LHS:=CreateSubDeclNameExpr(El,El.Name,AContext); AssignSt.Expr:=CreateVarInit(El,AContext); end else @@ -7026,8 +7170,8 @@ var New_Src:=TJSSourceElements(CreateElement(TJSSourceElements, El)); New_FuncContext:=TFunctionContext.Create(El,New_Src,ClassContext); try - New_FuncContext.This:=El; - New_FuncContext.IsSingleton:=true; + New_FuncContext.ThisPas:=El; + New_FuncContext.IsGlobal:=true; // add class members For I:=0 to El.Members.Count-1 do @@ -7056,7 +7200,7 @@ var begin AssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El)); NewEl:=AssignSt; - AssignSt.LHS:=CreateDeclNameExpression(P,P.Name,New_FuncContext); + AssignSt.LHS:=CreateSubDeclNameExpr(P,P.Name,New_FuncContext); AssignSt.Expr:=CreateLiteralUndefined(El); end; end; @@ -7087,7 +7231,7 @@ var end; end; - procedure AddRTTI(Src: TJSSourceElements; FuncContext: TConvertContext); + procedure AddRTTI(Src: TJSSourceElements; FuncContext: TFunctionContext); var HasRTTIMembers: Boolean; i: Integer; @@ -7095,6 +7239,9 @@ var NewEl: TJSElement; VarSt: TJSVariableStatement; begin + // add $r to local vars, to avoid name clashes and nicer debugging + FuncContext.AddLocalVar(FBuiltInNames[pbivnRTTILocal],nil); + HasRTTIMembers:=false; For i:=0 to El.Members.Count-1 do begin @@ -7122,6 +7269,7 @@ var VarSt:=CreateVarStatement(FBuiltInNames[pbivnRTTILocal], CreateMemberExpression(['this',FBuiltInNames[pbivnRTTI]]),El); AddToSourceElements(Src,VarSt); + HasRTTIMembers:=true; end; AddToSourceElements(Src,NewEl); @@ -7139,7 +7287,7 @@ var P: TPasElement; Scope: TPas2JSClassScope; Ancestor: TPasType; - AncestorPath: String; + AncestorPath, OwnerName: String; C: TClass; begin Result:=nil; @@ -7173,8 +7321,11 @@ begin else Call.Expr:=CreateMemberExpression([FBuiltInNames[pbivnRTL],FBuiltInNames[pbifnCreateClass]]); - // add parameter: owner. 'this' for top level class. - Call.AddArg(CreateBuiltInIdentifierExpr('this')); + // add parameter: owner. For top level class, the module is the owner. + OwnerName:=AContext.GetLocalName(El.GetModule); + if OwnerName='' then + OwnerName:='this'; + Call.AddArg(CreateBuiltInIdentifierExpr(OwnerName)); // add parameter: string constant '"classname"' ArgEx := CreateLiteralString(El,TransformVariableName(El,AContext)); @@ -7206,8 +7357,8 @@ begin // add members FuncContext:=TFunctionContext.Create(El,Src,AContext); - FuncContext.IsSingleton:=true; - FuncContext.This:=El; + FuncContext.IsGlobal:=true; + FuncContext.ThisPas:=El; // add class members: types and class vars For i:=0 to El.Members.Count-1 do begin @@ -7438,7 +7589,7 @@ begin begin // add 'this.TypeName = function(){}' AssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El)); - AssignSt.LHS:=CreateDeclNameExpression(El,El.Name,AContext); + AssignSt.LHS:=CreateSubDeclNameExpr(El,El.Name,AContext); AssignSt.Expr:=Obj; Result:=AssignSt; end; @@ -7481,7 +7632,7 @@ begin // add enumtype: this.TypeName TIProp:=TIObj.Elements.AddElement; TIProp.Name:=TJSString(FBuiltInNames[pbivnRTTIEnum_EnumType]); - TIProp.Expr:=CreateDeclNameExpression(El,El.Name,AContext); + TIProp.Expr:=CreateSubDeclNameExpr(El,El.Name,AContext); end; ok:=true; @@ -7779,6 +7930,15 @@ end; function TPasToJSConverter.ConvertProcedure(El: TPasProcedure; AContext: TConvertContext): TJSElement; +var + BodyJS: TJSFunctionBody; + FirstSt, LastSt: TJSStatementList; + + procedure AddBodyStatement(Add: TJSElement; Src: TPasElement); + begin + AddToStatementList(FirstSt,LastSt,Add,Src); + BodyJS.A:=FirstSt; + end; Var FS : TJSFunctionDeclarationStatement; @@ -7786,9 +7946,11 @@ Var n:Integer; AssignSt: TJSSimpleAssignStatement; FuncContext: TFunctionContext; - ProcScope: TPasProcedureScope; + ProcScope, ImplProcScope: TPasProcedureScope; Arg: TPasArgument; + SelfSt: TJSVariableStatement; ImplProc: TPasProcedure; + BodyPas: TProcedureBody; begin Result:=nil; @@ -7806,13 +7968,14 @@ begin ImplProc:=El; if ProcScope.ImplProc<>nil then ImplProc:=ProcScope.ImplProc; + ImplProcScope:=TPasProcedureScope(ImplProc.CustomData); AssignSt:=nil; - if AContext.IsSingleton then + if AContext.IsGlobal then begin AssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El)); Result:=AssignSt; - AssignSt.LHS:=CreateDeclNameExpression(El,El.Name,AContext); + AssignSt.LHS:=CreateSubDeclNameExpr(El,El.Name,AContext); end; FS:=CreateFunction(El,ImplProc.Body<>nil); @@ -7833,13 +7996,40 @@ begin if ImplProc.Body<>nil then begin + BodyPas:=ImplProc.Body; + BodyJS:=FD.Body; FuncContext:=TFunctionContext.Create(ImplProc,FD.Body,AContext); try + FirstSt:=nil; + LastSt:=nil; if ProcScope.ClassScope<>nil then - FuncContext.This:=ProcScope.ClassScope.Element - else - FuncContext.This:=AContext.GetThis; - FD.Body.A:=ConvertDeclarations(ImplProc.Body,FuncContext); + begin + // method or class method + FuncContext.ThisPas:=ProcScope.ClassScope.Element; + if ImplProc.Body.Functions.Count>0 then + begin + // has nested procs -> add "var self = this;" + FuncContext.AddLocalVar(FBuiltInNames[pbivnSelf],FuncContext.ThisPas); + SelfSt:=CreateVarStatement(FBuiltInNames[pbivnSelf], + CreateBuiltInIdentifierExpr('this'),El); + AddBodyStatement(SelfSt,BodyPas); + if ImplProcScope.SelfArg<>nil then + begin + // redirect Pascal-Self to JS-Self + FuncContext.AddLocalVar(FBuiltInNames[pbivnSelf],ImplProcScope.SelfArg); + end; + end + else + begin + if ImplProcScope.SelfArg<>nil then + begin + // no nested procs -> redirect Pascal-Self to JS-this + FuncContext.AddLocalVar('this',ImplProcScope.SelfArg); + end; + end; + end; + FuncContext.WriteStack; + AddBodyStatement(ConvertDeclarations(BodyPas,FuncContext),BodyPas); finally FuncContext.Free; end; @@ -7910,7 +8100,7 @@ var FuncContext: TFunctionContext; Body: TJSFunctionBody; begin - // create: 'this.$init=function(){}' + // create: '$mod.$init=function(){}' IsMain:=(El.Parent<>nil) and (El.Parent is TPasProgram); if IsMain then @@ -7923,14 +8113,15 @@ begin FuncContext:=nil; ok:=false; try - AssignSt.LHS:=CreateMemberExpression(['this',FunName]); + AssignSt.LHS:=CreateMemberExpression([FBuiltInNames[pbivnModule],FunName]); FDS:=CreateFunction(El,El.Elements.Count>0); AssignSt.Expr:=FDS; if El.Elements.Count>0 then begin Body:=FDS.AFunction.Body; FuncContext:=TFunctionContext.Create(El,Body,AContext); - FuncContext.This:=AContext.GetThis; + // Note: although the rtl sets 'this' as the module, the function can + // simply refer to $mod, so no need to set ThisPas here Body.A:=ConvertImplBlockElements(El,FuncContext,false); end; ok:=true; @@ -8197,6 +8388,7 @@ var ImplDecl: TJSElement; ImplVarSt: TJSVariableStatement; FunDecl: TJSFunctionDeclarationStatement; + ModVarName, ImplVarName: String; begin Result:=nil; // create function(){} @@ -8209,12 +8401,20 @@ begin if coUseStrict in Options then AddToSourceElements(Src,CreateLiteralString(El,'use strict')); - // add var $impl = this.$impl - ImplVarSt:=CreateVarStatement(FBuiltInNames[pbivnImplementation], - CreateMemberExpression(['this',FBuiltInNames[pbivnImplementation]]),El); - AddToSourceElements(Src,ImplVarSt); + // add "var $mod = this;" + ImplContext.ThisPas:=El; + ModVarName:=FBuiltInNames[pbivnModule]; + AddToSourceElements(Src,CreateVarStatement(ModVarName, + CreateBuiltInIdentifierExpr('this'),El)); + ImplContext.AddLocalVar(ModVarName,El); + + // add var $impl = $mod.$impl + ImplVarName:=FBuiltInNames[pbivnImplementation]; + ImplVarSt:=CreateVarStatement(ImplVarName, + CreateMemberExpression([ModVarName,ImplVarName]),El.ImplementationSection); + AddToSourceElements(Src,ImplVarSt); + ImplContext.AddLocalVar(ImplVarName,El.ImplementationSection); - ImplContext.This:=El; // create implementation declarations ImplDecl:=ConvertDeclarations(El.ImplementationSection,ImplContext); if ImplDecl=nil then @@ -8369,36 +8569,49 @@ end; function TPasToJSConverter.CreateCallback(El: TPasElement; ResolvedEl: TPasResolverResult; AContext: TConvertContext): TJSElement; +// El is a reference to a proc +// for a proc or nested proc simply use the function +// for a method create "rtl.createCallback(Target,func)" var Call: TJSCallExpression; - Scope: TJSElement; + Target: TJSElement; DotExpr: TJSDotMemberExpression; Prim: TJSPrimaryExpressionIdent; aName: String; DotPos: SizeInt; FunName: String; + ProcScope: TPasProcedureScope; begin - // create "rtl.createCallback(scope,func)" Result:=nil; if not (ResolvedEl.IdentEl is TPasProcedure) then RaiseInconsistency(20170215140756); + + Target:=ConvertElement(El,AContext); + + ProcScope:=TPasProcedureScope(ResolvedEl.IdentEl.CustomData); + if ProcScope.ClassScope=nil then + begin + // not a method -> simply use the function + Result:=Target; + exit; + end; + + // a method -> create "rtl.createCallback(Target,func)" Call:=nil; - Scope:=nil; try Call:=CreateCallExpression(El); // "rtl.createCallback" Call.Expr:=CreateMemberExpression([FBuiltInNames[pbivnRTL],FBuiltInNames[pbifnProcType_Create]]); // add parameters - Scope:=ConvertElement(El,AContext); {$IFDEF VerbosePas2JS} - writeln('TPasToJSConverter.CreateCallback ',GetObjName(Scope)); + writeln('TPasToJSConverter.CreateCallback ',GetObjName(Target)); {$ENDIF} FunName:=''; - // the last element of Scope is the proc, chomp that off - if Scope.ClassType=TJSDotMemberExpression then + // the last element of Target is the proc, chomp that off + if Target.ClassType=TJSDotMemberExpression then begin // chomp dot member -> rtl.createCallback(scope,"FunName") - DotExpr:=TJSDotMemberExpression(Scope); + DotExpr:=TJSDotMemberExpression(Target); FunName:=String(DotExpr.Name); DotPos:=PosLast('.',FunName); if DotPos>0 then @@ -8410,7 +8623,7 @@ begin if not IsValidJSIdentifier(DotExpr.Name) then begin {$IFDEF VerbosePas2JS} - writeln('TPasToJSConverter.CreateCallback ',GetObjName(Scope),' DotExpr.Name="',DotExpr.Name,'"'); + writeln('TPasToJSConverter.CreateCallback ',GetObjName(Target),' DotExpr.Name="',DotExpr.Name,'"'); {$ENDIF} DoError(20170215161802,nInvalidFunctionReference,sInvalidFunctionReference,[],El); end; @@ -8419,58 +8632,48 @@ begin begin // e.g. path dot funname // delete DotExpr - Scope:=DotExpr.MExpr; + Target:=DotExpr.MExpr; DotExpr.MExpr:=nil; FreeAndNil(DotExpr); end; if not IsValidJSIdentifier(TJSString(FunName)) then begin {$IFDEF VerbosePas2JS} - writeln('TPasToJSConverter.CreateCallback ',GetObjName(Scope),' FunName="',FunName,'"'); + writeln('TPasToJSConverter.CreateCallback ',GetObjName(Target),' FunName="',FunName,'"'); {$ENDIF} DoError(20170215161802,nInvalidFunctionReference,sInvalidFunctionReference,[],El); end; - Call.AddArg(Scope); + Call.AddArg(Target); // add function name as parameter Call.AddArg(CreateLiteralString(El,FunName)); end - else if Scope.ClassType=TJSPrimaryExpressionIdent then + else if Target.ClassType=TJSPrimaryExpressionIdent then begin - Prim:=TJSPrimaryExpressionIdent(Scope); + Prim:=TJSPrimaryExpressionIdent(Target); aName:=String(Prim.Name); DotPos:=PosLast('.',aName); - if DotPos>0 then - begin - // chomp dotted identifier -> rtl.createCallback(scope,"FunName") - FunName:=copy(aName,DotPos+1); - Prim.Name:=TJSString(LeftStr(aName,DotPos-1)); - Call.AddArg(Prim); - // add function name as parameter - Call.AddArg(CreateLiteralString(El,FunName)); - end - else - begin - // nested proc -> rtl.createCallback(this,FunName) - FunName:=aName; - Prim.Name:='this'; - Call.AddArg(Prim); - // add function as parameter - Call.AddArg(CreateBuiltInIdentifierExpr(FunName)); - end; + if DotPos<1 then + DoError(20170418135806,nInvalidFunctionReference,sInvalidFunctionReference,[],El); + // chomp dotted identifier -> rtl.createCallback(scope,"FunName") + FunName:=copy(aName,DotPos+1); + Prim.Name:=TJSString(LeftStr(aName,DotPos-1)); + Call.AddArg(Prim); + // add function name as parameter + Call.AddArg(CreateLiteralString(El,FunName)); end else begin {$IFDEF VerbosePas2JS} - writeln('TPasToJSConverter.CreateCallback invalid Scope=',GetObjName(Scope)); + writeln('TPasToJSConverter.CreateCallback invalid Scope=',GetObjName(Target)); {$ENDIF} - RaiseNotSupported(El,AContext,20170215161210); + DoError(20170418135820,nInvalidFunctionReference,sInvalidFunctionReference,[],El); end; Result:=Call; finally if Result=nil then begin - Scope.Free; + Target.Free; Call.Free; end; end; @@ -8613,9 +8816,8 @@ begin if Parent is TPasSection then begin aModule:=Parent.Parent as TPasModule; - if AContext.GetThis=aModule then - aModName:='this' - else + aModName:=AContext.GetLocalName(aModule); + if aModName='' then aModName:=TransformModuleName(aModule,true,AContext); Bracket:=TJSBracketMemberExpression(CreateElement(TJSBracketMemberExpression,El)); Bracket.MExpr:=CreateMemberExpression([aModName,FBuiltInNames[pbivnRTTI]]); @@ -8691,22 +8893,20 @@ function TPasToJSConverter.CreateRTTINewType(El: TPasType; out ObjLit: TJSObjectLiteral): TJSCallExpression; // module.$rtti.$TiSomething("name",{}) var - ThisContext: TFunctionContext; RttiPath, TypeName: String; Call: TJSCallExpression; + aModule: TPasModule; begin Result:=nil; ObjLit:=nil; // get module path - ThisContext:=AContext.GetThisContext; - if ThisContext=nil then - RaiseInconsistency(20170411151517); - if ThisContext.This is TPasModule then - RttiPath:='this' - else - begin - RttiPath:=TransformModuleName(ThisContext.GetRootModule,true,AContext); - end; + aModule:=El.GetModule; + if aModule=nil then + RaiseInconsistency(20170418115552); + RttiPath:=AContext.GetLocalName(aModule); + if RttiPath='' then + RttiPath:=TransformModuleName(aContext.GetRootModule,true,AContext); + Call:=CreateCallExpression(El); try // module.$rtti.$ProcVar @@ -9867,6 +10067,7 @@ end; function TPasToJSConverter.CreateVarStatement(const aName: String; Init: TJSElement; El: TPasElement): TJSVariableStatement; +// craete "var aname = init" begin Result:=TJSVariableStatement(CreateElement(TJSVariableStatement,El)); Result.A:=CreateVarDecl(aName,Init,El); @@ -10132,13 +10333,8 @@ function TPasToJSConverter.CreateReferencePath(El: TPasElement; { Notes: - local var, argument or result variable, even higher lvl does not need a reference path local vars are also argument, result var, result variable - - 'this': - - in interface function (even nested) 'this' is the interface, - - in implementation function (even nested) 'this' is the implementation, - - in initialization 'this' is interface - - in method body 'this' is the instance - - in class method body 'this' is the class - with context uses the local $withnnn var + - auto created local var otherwise use absolute path } @@ -10196,15 +10392,18 @@ function TPasToJSConverter.CreateReferencePath(El: TPasElement; var FoundModule: TPasModule; - This, ParentEl: TPasElement; + ParentEl: TPasElement; Dot: TDotContext; - ThisContext: TFunctionContext; WithData: TPas2JSWithExprScope; ProcScope: TPasProcedureScope; + ShortName: String; + SelfContext: TFunctionContext; begin Result:=''; + {$IFDEF VerbosePas2JS} //writeln('TPasToJSConverter.CreateReferencePath START El=',GetObjName(El),' Parent=',GetObjName(El.Parent),' Context=',GetObjName(AContext),' ',GetObjName(AContext.GetThis)); //AContext.WriteStack; + {$ENDIF} if AContext is TDotContext then begin @@ -10273,49 +10472,47 @@ begin RaiseNotSupported(El,AContext,20170201172141,GetObjName(El)); if (El.CustomData is TPasProcedureScope) then begin + // proc: always use the the declaration, not the body ProcScope:=TPasProcedureScope(El.CustomData); if ProcScope.DeclarationProc<>nil then El:=ProcScope.DeclarationProc; end; - ThisContext:=AContext.GetThisContext; - if ThisContext<>nil then - This:=ThisContext.This - else - This:=nil; + ParentEl:=El.Parent; while ParentEl<>nil do begin if (ParentEl.CustomData is TPasProcedureScope) then begin + // proc: always use the the declaration, not the body ProcScope:=TPasProcedureScope(ParentEl.CustomData); if ProcScope.DeclarationProc<>nil then ParentEl:=ProcScope.DeclarationProc; end; + + // check if there is a local var + ShortName:=AContext.GetLocalName(ParentEl); + if ParentEl.ClassType=TImplementationSection then begin - // element is in an implementation section - if ParentEl=This then - Prepend(Result,'this') + // element is in an implementation section (not program/library section) + if ShortName<>'' then + Prepend(Result,ShortName) else begin + // in other unit -> use pas.unitname.$impl FoundModule:=El.GetModule; if FoundModule=nil then RaiseInconsistency(20161024192755); - if AContext.GetRootModule=FoundModule then - // in same unit -> use '$impl' - Prepend(Result,FBuiltInNames[pbivnImplementation]) - else - // in other unit -> use pas.unitname.$impl - Prepend(Result,TransformModuleName(FoundModule,true,AContext) - +'.'+FBuiltInNames[pbivnImplementation]); + Prepend(Result,TransformModuleName(FoundModule,true,AContext) + +'.'+FBuiltInNames[pbivnImplementation]); end; break; end else if ParentEl is TPasModule then begin // element is in an unit interface or program/library section - if ParentEl=This then - Prepend(Result,'this') + if ShortName<>'' then + Prepend(Result,ShortName) else Prepend(Result,TransformModuleName(TPasModule(ParentEl),true,AContext)); break; @@ -10323,16 +10520,21 @@ begin else if (ParentEl.ClassType=TPasClassType) or (ParentEl.ClassType=TPasRecordType) then begin - // element is a class or record + // parent is a class or record declaration if Full then Prepend(Result,ParentEl.Name) else begin - // Pascal and JS have similar scoping rules, so we can use 'this'. - Result:='this'; - if (ThisContext<>nil) and (not IsClassFunction(ThisContext.PasElement)) then + // Pascal and JS have similar scoping rules (we are not in a dotscope), + // so 'this' can be used. + if ShortName<>'' then + Result:=ShortName + else + Result:='this'; + SelfContext:=AContext.GetSelfContext; + if (SelfContext<>nil) and not IsClassFunction(SelfContext.PasElement) then begin - // 'this' is an class instance + // inside a method -> Self is a class instance if El is TPasVariable then begin //writeln('TPasToJSConverter.CreateReferencePath class var ',GetObjName(El),' This=',GetObjName(This)); @@ -10874,10 +11076,10 @@ Var Src: TJSSourceElements; begin Result:=nil; - if not AContext.IsSingleton then + if not AContext.IsGlobal then begin // local const are stored in interface/implementation - ConstContext:=AContext.GetSingletonFunc; + ConstContext:=AContext.GetGlobalFunc; if not (ConstContext.JSElement is TJSSourceElements) then begin {$IFDEF VerbosePas2JS} @@ -10904,7 +11106,7 @@ begin // create 'this.A=initvalue' AssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El)); Result:=AssignSt; - AssignSt.LHS:=CreateDeclNameExpression(El,El.Name,AContext); + AssignSt.LHS:=CreateSubDeclNameExpr(El,El.Name,AContext); AssignSt.Expr:=CreateVarInit(El,AContext); end; end; @@ -11027,7 +11229,7 @@ const VarAssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,PasVar)); AddToStatementList(First,Last,VarAssignSt,PasVar); if i=0 then IfSt.BTrue:=First; - VarAssignSt.LHS:=CreateDeclNameExpression(PasVar,PasVar.Name,FuncContext); + VarAssignSt.LHS:=CreateSubDeclNameExpr(PasVar,PasVar.Name,FuncContext); VarDotExpr:=TJSDotMemberExpression(CreateElement(TJSDotMemberExpression,PasVar)); VarAssignSt.Expr:=VarDotExpr; VarDotExpr.MExpr:=CreateBuiltInIdentifierExpr(SrcParamName); @@ -11228,7 +11430,7 @@ begin // add 'this.TypeName = function(){}' AssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El)); Result:=AssignSt; - AssignSt.LHS:=CreateDeclNameExpression(El,El.Name,AContext); + AssignSt.LHS:=CreateSubDeclNameExpr(El,El.Name,AContext); AssignSt.Expr:=FDS; end; FD:=FDS.AFunction; @@ -11236,8 +11438,8 @@ begin FD.Params.Add(SrcParamName); // create function body FuncContext:=TFunctionContext.Create(El,FD.Body,AContext); - FuncContext.This:=El; - FuncContext.IsSingleton:=true; + FuncContext.ThisPas:=El; + FuncContext.IsGlobal:=true; if El.Members.Count>0 then begin BodyFirst:=nil; diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas index 6b1d3088d0..d64a9b01a0 100644 --- a/packages/pastojs/tests/tcmodules.pas +++ b/packages/pastojs/tests/tcmodules.pas @@ -100,6 +100,7 @@ type procedure SetUp; override; procedure TearDown; override; Procedure Add(Line: string); virtual; + Procedure Add(const Lines: array of string); Procedure StartParsing; virtual; procedure ParseModule; virtual; procedure ParseProgram; virtual; @@ -344,6 +345,11 @@ type Procedure TestClass_ExternalOverrideFail; Procedure TestClass_ExternalVar; Procedure TestClass_Const; + Procedure TestClass_LocalVarSelfFail; + Procedure TestClass_ArgSelfFail; + Procedure TestClass_NestedSelf; + Procedure TestClass_NestedClassSelf; + Procedure TestClass_NestedCallInherited; // class of Procedure TestClassOf_Create; @@ -403,6 +409,7 @@ type Procedure TestProcType_PropertyDelphi; Procedure TestProcType_WithClassInstDoPropertyFPC; Procedure TestProcType_Nested; + Procedure TestProcType_NestedOfObject; Procedure TestProcType_Typecast; // pointer @@ -669,6 +676,14 @@ begin Source.Add(Line); end; +procedure TCustomTestModule.Add(const Lines: array of string); +var + i: Integer; +begin + for i:=low(Lines) to high(Lines) do + Add(Lines[i]); +end; + procedure TCustomTestModule.StartParsing; var Src: String; @@ -934,11 +949,11 @@ begin Arg:=JSModuleCallArgs.Elements.Elements[2]; CheckFunctionParam('module intf-function',Arg,FJSModuleSrc); - // search for this.$init or this.$main - the last statement + // search for $mod.$init or $mod.$main - the last statement if Module is TPasProgram then begin InitName:='$main'; - AssertEquals('this.'+InitName+' function 1',true,JSModuleSrc.Statements.Count>0); + AssertEquals('$mod.'+InitName+' function 1',true,JSModuleSrc.Statements.Count>0); end else InitName:='$init'; @@ -949,13 +964,13 @@ begin if LastNode is TJSSimpleAssignStatement then begin InitAssign:=LastNode as TJSSimpleAssignStatement; - if GetDottedIdentifier(InitAssign.LHS)='this.'+InitName then + if GetDottedIdentifier(InitAssign.LHS)='$mod.'+InitName then begin InitFunction:=InitAssign.Expr as TJSFunctionDeclarationStatement; FJSInitBody:=InitFunction.AFunction.Body as TJSFunctionBody; end else if Module is TPasProgram then - CheckDottedIdentifier('init function',InitAssign.LHS,'this.'+InitName); + CheckDottedIdentifier('init function',InitAssign.LHS,'$mod.'+InitName); end; end; @@ -1018,14 +1033,18 @@ var ActualSrc, ExpectedSrc, InitName: String; begin ActualSrc:=JSToStr(JSModuleSrc); - ExpectedSrc:=Statements; + ExpectedSrc:= + 'var $mod = this;'+LineEnding + +Statements; + if coUseStrict in Converter.Options then + ExpectedSrc:='"use strict";'+LineEnding+ExpectedSrc; if Module is TPasProgram then InitName:='$main' else InitName:='$init'; if (Module is TPasProgram) or (Trim(InitStatements)<>'') then ExpectedSrc:=ExpectedSrc+LineEnding - +'this.'+InitName+' = function () {'+LineEnding + +'$mod.'+InitName+' = function () {'+LineEnding +InitStatements +'};'+LineEnding; //writeln('TTestModule.CheckSource InitStatements="',InitStatements,'"'); @@ -1034,7 +1053,10 @@ begin if (JSImplementationSrc<>nil) then begin ActualSrc:=JSToStr(JSImplementationSrc); - ExpectedSrc:='var $impl = this.$impl;'+LineEnding+ImplStatements; + ExpectedSrc:= + 'var $mod = this;'+LineEnding + +'var $impl = $mod.$impl;'+LineEnding + +ImplStatements; end else begin @@ -1311,7 +1333,7 @@ begin StartProgram(false); Add('begin'); ConvertProgram; - CheckSource('TestEmptyProgramUseStrict','"use strict";',''); + CheckSource('TestEmptyProgramUseStrict','',''); end; procedure TTestModule.TestEmptyUnit; @@ -1335,7 +1357,7 @@ begin ConvertUnit; CheckSource('TestEmptyUnitUseStrict', LinesToStr([ - '"use strict";' + '' ]), ''); end; @@ -1479,15 +1501,15 @@ begin 'this.c = "";', '']), LinesToStr([ // this.$main - 'this.i = this.i;', - 'this.i = (this.b ? 1 : 0);', - 'this.b = this.b;', - 'this.b = this.i != 0;', - 'this.d = this.d;', - 'this.d = this.i;', - 'this.s = this.s;', - 'this.s = this.c;', - 'this.c = this.c;', + '$mod.i = $mod.i;', + '$mod.i = ($mod.b ? 1 : 0);', + '$mod.b = $mod.b;', + '$mod.b = $mod.i != 0;', + '$mod.d = $mod.d;', + '$mod.d = $mod.i;', + '$mod.s = $mod.s;', + '$mod.s = $mod.c;', + '$mod.c = $mod.c;', ''])); end; @@ -1526,15 +1548,15 @@ begin 'this.c = "";', '']), LinesToStr([ // this.$main - 'this.i = this.i;', - 'this.i = (this.b ? 1 : 0);', - 'this.b = this.b;', - 'this.b = this.i != 0;', - 'this.d = this.d;', - 'this.d = this.i;', - 'this.s = this.s;', - 'this.s = this.c;', - 'this.c = this.c;', + '$mod.i = $mod.i;', + '$mod.i = ($mod.b ? 1 : 0);', + '$mod.b = $mod.b;', + '$mod.b = $mod.i != 0;', + '$mod.d = $mod.d;', + '$mod.d = $mod.i;', + '$mod.s = $mod.s;', + '$mod.s = $mod.c;', + '$mod.c = $mod.c;', ''])); end; @@ -1571,7 +1593,7 @@ begin '};' ]), LinesToStr([ // this.$main - 'this.ProcA(3);' + '$mod.ProcA(3);' ])); end; @@ -1597,10 +1619,10 @@ begin 'this.i=0;' ]), LinesToStr([ // this.$main - 'this.i=this.FuncA();', - 'this.i=this.FuncA();', - 'this.FuncA();', - 'this.FuncA();' + '$mod.i=$mod.FuncA();', + '$mod.i=$mod.FuncA();', + '$mod.FuncA();', + '$mod.FuncA();' ])); end; @@ -1620,8 +1642,8 @@ begin '};' ]), LinesToStr([ // this.$main - 'this.ProcA();', - 'this.ProcA();' + '$mod.ProcA();', + '$mod.ProcA();' ])); end; @@ -1641,10 +1663,10 @@ begin 'this.Bar = 0;' ]), LinesToStr([ // this.$main - 'this.Bar+=1;', - 'this.Bar+=2;', - 'this.Bar-=1;', - 'this.Bar-=3;' + '$mod.Bar+=1;', + '$mod.Bar+=2;', + '$mod.Bar-=1;', + '$mod.Bar-=3;' ])); end; @@ -1665,10 +1687,10 @@ begin 'this.Bar = 0;' ]), LinesToStr([ // this.$main - 'this.Bar=3;', - 'this.Bar+=4;', - 'this.Bar-=5;', - 'this.Bar*=6;' + '$mod.Bar=3;', + '$mod.Bar+=4;', + '$mod.Bar-=5;', + '$mod.Bar*=6;' ])); end; @@ -1695,15 +1717,15 @@ begin 'this.vC = 0;' ]), LinesToStr([ // this.$main - 'this.vA = 1;', - 'this.vB = this.vA + this.vA;', - 'this.vB = Math.floor(this.vA / this.vB);', - 'this.vB = this.vA % this.vB;', - 'this.vB = (this.vA + (this.vA * this.vB)) + Math.floor(this.vA / this.vB);', - 'this.vC = -this.vA;', - 'this.vA = this.vA - this.vB;', - 'this.vB = this.vA;', - 'if (this.vA < this.vB){ this.vC = this.vA } else this.vC = this.vB;' + '$mod.vA = 1;', + '$mod.vB = $mod.vA + $mod.vA;', + '$mod.vB = Math.floor($mod.vA / $mod.vB);', + '$mod.vB = $mod.vA % $mod.vB;', + '$mod.vB = ($mod.vA + ($mod.vA * $mod.vB)) + Math.floor($mod.vA / $mod.vB);', + '$mod.vC = -$mod.vA;', + '$mod.vA = $mod.vA - $mod.vB;', + '$mod.vB = $mod.vA;', + 'if ($mod.vA < $mod.vB){ $mod.vC = $mod.vA } else $mod.vC = $mod.vB;' ])); end; @@ -1726,11 +1748,11 @@ begin 'this.vC = false;' ]), LinesToStr([ // this.$main - 'this.vA = this.vB && this.vC;', - 'this.vA = this.vB || this.vC;', - 'this.vA = true && this.vC;', - 'this.vA = (this.vB && this.vC) || (this.vA && this.vB);', - 'this.vA = !this.vB;' + '$mod.vA = $mod.vB && $mod.vC;', + '$mod.vA = $mod.vB || $mod.vC;', + '$mod.vA = true && $mod.vC;', + '$mod.vA = ($mod.vB && $mod.vC) || ($mod.vA && $mod.vB);', + '$mod.vA = !$mod.vB;' ])); end; @@ -1756,14 +1778,14 @@ begin 'this.vC = 0;' ]), LinesToStr([ // this.$main - 'this.vA = this.vB & this.vC;', - 'this.vA = this.vB | this.vC;', - 'this.vA = this.vB ^ this.vC;', - 'this.vA = this.vB << this.vC;', - 'this.vA = this.vB >>> this.vC;', - 'this.vA = 3 & this.vC;', - 'this.vA = (this.vB & this.vC) | (this.vA & this.vB);', - 'this.vA = ~this.vB;' + '$mod.vA = $mod.vB & $mod.vC;', + '$mod.vA = $mod.vB | $mod.vC;', + '$mod.vA = $mod.vB ^ $mod.vC;', + '$mod.vA = $mod.vB << $mod.vC;', + '$mod.vA = $mod.vB >>> $mod.vC;', + '$mod.vA = 3 & $mod.vC;', + '$mod.vA = ($mod.vB & $mod.vC) | ($mod.vA & $mod.vB);', + '$mod.vA = ~$mod.vB;' ])); end; @@ -1809,7 +1831,7 @@ begin ConvertUnit; CheckSource('TestUnitProcVar', LinesToStr([ // statements - 'var $impl = this.$impl;', + 'var $impl = $mod.$impl;', 'this.Proc1 = function () {', ' var v1 = 0;', '};', @@ -1839,12 +1861,12 @@ begin ConvertUnit; CheckSource('TestImplProc', LinesToStr([ // statements - 'var $impl = this.$impl;', + 'var $impl = $mod.$impl;', 'this.Proc1 = function () {', '};', '']), LinesToStr([ // this.$init - 'this.Proc1();', + '$mod.Proc1();', '$impl.Proc2();', '']), LinesToStr([ // implementation @@ -1902,7 +1924,7 @@ begin ' function Nesty(pA) {', ' var Result = 0;', ' var vB = 0;', - ' Result = (((pA + vB) + vC) + pD) + this.vInUnit;', + ' Result = (((pA + vB) + vC) + pD) + $mod.vInUnit;', ' return Result;', ' };', ' Result = (pA + vB) + vC;', @@ -1931,15 +1953,15 @@ begin CheckSource('TestForwardProc', LinesToStr([ // statements' 'this.FuncB = function (Bar) {', - ' this.FuncA(Bar);', + ' $mod.FuncA(Bar);', '};', 'this.FuncA = function (Bar) {', ' if (Bar == 3);', '};' ]), LinesToStr([ - 'this.FuncA(4);', - 'this.FuncB(5);' + '$mod.FuncA(4);', + '$mod.FuncB(5);' ]) ); end; @@ -1976,7 +1998,7 @@ begin '};' ]), LinesToStr([ - 'this.FuncA();' + '$mod.FuncA();' ]) ); end; @@ -2001,8 +2023,8 @@ begin 'this.i = 0;' ]), LinesToStr([ - 'this.i = this.Func1();', - 'this.i = this.Func1() + this.Func1();' + '$mod.i = $mod.Func1();', + '$mod.i = $mod.Func1() + $mod.Func1();' ])); end; @@ -2034,9 +2056,9 @@ begin 'this.i = 0;' ]), LinesToStr([ - 'if (this.Func2());', - 'if (this.i == this.Func1());', - 'if (this.i == this.Func1());' + 'if ($mod.Func2());', + 'if ($mod.i == $mod.Func1());', + 'if ($mod.i == $mod.Func1());' ])); end; @@ -2105,8 +2127,8 @@ begin '} while (!true);', 'while (true) break;', 'var $loopend1 = 2;', - 'for (this.i = 1; this.i <= $loopend1; this.i++) break;', - 'if (this.i > $loopend1) this.i--;' + 'for ($mod.i = 1; $mod.i <= $loopend1; $mod.i++) break;', + 'if ($mod.i > $loopend1) $mod.i--;' ])); end; @@ -2133,8 +2155,8 @@ begin '} while (!true);', 'while (true) continue;', 'var $loopend1 = 2;', - 'for (this.i = 1; this.i <= $loopend1; this.i++) continue;', - 'if (this.i > $loopend1) this.i--;' + 'for ($mod.i = 1; $mod.i <= $loopend1; $mod.i++) continue;', + 'if ($mod.i > $loopend1) $mod.i--;' ])); end; @@ -2157,8 +2179,8 @@ begin ]), LinesToStr([ 'console.log();', - 'this.i = get.item();', - 'this.i = apply.something("abc");' + '$mod.i = get.item();', + '$mod.i = apply.something("abc");' ])); end; @@ -2272,7 +2294,7 @@ begin ' vG = vG + 1;', ' vJ = vH + 2;', ' vI.set(vI.get()+3);', - ' this.DoIt(vG, vG, {', + ' $mod.DoIt(vG, vG, {', ' get: function () {', ' return vG;', ' },', @@ -2280,7 +2302,7 @@ begin ' vG = v;', ' }', ' });', - ' this.DoIt(vH, vH, {', + ' $mod.DoIt(vH, vH, {', ' get: function () {', ' return vJ;', ' },', @@ -2288,8 +2310,8 @@ begin ' vJ = v;', ' }', ' });', - ' this.DoIt(vI.get(), vI.get(), vI);', - ' this.DoIt(vJ, vJ, {', + ' $mod.DoIt(vI.get(), vI.get(), vI);', + ' $mod.DoIt(vJ, vJ, {', ' get: function () {', ' return vJ;', ' },', @@ -2301,8 +2323,8 @@ begin 'this.i = 0;' ]), LinesToStr([ - 'this.DoIt(this.i,this.i,{', - ' p: this,', + '$mod.DoIt($mod.i,$mod.i,{', + ' p: $mod,', ' get: function () {', ' return this.p.i;', ' },', @@ -2334,9 +2356,9 @@ begin '};', '']), LinesToStr([ - 'this.DoIt(1);', - 'this.DoIt$1(2, 3);', - 'this.DoIt$2(4.5);', + '$mod.DoIt(1);', + '$mod.DoIt$1(2, 3);', + '$mod.DoIt$2(4.5);', ''])); end; @@ -2358,8 +2380,8 @@ begin '};', '']), LinesToStr([ - 'this.DoIt(1);', - 'this.DoIt$1(2, 3);', + '$mod.DoIt(1);', + '$mod.DoIt$1(2, 3);', ''])); end; @@ -2385,15 +2407,15 @@ begin ConvertUnit; CheckSource('TestProcedureOverloadUnit', LinesToStr([ // statements - 'var $impl = this.$impl;', + 'var $impl = $mod.$impl;', 'this.DoIt = function (vI) {', '};', 'this.DoIt$1 = function (vI, vJ) {', '};', '']), LinesToStr([ // this.$init - 'this.DoIt(1);', - 'this.DoIt$1(2, 3);', + '$mod.DoIt(1);', + '$mod.DoIt$1(2, 3);', '$impl.DoIt$3(4,5,6);', '$impl.DoIt$4(7,8,9,10);', '$impl.DoIt$2(11,12,13,14,15);', @@ -2467,49 +2489,49 @@ begin CheckSource('TestProcedureOverloadNested', LinesToStr([ // statements 'this.DoIt$1 = function (vB, vC) {', - ' this.DoIt(1);', - ' this.DoIt$1(1, 2);', + ' $mod.DoIt(1);', + ' $mod.DoIt$1(1, 2);', '};', 'this.DoIt = function (vA) {', ' function DoIt$3(vA, vB, vC, vD) {', - ' this.DoIt(1);', - ' this.DoIt$1(1, 2);', + ' $mod.DoIt(1);', + ' $mod.DoIt$1(1, 2);', ' DoIt$2(1, 2, 3);', ' DoIt$3(1, 2, 3, 4);', ' };', ' function DoIt$2(vA, vB, vC) {', ' function DoIt$5(vA, vB, vC, vD, vE, vF) {', - ' this.DoIt(1);', - ' this.DoIt$1(1, 2);', + ' $mod.DoIt(1);', + ' $mod.DoIt$1(1, 2);', ' DoIt$2(1, 2, 3);', ' DoIt$3(1, 2, 3, 4);', ' DoIt$4(1, 2, 3, 4, 5);', ' DoIt$5(1, 2, 3, 4, 5, 6);', ' };', ' function DoIt$4(vA, vB, vC, vD, vE) {', - ' this.DoIt(1);', - ' this.DoIt$1(1, 2);', + ' $mod.DoIt(1);', + ' $mod.DoIt$1(1, 2);', ' DoIt$2(1, 2, 3);', ' DoIt$3(1, 2, 3, 4);', ' DoIt$4(1, 2, 3, 4, 5);', ' DoIt$5(1, 2, 3, 4, 5, 6);', ' };', - ' this.DoIt(1);', - ' this.DoIt$1(1, 2);', + ' $mod.DoIt(1);', + ' $mod.DoIt$1(1, 2);', ' DoIt$2(1, 2, 3);', ' DoIt$3(1, 2, 3, 4);', ' DoIt$4(1, 2, 3, 4, 5);', ' DoIt$5(1, 2, 3, 4, 5, 6);', ' };', - ' this.DoIt(1);', - ' this.DoIt$1(1, 2);', + ' $mod.DoIt(1);', + ' $mod.DoIt$1(1, 2);', ' DoIt$2(1, 2, 3);', ' DoIt$3(1, 2, 3, 4);', '};', '']), LinesToStr([ - 'this.DoIt(1);', - 'this.DoIt$1(1, 2);', + '$mod.DoIt(1);', + '$mod.DoIt$1(1, 2);', ''])); end; @@ -2563,9 +2585,9 @@ begin 'ProcC(17);', 'ProcC(4);', 'ProcC(5, "foo");', - 'ProcB(this.GetIt());', - 'ProcB(this.GetIt());', - 'ProcB(this.GetIt(), this.GetIt());', + 'ProcB($mod.GetIt());', + 'ProcB($mod.GetIt());', + 'ProcB($mod.GetIt(), $mod.GetIt());', ''])); end; @@ -2589,10 +2611,10 @@ begin ' Blue:2', ' };', 'this.e = 0;', - 'this.f = this.TMyEnum.Blue;' + 'this.f = $mod.TMyEnum.Blue;' ]), LinesToStr([ - 'this.e=this.TMyEnum.Green;' + '$mod.e=$mod.TMyEnum.Green;' ])); end; @@ -2619,7 +2641,7 @@ begin 'this.f = 1;' ]), LinesToStr([ - 'this.e=1;' + '$mod.e=1;' ])); end; @@ -2662,22 +2684,22 @@ begin 'this.s = "";' ]), LinesToStr([ - 'this.i=this.TMyEnum.Red;', - 'this.i=this.TMyEnum.Green;', - 'this.i=this.e;', - 'this.e=this.TMyEnum.Red;', - 'this.e=this.TMyEnum.Red;', - 'this.e=this.TMyEnum.Green;', - 'this.e=this.TMyEnum.Green;', - 'this.e=this.TMyEnum.Green-1;', - 'this.e=this.e-1;', - 'this.e=this.TMyEnum.Red+1;', - 'this.e=this.e+1;', - 'this.e=1;', - 'this.e=this.i;', - 'this.s = this.TMyEnum[this.e];', - 'this.s = this.TMyEnum[this.e];', - 'this.s = rtl.spaceLeft(this.TMyEnum[this.e], 3);', + '$mod.i=$mod.TMyEnum.Red;', + '$mod.i=$mod.TMyEnum.Green;', + '$mod.i=$mod.e;', + '$mod.e=$mod.TMyEnum.Red;', + '$mod.e=$mod.TMyEnum.Red;', + '$mod.e=$mod.TMyEnum.Green;', + '$mod.e=$mod.TMyEnum.Green;', + '$mod.e=$mod.TMyEnum.Green-1;', + '$mod.e=$mod.e-1;', + '$mod.e=$mod.TMyEnum.Red+1;', + '$mod.e=$mod.e+1;', + '$mod.e=1;', + '$mod.e=$mod.i;', + '$mod.s = $mod.TMyEnum[$mod.e];', + '$mod.s = $mod.TMyEnum[$mod.e];', + '$mod.s = rtl.spaceLeft($mod.TMyEnum[$mod.e], 3);', ''])); end; @@ -2713,7 +2735,7 @@ begin ' vG = vG;', ' vJ = vH;', ' vI.set(vI.get());', - ' this.DoIt(vG, vG, {', + ' $mod.DoIt(vG, vG, {', ' get: function () {', ' return vG;', ' },', @@ -2721,7 +2743,7 @@ begin ' vG = v;', ' }', ' });', - ' this.DoIt(vH, vH, {', + ' $mod.DoIt(vH, vH, {', ' get: function () {', ' return vJ;', ' },', @@ -2729,8 +2751,8 @@ begin ' vJ = v;', ' }', ' });', - ' this.DoIt(vI.get(), vI.get(), vI);', - ' this.DoIt(vJ, vJ, {', + ' $mod.DoIt(vI.get(), vI.get(), vI);', + ' $mod.DoIt(vJ, vJ, {', ' get: function () {', ' return vJ;', ' },', @@ -2742,8 +2764,8 @@ begin 'this.i = 0;' ]), LinesToStr([ - 'this.DoIt(this.i,this.i,{', - ' p: this,', + '$mod.DoIt($mod.i,$mod.i,{', + ' p: $mod,', ' get: function () {', ' return this.p.i;', ' },', @@ -2787,16 +2809,16 @@ begin 'this.c = 0;', 'this.s = {};', 'this.t = {};', - 'this.u = rtl.createSet(this.TColor.Red);' + 'this.u = rtl.createSet($mod.TColor.Red);' ]), LinesToStr([ - 'this.s={};', - 'this.s=rtl.createSet(this.TColor.Green);', - 'this.s=rtl.createSet(this.TColor.Green,this.TColor.Blue);', - 'this.s=rtl.createSet(null,this.TColor.Red,this.TColor.Blue);', - 'this.s=rtl.createSet(this.TColor.Red,null,this.TColor.Green,this.TColor.Blue);', - 'this.s=rtl.createSet(this.TColor.Red,this.c);', - 'this.s=rtl.refSet(this.t);', + '$mod.s={};', + '$mod.s=rtl.createSet($mod.TColor.Green);', + '$mod.s=rtl.createSet($mod.TColor.Green,$mod.TColor.Blue);', + '$mod.s=rtl.createSet(null,$mod.TColor.Red,$mod.TColor.Blue);', + '$mod.s=rtl.createSet($mod.TColor.Red,null,$mod.TColor.Green,$mod.TColor.Blue);', + '$mod.s=rtl.createSet($mod.TColor.Red,$mod.c);', + '$mod.s=rtl.refSet($mod.t);', ''])); end; @@ -2865,40 +2887,40 @@ begin 'this.B = false;' ]), LinesToStr([ - 'this.vS = rtl.includeSet(this.vS,this.TColor.Green);', - 'this.vS = rtl.excludeSet(this.vS,this.vC);', - 'this.vS = rtl.unionSet(this.vT, this.vU);', - 'this.vS = rtl.unionSet(this.vT, rtl.createSet(this.TColor.Red));', - 'this.vS = rtl.unionSet(rtl.createSet(this.TColor.Red), this.vT);', - 'this.vS = rtl.unionSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));', - 'this.vS = rtl.diffSet(this.vT, this.vU);', - 'this.vS = rtl.diffSet(this.vT, rtl.createSet(this.TColor.Red));', - 'this.vS = rtl.diffSet(rtl.createSet(this.TColor.Red), this.vT);', - 'this.vS = rtl.diffSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));', - 'this.vS = rtl.intersectSet(this.vT, this.vU);', - 'this.vS = rtl.intersectSet(this.vT, rtl.createSet(this.TColor.Red));', - 'this.vS = rtl.intersectSet(rtl.createSet(this.TColor.Red), this.vT);', - 'this.vS = rtl.intersectSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));', - 'this.vS = rtl.symDiffSet(this.vT, this.vU);', - 'this.vS = rtl.symDiffSet(this.vT, rtl.createSet(this.TColor.Red));', - 'this.vS = rtl.symDiffSet(rtl.createSet(this.TColor.Red), this.vT);', - 'this.vS = rtl.symDiffSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));', - 'this.B = rtl.eqSet(this.vT, this.vU);', - 'this.B = rtl.eqSet(this.vT, rtl.createSet(this.TColor.Red));', - 'this.B = rtl.eqSet(rtl.createSet(this.TColor.Red), this.vT);', - 'this.B = rtl.eqSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));', - 'this.B = rtl.neSet(this.vT, this.vU);', - 'this.B = rtl.neSet(this.vT, rtl.createSet(this.TColor.Red));', - 'this.B = rtl.neSet(rtl.createSet(this.TColor.Red), this.vT);', - 'this.B = rtl.neSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));', - 'this.B = rtl.leSet(this.vT, this.vU);', - 'this.B = rtl.leSet(this.vT, rtl.createSet(this.TColor.Red));', - 'this.B = rtl.leSet(rtl.createSet(this.TColor.Red), this.vT);', - 'this.B = rtl.leSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));', - 'this.B = rtl.geSet(this.vT, this.vU);', - 'this.B = rtl.geSet(this.vT, rtl.createSet(this.TColor.Red));', - 'this.B = rtl.geSet(rtl.createSet(this.TColor.Red), this.vT);', - 'this.B = rtl.geSet(rtl.createSet(this.TColor.Red), rtl.createSet(this.TColor.Green));', + '$mod.vS = rtl.includeSet($mod.vS,$mod.TColor.Green);', + '$mod.vS = rtl.excludeSet($mod.vS,$mod.vC);', + '$mod.vS = rtl.unionSet($mod.vT, $mod.vU);', + '$mod.vS = rtl.unionSet($mod.vT, rtl.createSet($mod.TColor.Red));', + '$mod.vS = rtl.unionSet(rtl.createSet($mod.TColor.Red), $mod.vT);', + '$mod.vS = rtl.unionSet(rtl.createSet($mod.TColor.Red), rtl.createSet($mod.TColor.Green));', + '$mod.vS = rtl.diffSet($mod.vT, $mod.vU);', + '$mod.vS = rtl.diffSet($mod.vT, rtl.createSet($mod.TColor.Red));', + '$mod.vS = rtl.diffSet(rtl.createSet($mod.TColor.Red), $mod.vT);', + '$mod.vS = rtl.diffSet(rtl.createSet($mod.TColor.Red), rtl.createSet($mod.TColor.Green));', + '$mod.vS = rtl.intersectSet($mod.vT, $mod.vU);', + '$mod.vS = rtl.intersectSet($mod.vT, rtl.createSet($mod.TColor.Red));', + '$mod.vS = rtl.intersectSet(rtl.createSet($mod.TColor.Red), $mod.vT);', + '$mod.vS = rtl.intersectSet(rtl.createSet($mod.TColor.Red), rtl.createSet($mod.TColor.Green));', + '$mod.vS = rtl.symDiffSet($mod.vT, $mod.vU);', + '$mod.vS = rtl.symDiffSet($mod.vT, rtl.createSet($mod.TColor.Red));', + '$mod.vS = rtl.symDiffSet(rtl.createSet($mod.TColor.Red), $mod.vT);', + '$mod.vS = rtl.symDiffSet(rtl.createSet($mod.TColor.Red), rtl.createSet($mod.TColor.Green));', + '$mod.B = rtl.eqSet($mod.vT, $mod.vU);', + '$mod.B = rtl.eqSet($mod.vT, rtl.createSet($mod.TColor.Red));', + '$mod.B = rtl.eqSet(rtl.createSet($mod.TColor.Red), $mod.vT);', + '$mod.B = rtl.eqSet(rtl.createSet($mod.TColor.Red), rtl.createSet($mod.TColor.Green));', + '$mod.B = rtl.neSet($mod.vT, $mod.vU);', + '$mod.B = rtl.neSet($mod.vT, rtl.createSet($mod.TColor.Red));', + '$mod.B = rtl.neSet(rtl.createSet($mod.TColor.Red), $mod.vT);', + '$mod.B = rtl.neSet(rtl.createSet($mod.TColor.Red), rtl.createSet($mod.TColor.Green));', + '$mod.B = rtl.leSet($mod.vT, $mod.vU);', + '$mod.B = rtl.leSet($mod.vT, rtl.createSet($mod.TColor.Red));', + '$mod.B = rtl.leSet(rtl.createSet($mod.TColor.Red), $mod.vT);', + '$mod.B = rtl.leSet(rtl.createSet($mod.TColor.Red), rtl.createSet($mod.TColor.Green));', + '$mod.B = rtl.geSet($mod.vT, $mod.vU);', + '$mod.B = rtl.geSet($mod.vT, rtl.createSet($mod.TColor.Red));', + '$mod.B = rtl.geSet(rtl.createSet($mod.TColor.Red), $mod.vT);', + '$mod.B = rtl.geSet(rtl.createSet($mod.TColor.Red), rtl.createSet($mod.TColor.Green));', ''])); end; @@ -2938,15 +2960,15 @@ begin 'this.B = false;' ]), LinesToStr([ - 'this.B = this.TColor.Red in this.vT;', - 'this.B = this.vC in this.vT;', - 'this.B = this.TColor.Green in rtl.createSet(null, this.TColor.Red, this.TColor.Blue);', - 'this.B = this.vC in rtl.createSet(null, this.TColor.Red, this.TColor.Blue);', - 'if (this.TColor.Red in this.vT) ;', - 'while (this.vC in this.vT) {', + '$mod.B = $mod.TColor.Red in $mod.vT;', + '$mod.B = $mod.vC in $mod.vT;', + '$mod.B = $mod.TColor.Green in rtl.createSet(null, $mod.TColor.Red, $mod.TColor.Blue);', + '$mod.B = $mod.vC in rtl.createSet(null, $mod.TColor.Red, $mod.TColor.Blue);', + 'if ($mod.TColor.Red in $mod.vT) ;', + 'while ($mod.vC in $mod.vT) {', '};', 'do {', - '} while (!(this.vC in this.vT));', + '} while (!($mod.vC in $mod.vT));', ''])); end; @@ -2977,10 +2999,10 @@ begin 'this.s = {};' ]), LinesToStr([ - 'this.e=this.TMyEnum.Red;', - 'this.e=this.TMyEnum.Red;', - 'this.e=this.TMyEnum.Green;', - 'this.e=this.TMyEnum.Green;', + '$mod.e=$mod.TMyEnum.Red;', + '$mod.e=$mod.TMyEnum.Red;', + '$mod.e=$mod.TMyEnum.Green;', + '$mod.e=$mod.TMyEnum.Green;', ''])); end; @@ -3013,8 +3035,8 @@ begin 'this.aSet = {};' ]), LinesToStr([ - 'this.DoDefault(rtl.refSet(this.aSet));', - 'this.DoConst(this.aSet);', + '$mod.DoDefault(rtl.refSet($mod.aSet));', + '$mod.DoConst($mod.aSet);', ''])); end; @@ -3051,7 +3073,7 @@ begin ' vG = rtl.refSet(vG);', ' vJ = rtl.refSet(vH);', ' vI.set(rtl.refSet(vI.get()));', - ' this.DoIt(rtl.refSet(vG), vG, {', + ' $mod.DoIt(rtl.refSet(vG), vG, {', ' get: function () {', ' return vG;', ' },', @@ -3059,7 +3081,7 @@ begin ' vG = v;', ' }', ' });', - ' this.DoIt(rtl.refSet(vH), vH, {', + ' $mod.DoIt(rtl.refSet(vH), vH, {', ' get: function () {', ' return vJ;', ' },', @@ -3067,8 +3089,8 @@ begin ' vJ = v;', ' }', ' });', - ' this.DoIt(rtl.refSet(vI.get()), vI.get(), vI);', - ' this.DoIt(rtl.refSet(vJ), vJ, {', + ' $mod.DoIt(rtl.refSet(vI.get()), vI.get(), vI);', + ' $mod.DoIt(rtl.refSet(vJ), vJ, {', ' get: function () {', ' return vJ;', ' },', @@ -3080,8 +3102,8 @@ begin 'this.i = {};' ]), LinesToStr([ - 'this.DoIt(rtl.refSet(this.i),this.i,{', - ' p: this,', + '$mod.DoIt(rtl.refSet($mod.i),$mod.i,{', + ' p: $mod,', ' get: function () {', ' return this.p.i;', ' },', @@ -3119,7 +3141,7 @@ begin ' "1": "Blue",', ' Blue: 1', '};', - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -3130,8 +3152,8 @@ begin 'this.Obj = null;', '']), LinesToStr([ - 'this.Obj.SetColors(rtl.includeSet(this.Obj.GetColors(), this.TEnum.Red));', - 'this.Obj.SetColors(rtl.excludeSet(this.Obj.GetColors(), this.TEnum.Red));', + '$mod.Obj.SetColors(rtl.includeSet($mod.Obj.GetColors(), $mod.TEnum.Red));', + '$mod.Obj.SetColors(rtl.excludeSet($mod.Obj.GetColors(), $mod.TEnum.Red));', ''])); end; @@ -3160,15 +3182,15 @@ begin ' "1": "Blue",', ' Blue: 1', '};', - 'this.Orange = this.TEnum.Red;', + 'this.Orange = $mod.TEnum.Red;', 'this.Enum = 0;', 'this.Enums = {};', '']), LinesToStr([ - 'this.Enums = rtl.includeSet(this.Enums, this.Orange);', - 'this.Enums = rtl.excludeSet(this.Enums, this.Orange);', - 'if (this.Orange in this.Enums) ;', - 'if (this.Orange in rtl.createSet(this.Orange, this.TEnum.Red)) ;', + '$mod.Enums = rtl.includeSet($mod.Enums, $mod.Orange);', + '$mod.Enums = rtl.excludeSet($mod.Enums, $mod.Orange);', + 'if ($mod.Orange in $mod.Enums) ;', + 'if ($mod.Orange in rtl.createSet($mod.Orange, $mod.TEnum.Red)) ;', ''])); end; @@ -3203,22 +3225,22 @@ begin ' "1": "green",', ' green: 1', '};', - 'this.favorite = this.TFlags$a.red;', + 'this.favorite = $mod.TFlags$a.red;', 'this.f = {};', 'this.i = 0;', '']), LinesToStr([ - 'this.f = rtl.includeSet(this.f, this.TFlags$a.red);', - 'this.f = rtl.includeSet(this.f, this.favorite);', - 'this.i = this.TFlags$a.red;', - 'this.i = this.favorite;', - 'this.i = this.TFlags$a.red;', - 'this.i = this.TFlags$a.red;', - 'this.i = this.TFlags$a.red;', - 'this.i = this.TFlags$a.green;', - 'this.i = this.TFlags$a.green;', - 'this.i = this.TFlags$a.green;', - 'this.f = rtl.createSet(this.TFlags$a.green, this.favorite);', + '$mod.f = rtl.includeSet($mod.f, $mod.TFlags$a.red);', + '$mod.f = rtl.includeSet($mod.f, $mod.favorite);', + '$mod.i = $mod.TFlags$a.red;', + '$mod.i = $mod.favorite;', + '$mod.i = $mod.TFlags$a.red;', + '$mod.i = $mod.TFlags$a.red;', + '$mod.i = $mod.TFlags$a.red;', + '$mod.i = $mod.TFlags$a.green;', + '$mod.i = $mod.TFlags$a.green;', + '$mod.i = $mod.TFlags$a.green;', + '$mod.f = rtl.createSet($mod.TFlags$a.green, $mod.favorite);', ''])); end; @@ -3262,16 +3284,16 @@ begin CheckSource('TestSet_ConstChar', LinesToStr([ // statements 'this.LowChars = rtl.createSet(null, 97, 122);', - 'this.Chars = rtl.unionSet(this.LowChars, rtl.createSet(null, 65, 90));', + 'this.Chars = rtl.unionSet($mod.LowChars, rtl.createSet(null, 65, 90));', 'this.c = "";', 'this.s = "";', '']), LinesToStr([ - 'if (this.c.charCodeAt() in this.LowChars) ;', - 'if (97 in this.LowChars) ;', - 'if (this.s.charCodeAt(1 - 1) in this.LowChars) ;', - 'if (this.c.charCodeAt() in this.Chars) ;', - 'if (this.c.charCodeAt() in rtl.createSet(null, 97, 122, 95)) ;', + 'if ($mod.c.charCodeAt() in $mod.LowChars) ;', + 'if (97 in $mod.LowChars) ;', + 'if ($mod.s.charCodeAt(1 - 1) in $mod.LowChars) ;', + 'if ($mod.c.charCodeAt() in $mod.Chars) ;', + 'if ($mod.c.charCodeAt() in rtl.createSet(null, 97, 122, 95)) ;', 'if (98 in rtl.createSet(null, 97, 122, 95)) ;', ''])); end; @@ -3305,7 +3327,7 @@ begin ConvertUnit; CheckSource('TestUnitImplVars', LinesToStr([ // statements - 'var $impl = this.$impl;', + 'var $impl = $mod.$impl;', '']), '', // this.$init LinesToStr([ // implementation @@ -3327,7 +3349,7 @@ begin ConvertUnit; CheckSource('TestUnitImplConsts', LinesToStr([ // statements - 'var $impl = this.$impl;', + 'var $impl = $mod.$impl;', '']), '', // this.$init LinesToStr([ // implementation @@ -3352,7 +3374,7 @@ begin ConvertUnit; CheckSource('TestUnitImplRecord', LinesToStr([ // statements - 'var $impl = this.$impl;', + 'var $impl = $mod.$impl;', '']), // this.$init '$impl.aRec.i = 3;', @@ -3442,7 +3464,7 @@ begin 'this.d = 0.0;' ]), LinesToStr([ - 'this.d = Global.NaN;' + '$mod.d = Global.NaN;' ])); end; @@ -3472,7 +3494,7 @@ begin ConvertUnit; CheckSource('TestVarExternalOtherUnit', LinesToStr([ - 'var $impl = this.$impl;', + 'var $impl = $mod.$impl;', '']), LinesToStr([ // this.$init '$impl.d = Global.NaN;', @@ -3513,19 +3535,19 @@ begin 'this.c="1";' ]), LinesToStr([ - 'this.c="\x00";', - 'this.c="\x01";', - 'this.c="\t";', - 'this.c="\n";', - 'this.c="\r";', - 'this.c="\x1F";', - 'this.c=" ";', - 'this.c="\n";', - 'this.c="\n";', - 'this.c="\x0B";', - 'this.c="\x0B";', - 'this.c="\x01";', - 'this.c=''"'';' + '$mod.c="\x00";', + '$mod.c="\x01";', + '$mod.c="\t";', + '$mod.c="\n";', + '$mod.c="\r";', + '$mod.c="\x1F";', + '$mod.c=" ";', + '$mod.c="\n";', + '$mod.c="\n";', + '$mod.c="\x0B";', + '$mod.c="\x0B";', + '$mod.c="\x01";', + '$mod.c=''"'';' ])); end; @@ -3556,19 +3578,19 @@ begin 'this.b = false;' ]), LinesToStr([ - 'this.b = this.c == "1";', - 'this.b = "2" == this.c;', - 'this.b = "3" == "4";', - 'this.b = this.c != "5";', - 'this.b = "6" != this.c;', - 'this.b = this.c > "7";', - 'this.b = "8" > this.c;', - 'this.b = this.c >= "9";', - 'this.b = "A" >= this.c;', - 'this.b = this.c < "B";', - 'this.b = "C" < this.c;', - 'this.b = this.c <= "D";', - 'this.b = "E" <= this.c;', + '$mod.b = $mod.c == "1";', + '$mod.b = "2" == $mod.c;', + '$mod.b = "3" == "4";', + '$mod.b = $mod.c != "5";', + '$mod.b = "6" != $mod.c;', + '$mod.b = $mod.c > "7";', + '$mod.b = "8" > $mod.c;', + '$mod.b = $mod.c >= "9";', + '$mod.b = "A" >= $mod.c;', + '$mod.b = $mod.c < "B";', + '$mod.b = "C" < $mod.c;', + '$mod.b = $mod.c <= "D";', + '$mod.b = "E" <= $mod.c;', ''])); end; @@ -3590,8 +3612,8 @@ begin 'this.s = "";' ]), LinesToStr([ - 'this.i = this.c.charCodeAt();', - 'this.i = this.s.charCodeAt(this.i-1);', + '$mod.i = $mod.c.charCodeAt();', + '$mod.i = $mod.s.charCodeAt($mod.i-1);', ''])); end; @@ -3610,7 +3632,7 @@ begin 'this.i = 0;' ]), LinesToStr([ - 'this.c = String.fromCharCode(this.i);', + '$mod.c = String.fromCharCode($mod.i);', ''])); end; @@ -3633,13 +3655,13 @@ begin 'this.s="abc";' ]), LinesToStr([ - 'this.s="";', - 'this.s="\r\n";', - 'this.s="\tfoo";', - 'this.s="©";', - 'this.s="foo\rbar";', - 'this.s=''"'';', - 'this.s=''"\''"'';' + '$mod.s="";', + '$mod.s="\r\n";', + '$mod.s="\tfoo";', + '$mod.s="©";', + '$mod.s="foo\rbar";', + '$mod.s=''"'';', + '$mod.s=''"\''"'';' ])); end; @@ -3663,10 +3685,10 @@ begin 'this.i = 0;', '']), LinesToStr([ - 'this.i = this.s.length;', - 'this.i = (this.s+this.s).length;', - 'this.i = "abc".length;', - 'this.i = this.c.length;', + '$mod.i = $mod.s.length;', + '$mod.i = ($mod.s+$mod.s).length;', + '$mod.i = "abc".length;', + '$mod.i = $mod.c.length;', ''])); end; @@ -3691,12 +3713,12 @@ begin 'this.b =false;' ]), LinesToStr([ // this.$main - 'this.b = this.s == this.t;', - 'this.b = this.s != this.t;', - 'this.b = this.s > this.t;', - 'this.b = this.s >= this.t;', - 'this.b = this.s < this.t;', - 'this.b = this.s <= this.t;', + '$mod.b = $mod.s == $mod.t;', + '$mod.b = $mod.s != $mod.t;', + '$mod.b = $mod.s > $mod.t;', + '$mod.b = $mod.s >= $mod.t;', + '$mod.b = $mod.s < $mod.t;', + '$mod.b = $mod.s <= $mod.t;', ''])); end; @@ -3712,7 +3734,7 @@ begin 'this.s = "";' ]), LinesToStr([ // this.$main - 'this.s.length = 3;' + '$mod.s.length = 3;' ])); end; @@ -3740,14 +3762,14 @@ begin 'this.b = false;' ]), LinesToStr([ // this.$main - 'this.b = this.s.charAt(1-1) == this.c;', - 'this.b = this.c == this.s.charAt(1 - 1);', - 'this.b = this.c != this.s.charAt(1 - 1);', - 'this.b = this.c > this.s.charAt(1 - 1);', - 'this.b = this.c >= this.s.charAt(1 - 1);', - 'this.b = this.c < this.s.charAt(1 - 1);', - 'this.b = this.c <= this.s.charAt(1 - 1);', - 'this.s = rtl.setCharAt(this.s, 1, this.c);', + '$mod.b = $mod.s.charAt(1-1) == $mod.c;', + '$mod.b = $mod.c == $mod.s.charAt(1 - 1);', + '$mod.b = $mod.c != $mod.s.charAt(1 - 1);', + '$mod.b = $mod.c > $mod.s.charAt(1 - 1);', + '$mod.b = $mod.c >= $mod.s.charAt(1 - 1);', + '$mod.b = $mod.c < $mod.s.charAt(1 - 1);', + '$mod.b = $mod.c <= $mod.s.charAt(1 - 1);', + '$mod.s = rtl.setCharAt($mod.s, 1, $mod.c);', ''])); end; @@ -3785,22 +3807,22 @@ begin 'this.s = "";', '']), LinesToStr([ // this.$main - 'this.s = ""+this.b;', - 'this.s = ""+this.i;', - 'this.s = ""+this.d;', - 'this.s = rtl.spaceLeft(""+this.i,3);', - 'this.s = rtl.spaceLeft(this.d.toFixed(2),3);', - 'this.s = ""+this.b;', - 'this.s = ""+this.i;', - 'this.s = ""+this.d;', - 'this.s = (""+this.i)+this.i;', - 'this.s = rtl.spaceLeft(""+this.i,3);', - 'this.s = rtl.spaceLeft(this.d.toFixed(2),3);', - 'this.s = rtl.spaceLeft("" + this.i, 4) + this.i;', - 'this.s = ("" + this.i) + rtl.spaceLeft("" + this.i, 5);', - 'this.s = rtl.spaceLeft("" + this.i, 4) + rtl.spaceLeft("" + this.i, 5);', - 'this.s = this.s + this.s;', - 'this.s = this.s + "foo";', + '$mod.s = ""+$mod.b;', + '$mod.s = ""+$mod.i;', + '$mod.s = ""+$mod.d;', + '$mod.s = rtl.spaceLeft(""+$mod.i,3);', + '$mod.s = rtl.spaceLeft($mod.d.toFixed(2),3);', + '$mod.s = ""+$mod.b;', + '$mod.s = ""+$mod.i;', + '$mod.s = ""+$mod.d;', + '$mod.s = (""+$mod.i)+$mod.i;', + '$mod.s = rtl.spaceLeft(""+$mod.i,3);', + '$mod.s = rtl.spaceLeft($mod.d.toFixed(2),3);', + '$mod.s = rtl.spaceLeft("" + $mod.i, 4) + $mod.i;', + '$mod.s = ("" + $mod.i) + rtl.spaceLeft("" + $mod.i, 5);', + '$mod.s = rtl.spaceLeft("" + $mod.i, 4) + rtl.spaceLeft("" + $mod.i, 5);', + '$mod.s = $mod.s + $mod.s;', + '$mod.s = $mod.s + "foo";', ''])); end; @@ -3886,14 +3908,14 @@ begin '};' ]), LinesToStr([ // this.$main - ' this.p1(1);', - ' this.p1(1);', - ' this.p1(11);', - ' this.p2(1,"a");', - ' this.p2(1,"a");', - ' this.p2(12,"a");', - ' this.p2(13,"b");', - ' this.p3(1.0,false,"abc");' + ' $mod.p1(1);', + ' $mod.p1(1);', + ' $mod.p1(11);', + ' $mod.p2(1,"a");', + ' $mod.p2(1,"a");', + ' $mod.p2(12,"a");', + ' $mod.p2(13,"b");', + ' $mod.p3(1.0,false,"abc");' ])); end; @@ -3961,13 +3983,13 @@ begin 'this.vN = 0;' ]), LinesToStr([ // this.$main - ' this.vJ = 0;', - ' this.vN = 3;', - ' var $loopend1 = this.vN;', - ' for (this.vI = 1; this.vI <= $loopend1; this.vI++) {', - ' this.vJ = this.vJ + this.vI;', + ' $mod.vJ = 0;', + ' $mod.vN = 3;', + ' var $loopend1 = $mod.vN;', + ' for ($mod.vI = 1; $mod.vI <= $loopend1; $mod.vI++) {', + ' $mod.vJ = $mod.vJ + $mod.vI;', ' };', - ' if (this.vI > $loopend1) this.vI--;' + ' if ($mod.vI > $loopend1) $mod.vI--;' ])); end; @@ -4001,8 +4023,8 @@ begin ' return Result;', '};' ]), - LinesToStr([ // this.$main - ' this.SumNumbers(3);' + LinesToStr([ // $mod.$main + ' $mod.SumNumbers(3);' ])); end; @@ -4021,9 +4043,9 @@ begin ]), LinesToStr([ // this.$main ' var $loopend1 = 2;', - ' for (this.vI = 1; this.vI <= $loopend1; this.vI++);', - ' if(this.vI>$loopend1)this.vI--;', - ' if (this.vI==3) ;' + ' for ($mod.vI = 1; $mod.vI <= $loopend1; $mod.vI++);', + ' if($mod.vI>$loopend1)$mod.vI--;', + ' if ($mod.vI==3) ;' ])); end; @@ -4064,8 +4086,8 @@ begin ' return Result;', '};' ]), - LinesToStr([ // this.$main - ' this.SumNumbers(3);' + LinesToStr([ // $mod.$main + ' $mod.SumNumbers(3);' ])); end; @@ -4089,14 +4111,14 @@ begin 'this.vJ = 0;', 'this.vN = 0;' ]), - LinesToStr([ // this.$main - ' this.vN = 3;', - ' this.vJ = 0;', - ' this.vI = 0;', + LinesToStr([ // $mod.$main + ' $mod.vN = 3;', + ' $mod.vJ = 0;', + ' $mod.vI = 0;', ' do{', - ' this.vI = this.vI + 1;', - ' this.vJ = this.vJ + this.vI;', - ' }while(!(this.vI>=this.vN));' + ' $mod.vI = $mod.vI + 1;', + ' $mod.vJ = $mod.vJ + $mod.vI;', + ' }while(!($mod.vI>=$mod.vN));' ])); end; @@ -4119,14 +4141,14 @@ begin LinesToStr([ // statements 'this.vI = 0;' ]), - LinesToStr([ // this.$main - 'this.vI = 1;', + LinesToStr([ // $mod.$main + '$mod.vI = 1;', 'if (vI==1) {', ' vI=2;', '}', 'if (vI==2){ vI=3; }', ';', - 'this.vI = 4;' + '$mod.vI = 4;' ])); end; @@ -4153,7 +4175,7 @@ begin // ToDo: check use analyzer CheckSource('TestAsmPas_Impl', LinesToStr([ - 'var $impl = this.$impl;', + 'var $impl = $mod.$impl;', 'this.cIntf = 1;', 'this.vIntf = 0;', '']), @@ -4183,12 +4205,12 @@ begin LinesToStr([ // statements 'this.i = 0;' ]), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main 'try {', - ' this.i = 0;', - ' this.i = Math.floor(2 / this.i);', + ' $mod.i = 0;', + ' $mod.i = Math.floor(2 / $mod.i);', '} finally {', - ' this.i = 3;', + ' $mod.i = 3;', '};' ])); end; @@ -4231,49 +4253,49 @@ begin ConvertProgram; CheckSource('TestTryExcept', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', ' };', '});', - 'rtl.createClass(this, "Exception", this.TObject, function () {', + 'rtl.createClass($mod, "Exception", $mod.TObject, function () {', ' this.$init = function () {', - ' pas.program.TObject.$init.call(this);', + ' $mod.TObject.$init.call(this);', ' this.Msg = "";', ' };', '});', - 'rtl.createClass(this, "EInvalidCast", this.Exception, function () {', + 'rtl.createClass($mod, "EInvalidCast", $mod.Exception, function () {', '});', 'this.vI = 0;' ]), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main 'try {', - ' this.vI = 1;', + ' $mod.vI = 1;', '} catch {', - ' this.vI = 2;', + ' $mod.vI = 2;', '};', 'try {', - ' this.vI = 3;', + ' $mod.vI = 3;', '} catch ($e) {', ' throw $e;', '};', 'try {', - ' this.vI = 4;', + ' $mod.vI = 4;', '} catch ($e) {', - ' if (this.EInvalidCast.isPrototypeOf($e)){', + ' if ($mod.EInvalidCast.isPrototypeOf($e)){', ' throw $e', - ' } else if (this.Exception.isPrototypeOf($e)) {', + ' } else if ($mod.Exception.isPrototypeOf($e)) {', ' var E = $e;', ' if (E.Msg == "") throw E;', ' } else {', - ' this.vI = 5;', + ' $mod.vI = 5;', ' }', '};', 'try {', - ' this.vI = 6;', + ' $mod.vI = 6;', '} catch ($e) {', - ' if (this.EInvalidCast.isPrototypeOf($e)){' , + ' if ($mod.EInvalidCast.isPrototypeOf($e)){' , ' } else throw $e', '};', ''])); @@ -4295,10 +4317,10 @@ begin LinesToStr([ // statements 'this.vI = 0;' ]), - LinesToStr([ // this.$main - 'var $tmp1 = this.vI;', - 'if ($tmp1 == 1) {} else if ($tmp1 == 2){ this.vI = 3 }else {', - ' this.vI = 4;', + LinesToStr([ // $mod.$main + 'var $tmp1 = $mod.vI;', + 'if ($tmp1 == 1) {} else if ($tmp1 == 2){ $mod.vI = 3 }else {', + ' $mod.vI = 4;', '};' ])); end; @@ -4320,15 +4342,15 @@ begin LinesToStr([ // statements 'this.Vi = 0;' ]), - LinesToStr([ // this.$main - 'switch (this.Vi) {', + LinesToStr([ // $mod.$main + 'switch ($mod.Vi) {', 'case 1:', ' break;', 'case 2:', - ' this.Vi = 3;', + ' $mod.Vi = 3;', ' break;', 'default:', - ' this.Vi = 4;', + ' $mod.Vi = 4;', '};' ])); end; @@ -4346,11 +4368,11 @@ begin LinesToStr([ // statements 'this.Vi = 0;' ]), - LinesToStr([ // this.$main - 'var $tmp1 = this.Vi;', + LinesToStr([ // $mod.$main + 'var $tmp1 = $mod.Vi;', 'if ($tmp1 == 1) {', - ' this.Vi = 2;', - ' this.Vi = 3;', + ' $mod.Vi = 2;', + ' $mod.Vi = 3;', '};' ])); end; @@ -4369,11 +4391,11 @@ begin LinesToStr([ // statements 'this.vI = 0;' ]), - LinesToStr([ // this.$main - 'switch (this.vI) {', + LinesToStr([ // $mod.$main + 'switch ($mod.vI) {', 'case 1:', - ' this.vI = 2;', - ' this.vI = 3;', + ' $mod.vI = 2;', + ' $mod.vI = 3;', ' break;', '};' ])); @@ -4395,12 +4417,12 @@ begin LinesToStr([ // statements 'this.vI = 0;' ]), - LinesToStr([ // this.$main - 'var $tmp1 = this.vI;', + LinesToStr([ // $mod.$main + 'var $tmp1 = $mod.vI;', 'if (($tmp1 >= 1) && ($tmp1 <= 3)){', - ' this.vI = 14', + ' $mod.vI = 14', '} else if (($tmp1 == 4) || ($tmp1 == 5)){', - ' this.vI = 16', + ' $mod.vI = 16', '} else if ((($tmp1 >= 6) && ($tmp1 <= 7)) || (($tmp1 >= 9) && ($tmp1 <= 10))) ;' ])); end; @@ -4430,15 +4452,15 @@ begin 'this.i = 0;', 'this.b = false;' ]), - LinesToStr([ // this.$main - 'this.Arr = rtl.arraySetLength(this.Arr,3,0);', - 'this.Arr[0] = 4;', - 'this.Arr[1] = rtl.length(this.Arr) + this.Arr[0];', - 'this.Arr[this.i] = 5;', - 'this.Arr[this.Arr[this.i]] = this.Arr[6];', - 'this.i = 0;', - 'this.i = rtl.length(this.Arr) - 1;', - 'this.b = rtl.length(this.Arr) > 0;', + LinesToStr([ // $mod.$main + '$mod.Arr = rtl.arraySetLength($mod.Arr,3,0);', + '$mod.Arr[0] = 4;', + '$mod.Arr[1] = rtl.length($mod.Arr) + $mod.Arr[0];', + '$mod.Arr[$mod.i] = 5;', + '$mod.Arr[$mod.Arr[$mod.i]] = $mod.Arr[6];', + '$mod.i = 0;', + '$mod.i = rtl.length($mod.Arr) - 1;', + '$mod.b = rtl.length($mod.Arr) > 0;', ''])); end; @@ -4464,13 +4486,13 @@ begin 'this.DoIt = function(i,j){', '};' ]), - LinesToStr([ // this.$main - 'this.Arr = [];', - 'if (rtl.length(this.Arr) == 0) ;', - 'if (rtl.length(this.Arr) == 0) ;', - 'if (rtl.length(this.Arr) > 0) ;', - 'if (rtl.length(this.Arr) > 0) ;', - 'this.DoIt([],[]);', + LinesToStr([ // $mod.$main + '$mod.Arr = [];', + 'if (rtl.length($mod.Arr) == 0) ;', + 'if (rtl.length($mod.Arr) == 0) ;', + 'if (rtl.length($mod.Arr) > 0) ;', + 'if (rtl.length($mod.Arr) > 0) ;', + '$mod.DoIt([],[]);', ''])); end; @@ -4506,21 +4528,21 @@ begin 'this.Arr2 = [];', 'this.i = 0;' ]), - LinesToStr([ // this.$main - 'this.Arr2 = [];', - 'if (rtl.length(this.Arr2) == 0) ;', - 'if (rtl.length(this.Arr2) == 0) ;', - 'this.i = 0;', - 'this.i = 0;', - 'this.i = rtl.length(this.Arr2) - 1;', - 'this.i = rtl.length(this.Arr2[2]) - 1;', - 'this.Arr2[3] = this.Arr;', - 'this.Arr2[4][5] = this.i;', - 'this.i = this.Arr2[6][7];', - 'this.Arr2[8][9] = this.i;', - 'this.i = this.Arr2[10][11];', - 'this.Arr2 = rtl.arraySetLength(this.Arr2, 14, []);', - 'this.Arr2[15] = rtl.arraySetLength(this.Arr2[15], 16, 0);', + LinesToStr([ // $mod.$main + '$mod.Arr2 = [];', + 'if (rtl.length($mod.Arr2) == 0) ;', + 'if (rtl.length($mod.Arr2) == 0) ;', + '$mod.i = 0;', + '$mod.i = 0;', + '$mod.i = rtl.length($mod.Arr2) - 1;', + '$mod.i = rtl.length($mod.Arr2[2]) - 1;', + '$mod.Arr2[3] = $mod.Arr;', + '$mod.Arr2[4][5] = $mod.i;', + '$mod.i = $mod.Arr2[6][7];', + '$mod.Arr2[8][9] = $mod.i;', + '$mod.i = $mod.Arr2[10][11];', + '$mod.Arr2 = rtl.arraySetLength($mod.Arr2, 14, []);', + '$mod.Arr2[15] = rtl.arraySetLength($mod.Arr2[15], 16, 0);', ''])); end; @@ -4559,18 +4581,18 @@ begin ' };', '};', 'this.Arr = [];', - 'this.r = new this.TRec();', + 'this.r = new $mod.TRec();', 'this.i = 0;' ]), - LinesToStr([ // this.$main - 'this.Arr = rtl.arraySetLength(this.Arr,3, this.TRec);', - 'this.Arr[0].Int = 4;', - 'this.Arr[1].Int = rtl.length(this.Arr)+this.Arr[2].Int;', - 'this.Arr[this.Arr[this.i].Int].Int = this.Arr[5].Int;', - 'this.Arr[7] = new this.TRec(this.r);', - 'this.r = new this.TRec(this.Arr[8]);', - 'this.i = 0;', - 'this.i = rtl.length(this.Arr)-1;', + LinesToStr([ // $mod.$main + '$mod.Arr = rtl.arraySetLength($mod.Arr,3, $mod.TRec);', + '$mod.Arr[0].Int = 4;', + '$mod.Arr[1].Int = rtl.length($mod.Arr)+$mod.Arr[2].Int;', + '$mod.Arr[$mod.Arr[$mod.i].Int].Int = $mod.Arr[5].Int;', + '$mod.Arr[7] = new $mod.TRec($mod.r);', + '$mod.r = new $mod.TRec($mod.Arr[8]);', + '$mod.i = 0;', + '$mod.i = rtl.length($mod.Arr)-1;', ''])); end; @@ -4601,7 +4623,7 @@ begin ' vG = vG;', ' vJ = vH;', ' vI.set(vI.get());', - ' this.DoIt(vG, vG, {', + ' $mod.DoIt(vG, vG, {', ' get: function () {', ' return vG;', ' },', @@ -4609,7 +4631,7 @@ begin ' vG = v;', ' }', ' });', - ' this.DoIt(vH, vH, {', + ' $mod.DoIt(vH, vH, {', ' get: function () {', ' return vJ;', ' },', @@ -4617,8 +4639,8 @@ begin ' vJ = v;', ' }', ' });', - ' this.DoIt(vI.get(), vI.get(), vI);', - ' this.DoIt(vJ, vJ, {', + ' $mod.DoIt(vI.get(), vI.get(), vI);', + ' $mod.DoIt(vJ, vJ, {', ' get: function () {', ' return vJ;', ' },', @@ -4630,8 +4652,8 @@ begin 'this.i = [];' ]), LinesToStr([ - 'this.DoIt(this.i,this.i,{', - ' p: this,', + '$mod.DoIt($mod.i,$mod.i,{', + ' p: $mod,', ' get: function () {', ' return this.p.i;', ' },', @@ -4663,8 +4685,8 @@ begin 'this.DoIt = function (vG,vH,vI) {', ' var vJ = [];', ' vI.set(vI.get());', - ' this.DoIt(vI.get(), vI.get(), vI);', - ' this.DoIt(vJ[1+1], vJ[1+2], {', + ' $mod.DoIt(vI.get(), vI.get(), vI);', + ' $mod.DoIt(vJ[1+1], vJ[1+2], {', ' a:1+3,', ' p:vJ,', ' get: function () {', @@ -4678,9 +4700,9 @@ begin 'this.a = [];' ]), LinesToStr([ - 'this.DoIt(this.a[1+4],this.a[1+5],{', + '$mod.DoIt($mod.a[1+4],$mod.a[1+5],{', ' a: 1+6,', - ' p: this.a,', + ' p: $mod.a,', ' get: function () {', ' return this.p[this.a];', ' },', @@ -4717,9 +4739,9 @@ begin '};' ]), LinesToStr([ - 'this.DoIt(this.GetArr(0)[1+1],this.GetArr(0)[1+2],{', + '$mod.DoIt($mod.GetArr(0)[1+1],$mod.GetArr(0)[1+2],{', ' a: 1+3,', - ' p: this.GetArr(0),', + ' p: $mod.GetArr(0),', ' get: function () {', ' return this.p[this.a];', ' },', @@ -4727,9 +4749,9 @@ begin ' this.p[this.a] = v;', ' }', '});', - 'this.DoIt(this.GetArr(0)[2+1],this.GetArr(0)[2+2],{', + '$mod.DoIt($mod.GetArr(0)[2+1],$mod.GetArr(0)[2+2],{', ' a: 2+3,', - ' p: this.GetArr(0),', + ' p: $mod.GetArr(0),', ' get: function () {', ' return this.p[this.a];', ' },', @@ -4737,9 +4759,9 @@ begin ' this.p[this.a] = v;', ' }', '});', - 'this.DoIt(this.GetArr(7)[3+1],this.GetArr(8)[3+2],{', + '$mod.DoIt($mod.GetArr(7)[3+1],$mod.GetArr(8)[3+2],{', ' a: 3+3,', - ' p: this.GetArr(9),', + ' p: $mod.GetArr(9),', ' get: function () {', ' return this.p[this.a];', ' },', @@ -4782,11 +4804,11 @@ begin 'this.numbers = [1, 2];', 'this.names = ["red", "blue"];', '']), - LinesToStr([ // this.$main - 'this.e = this.TEnum.red;', - 'this.e = this.TEnum.blue;', - 'this.i = this.a[this.TEnum.red]+2;', - 'this.a[this.e] = this.a[this.e];', + LinesToStr([ // $mod.$main + '$mod.e = $mod.TEnum.red;', + '$mod.e = $mod.TEnum.blue;', + '$mod.i = $mod.a[$mod.TEnum.red]+2;', + '$mod.a[$mod.e] = $mod.a[$mod.e];', ''])); end; @@ -4806,7 +4828,7 @@ begin ConvertProgram; CheckSource('TestArray_SetLengthProperty', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -4815,7 +4837,7 @@ begin 'this.Obj = null;', '']), LinesToStr([ - 'this.Obj.SetColors(rtl.arraySetLength(this.Obj.GetColors(), 2, 0));', + '$mod.Obj.SetColors(rtl.arraySetLength($mod.Obj.GetColors(), 2, 0));', ''])); end; @@ -4845,8 +4867,8 @@ begin 'this.s = "";', '']), LinesToStr([ - 'this.DoIt([]);', - 'this.DoIt([this.s, "foo", "", this.s + this.s]);', + '$mod.DoIt([]);', + '$mod.DoIt([$mod.s, "foo", "", $mod.s + $mod.s]);', ''])); end; @@ -4906,19 +4928,19 @@ begin 'this.ArrSet = [];', 'this.ArrJSValue = [];', '']), - LinesToStr([ // this.$main - 'this.ArrInt = this.ArrInt;', - 'this.ArrInt = this.ArrInt.concat(this.ArrInt);', - 'this.ArrInt = this.ArrInt.concat(this.ArrInt,this.ArrInt);', - 'this.ArrRec = this.ArrRec;', - 'this.ArrRec = rtl.arrayConcat(this.TRec, this.ArrRec);', - 'this.ArrRec = rtl.arrayConcat(this.TRec, this.ArrRec, this.ArrRec);', - 'this.ArrSet = this.ArrSet;', - 'this.ArrSet = rtl.arrayConcat("refSet", this.ArrSet);', - 'this.ArrSet = rtl.arrayConcat("refSet", this.ArrSet, this.ArrSet);', - 'this.ArrJSValue = this.ArrJSValue;', - 'this.ArrJSValue = this.ArrJSValue.concat(this.ArrJSValue);', - 'this.ArrJSValue = this.ArrJSValue.concat(this.ArrJSValue, this.ArrJSValue);', + LinesToStr([ // $mod.$main + '$mod.ArrInt = $mod.ArrInt;', + '$mod.ArrInt = $mod.ArrInt.concat($mod.ArrInt);', + '$mod.ArrInt = $mod.ArrInt.concat($mod.ArrInt,$mod.ArrInt);', + '$mod.ArrRec = $mod.ArrRec;', + '$mod.ArrRec = rtl.arrayConcat($mod.TRec, $mod.ArrRec);', + '$mod.ArrRec = rtl.arrayConcat($mod.TRec, $mod.ArrRec, $mod.ArrRec);', + '$mod.ArrSet = $mod.ArrSet;', + '$mod.ArrSet = rtl.arrayConcat("refSet", $mod.ArrSet);', + '$mod.ArrSet = rtl.arrayConcat("refSet", $mod.ArrSet, $mod.ArrSet);', + '$mod.ArrJSValue = $mod.ArrJSValue;', + '$mod.ArrJSValue = $mod.ArrJSValue.concat($mod.ArrJSValue);', + '$mod.ArrJSValue = $mod.ArrJSValue.concat($mod.ArrJSValue, $mod.ArrJSValue);', ''])); end; @@ -4978,19 +5000,19 @@ begin 'this.ArrSet = [];', 'this.ArrJSValue = [];', '']), - LinesToStr([ // this.$main - 'this.ArrInt = rtl.arrayCopy(0, this.ArrInt, 0);', - 'this.ArrInt = rtl.arrayCopy(0, this.ArrInt, 2);', - 'this.ArrInt = rtl.arrayCopy(0, this.ArrInt, 3, 4);', - 'this.ArrRec = rtl.arrayCopy(this.TRec, this.ArrRec, 0);', - 'this.ArrRec = rtl.arrayCopy(this.TRec, this.ArrRec, 5);', - 'this.ArrRec = rtl.arrayCopy(this.TRec, this.ArrRec, 6, 7);', - 'this.ArrSet = rtl.arrayCopy("refSet", this.ArrSet, 0);', - 'this.ArrSet = rtl.arrayCopy("refSet", this.ArrSet, 8);', - 'this.ArrSet = rtl.arrayCopy("refSet", this.ArrSet, 9, 10);', - 'this.ArrJSValue = rtl.arrayCopy(0, this.ArrJSValue, 0);', - 'this.ArrJSValue = rtl.arrayCopy(0, this.ArrJSValue, 11);', - 'this.ArrJSValue = rtl.arrayCopy(0, this.ArrJSValue, 12, 13);', + LinesToStr([ // $mod.$main + '$mod.ArrInt = rtl.arrayCopy(0, $mod.ArrInt, 0);', + '$mod.ArrInt = rtl.arrayCopy(0, $mod.ArrInt, 2);', + '$mod.ArrInt = rtl.arrayCopy(0, $mod.ArrInt, 3, 4);', + '$mod.ArrRec = rtl.arrayCopy($mod.TRec, $mod.ArrRec, 0);', + '$mod.ArrRec = rtl.arrayCopy($mod.TRec, $mod.ArrRec, 5);', + '$mod.ArrRec = rtl.arrayCopy($mod.TRec, $mod.ArrRec, 6, 7);', + '$mod.ArrSet = rtl.arrayCopy("refSet", $mod.ArrSet, 0);', + '$mod.ArrSet = rtl.arrayCopy("refSet", $mod.ArrSet, 8);', + '$mod.ArrSet = rtl.arrayCopy("refSet", $mod.ArrSet, 9, 10);', + '$mod.ArrJSValue = rtl.arrayCopy(0, $mod.ArrJSValue, 0);', + '$mod.ArrJSValue = rtl.arrayCopy(0, $mod.ArrJSValue, 11);', + '$mod.ArrJSValue = rtl.arrayCopy(0, $mod.ArrJSValue, 12, 13);', ''])); end; @@ -5048,17 +5070,17 @@ begin 'this.ArrSet = [];', 'this.ArrJSValue = [];', '']), - LinesToStr([ // this.$main - 'this.ArrInt.splice(2, 1, 1);', - 'this.ArrInt.splice(4, 1, this.ArrInt[3]);', - 'this.ArrRec.splice(6, 1, this.ArrRec[5]);', - 'this.ArrSet.splice(7, 1, this.ArrSet[7]);', - 'this.ArrJSValue.splice(9, 1, this.ArrJSValue[8]);', - 'this.ArrJSValue.splice(11, 1, 10);', - 'this.ArrInt.splice(12, 13);', - 'this.ArrRec.splice(14, 15);', - 'this.ArrSet.splice(17, 18);', - 'this.ArrJSValue.splice(19, 10);', + LinesToStr([ // $mod.$main + '$mod.ArrInt.splice(2, 1, 1);', + '$mod.ArrInt.splice(4, 1, $mod.ArrInt[3]);', + '$mod.ArrRec.splice(6, 1, $mod.ArrRec[5]);', + '$mod.ArrSet.splice(7, 1, $mod.ArrSet[7]);', + '$mod.ArrJSValue.splice(9, 1, $mod.ArrJSValue[8]);', + '$mod.ArrJSValue.splice(11, 1, 10);', + '$mod.ArrInt.splice(12, 13);', + '$mod.ArrRec.splice(14, 15);', + '$mod.ArrSet.splice(17, 18);', + '$mod.ArrJSValue.splice(19, 10);', ''])); end; @@ -5083,9 +5105,9 @@ begin 'this.aObj = null;', 'this.a = [];', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main 'if (Array.isArray(65)) ;', - 'this.aObj = this.a.concat(this.a);', + '$mod.aObj = $mod.a.concat($mod.a);', ''])); end; @@ -5109,9 +5131,9 @@ begin 'this.aObj = null;', 'this.a = [];', '']), - LinesToStr([ // this.$main - 'this.a = this.aObj;', - 'this.aObj[1] = this.aObj[2];', + LinesToStr([ // $mod.$main + '$mod.a = $mod.aObj;', + '$mod.aObj[1] = $mod.aObj[2];', ''])); end; @@ -5138,10 +5160,10 @@ begin ' return this.Bold == b.Bold;', ' };', '};', - 'this.Rec = new this.TRecA();' + 'this.Rec = new $mod.TRecA();' ]), - LinesToStr([ // this.$main - 'this.Rec.Bold = 123;' + LinesToStr([ // $mod.$main + '$mod.Rec.Bold = 123;' ])); end; @@ -5176,14 +5198,14 @@ begin ' };', '};', 'this.Int = 0;', - 'this.r = new this.TRec();' + 'this.r = new $mod.TRec();' ]), - LinesToStr([ // this.$main - 'var $with1 = this.r;', - 'this.Int = $with1.vI;', - 'var $with2 = this.r;', - 'this.Int = $with2.vI;', - '$with2.vI = this.Int;' + LinesToStr([ // $mod.$main + 'var $with1 = $mod.r;', + '$mod.Int = $with1.vI;', + 'var $with2 = $mod.r;', + '$mod.Int = $with2.vI;', + '$with2.vI = $mod.Int;' ])); end; @@ -5231,13 +5253,13 @@ begin ' this.Int = s.Int;', ' this.D = s.D;', ' this.Arr = s.Arr;', - ' this.Small = new pas.program.TSmallRec(s.Small);', + ' this.Small = new $mod.TSmallRec(s.Small);', ' this.Enums = rtl.refSet(s.Enums);', ' } else {', ' this.Int = 0;', ' this.D = 0.0;', ' this.Arr = [];', - ' this.Small = new pas.program.TSmallRec();', + ' this.Small = new $mod.TSmallRec();', ' this.Enums = {};', ' };', ' this.$equal = function (b) {', @@ -5245,11 +5267,11 @@ begin ' && (this.Small.$equal(b.Small) && rtl.eqSet(this.Enums, b.Enums))));', ' };', '};', - 'this.r = new this.TBigRec();', - 'this.s = new this.TBigRec();' + 'this.r = new $mod.TBigRec();', + 'this.s = new $mod.TBigRec();' ]), - LinesToStr([ // this.$main - 'this.r = new this.TBigRec(this.s);', + LinesToStr([ // $mod.$main + '$mod.r = new $mod.TBigRec($mod.s);', ''])); end; @@ -5283,11 +5305,11 @@ begin '};', 'this.DoConst = function (r) {', '};', - 'this.Rec = new this.TRecA();' + 'this.Rec = new $mod.TRecA();' ]), - LinesToStr([ // this.$main - 'this.DoDefault(new this.TRecA(this.Rec));', - 'this.DoConst(this.Rec);', + LinesToStr([ // $mod.$main + '$mod.DoDefault(new $mod.TRecA($mod.Rec));', + '$mod.DoConst($mod.Rec);', ''])); end; @@ -5327,11 +5349,11 @@ begin ' };', '};', 'this.DoIt = function (vG,vH,vI) {', - ' var vJ = new this.TRecord();', - ' vG = new this.TRecord(vG);', - ' vJ = new this.TRecord(vH);', - ' vI.set(new this.TRecord(vI.get()));', - ' this.DoIt(new this.TRecord(vG), vG, {', + ' var vJ = new $mod.TRecord();', + ' vG = new $mod.TRecord(vG);', + ' vJ = new $mod.TRecord(vH);', + ' vI.set(new $mod.TRecord(vI.get()));', + ' $mod.DoIt(new $mod.TRecord(vG), vG, {', ' get: function () {', ' return vG;', ' },', @@ -5339,7 +5361,7 @@ begin ' vG = v;', ' }', ' });', - ' this.DoIt(new this.TRecord(vH), vH, {', + ' $mod.DoIt(new $mod.TRecord(vH), vH, {', ' get: function () {', ' return vJ;', ' },', @@ -5347,8 +5369,8 @@ begin ' vJ = v;', ' }', ' });', - ' this.DoIt(new this.TRecord(vI.get()), vI.get(), vI);', - ' this.DoIt(new this.TRecord(vJ), vJ, {', + ' $mod.DoIt(new $mod.TRecord(vI.get()), vI.get(), vI);', + ' $mod.DoIt(new $mod.TRecord(vJ), vJ, {', ' get: function () {', ' return vJ;', ' },', @@ -5357,11 +5379,11 @@ begin ' }', ' });', '};', - 'this.i = new this.TRecord();' + 'this.i = new $mod.TRecord();' ]), LinesToStr([ - 'this.DoIt(new this.TRecord(this.i),this.i,{', - ' p: this,', + '$mod.DoIt(new $mod.TRecord($mod.i),$mod.i,{', + ' p: $mod,', ' get: function () {', ' return this.p.i;', ' },', @@ -5402,8 +5424,8 @@ begin ' };', '};', 'this.DoIt = function (vG,vH,vI) {', - ' var vJ = new this.TRecord();', - ' this.DoIt(vJ.i, vJ.i, {', + ' var vJ = new $mod.TRecord();', + ' $mod.DoIt(vJ.i, vJ.i, {', ' p: vJ,', ' get: function () {', ' return this.p.i;', @@ -5413,11 +5435,11 @@ begin ' }', ' });', '};', - 'this.r = new this.TRecord();' + 'this.r = new $mod.TRecord();' ]), LinesToStr([ - 'this.DoIt(this.r.i,this.r.i,{', - ' p: this.r,', + '$mod.DoIt($mod.r.i,$mod.r.i,{', + ' p: $mod.r,', ' get: function () {', ' return this.p.i;', ' },', @@ -5460,15 +5482,15 @@ begin ' };', '};', 'this.GetRec = function (vB) {', - ' var Result = new this.TRecord();', + ' var Result = new $mod.TRecord();', ' return Result;', '};', 'this.DoIt = function (vG,vH,vI) {', '};' ]), LinesToStr([ - 'this.DoIt(this.GetRec(0).i,this.GetRec(0).i,{', - ' p: this.GetRec(0),', + '$mod.DoIt($mod.GetRec(0).i,$mod.GetRec(0).i,{', + ' p: $mod.GetRec(0),', ' get: function () {', ' return this.p.i;', ' },', @@ -5476,8 +5498,8 @@ begin ' this.p.i = v;', ' }', '});', - 'this.DoIt(this.GetRec(0).i,this.GetRec(0).i,{', - ' p: this.GetRec(0),', + '$mod.DoIt($mod.GetRec(0).i,$mod.GetRec(0).i,{', + ' p: $mod.GetRec(0),', ' get: function () {', ' return this.p.i;', ' },', @@ -5485,8 +5507,8 @@ begin ' this.p.i = v;', ' }', '});', - 'this.DoIt(this.GetRec(1).i,this.GetRec(2).i,{', - ' p: this.GetRec(3),', + '$mod.DoIt($mod.GetRec(1).i,$mod.GetRec(2).i,{', + ' p: $mod.GetRec(3),', ' get: function () {', ' return this.p.i;', ' },', @@ -5527,11 +5549,11 @@ begin '};', 'this.DoIt = function (vG,vH,vI) {', '};', - 'this.r = new this.TRecord();' + 'this.r = new $mod.TRecord();' ]), LinesToStr([ - 'var $with1 = this.r;', - 'this.DoIt($with1.i,$with1.i,{', + 'var $with1 = $mod.r;', + '$mod.DoIt($with1.i,$with1.i,{', ' p: $with1,', ' get: function () {', ' return this.p.i;', @@ -5590,21 +5612,21 @@ begin '};', 'this.TNested = function (s) {', ' if (s) {', - ' this.r = new pas.program.TRecord(s.r);', + ' this.r = new $mod.TRecord(s.r);', ' } else {', - ' this.r = new pas.program.TRecord();', + ' this.r = new $mod.TRecord();', ' };', ' this.$equal = function (b) {', ' return this.r.$equal(b.r);', ' };', '};', 'this.b = false;', - 'this.r = new this.TRecord();', - 'this.s = new this.TRecord();' + 'this.r = new $mod.TRecord();', + 'this.s = new $mod.TRecord();' ]), LinesToStr([ - 'this.b = this.r.$equal(this.s);', - 'this.b = !this.r.$equal(this.s);', + '$mod.b = $mod.r.$equal($mod.s);', + '$mod.b = !$mod.r.$equal($mod.s);', ''])); end; @@ -5628,7 +5650,7 @@ begin ConvertProgram; CheckSource('TestClass_TObjectDefaultConstructor', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -5640,9 +5662,9 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj = this.TObject.$create("Create");', - 'this.Obj.$destroy("Destroy");', + LinesToStr([ // $mod.$main + '$mod.Obj = $mod.TObject.$create("Create");', + '$mod.Obj.$destroy("Destroy");', ''])); end; @@ -5662,7 +5684,7 @@ begin ConvertProgram; CheckSource('TestClass_TObjectConstructorWithParams', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -5672,8 +5694,8 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj = this.TObject.$create("Create",[3]);' + LinesToStr([ // $mod.$main + '$mod.Obj = $mod.TObject.$create("Create",[3]);' ])); end; @@ -5697,7 +5719,7 @@ begin ConvertProgram; CheckSource('TestClass_Var', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.$init = function () {', ' this.vI = 0;', ' };', @@ -5709,9 +5731,9 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj = this.TObject.$create("Create",[4]);', - 'this.Obj.vI = this.Obj.vI + 5;' + LinesToStr([ // $mod.$main + '$mod.Obj = $mod.TObject.$create("Create",[4]);', + '$mod.Obj.vI = $mod.Obj.vI + 5;' ])); end; @@ -5744,7 +5766,7 @@ begin ConvertProgram; CheckSource('TestClass_Method', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.$init = function () {', ' this.vI = 0;', ' this.Sub = null;', @@ -5763,14 +5785,14 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj = this.TObject.$create("Create");', - 'this.Obj.GetIt(4);', - 'this.Obj.Sub.Sub=null;', - 'this.Obj.Sub.GetIt(5);', - 'this.Obj.Sub.GetIt(6).Sub=null;', - 'this.Obj.Sub.GetIt(7).GetIt(8);', - 'this.Obj.Sub.GetIt(9).Sub.GetIt(10);' + LinesToStr([ // $mod.$main + '$mod.Obj = $mod.TObject.$create("Create");', + '$mod.Obj.GetIt(4);', + '$mod.Obj.Sub.Sub=null;', + '$mod.Obj.Sub.GetIt(5);', + '$mod.Obj.Sub.GetIt(6).Sub=null;', + '$mod.Obj.Sub.GetIt(7).GetIt(8);', + '$mod.Obj.Sub.GetIt(9).Sub.GetIt(10);' ])); end; @@ -5803,7 +5825,7 @@ begin ConvertProgram; CheckSource('TestClass_Inheritance', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -5811,9 +5833,9 @@ begin ' this.Create = function () {', ' };', '});', - 'rtl.createClass(this,"TClassA",this.TObject,function(){', + 'rtl.createClass($mod,"TClassA",$mod.TObject,function(){', '});', - 'rtl.createClass(this,"TClassB",this.TObject,function(){', + 'rtl.createClass($mod,"TClassB",$mod.TObject,function(){', ' this.ProcB = function () {', ' };', '});', @@ -5821,13 +5843,13 @@ begin 'this.oA = null;', 'this.oB = null;' ]), - LinesToStr([ // this.$main - 'this.oO = this.TObject.$create("Create");', - 'this.oA = this.TClassA.$create("Create");', - 'this.oB = this.TClassB.$create("Create");', - 'if (this.TClassA.isPrototypeOf(this.oO));', - 'this.oB = rtl.as(this.oO, this.TClassB);', - 'rtl.as(this.oO, this.TClassB).ProcB();' + LinesToStr([ // $mod.$main + '$mod.oO = $mod.TObject.$create("Create");', + '$mod.oA = $mod.TClassA.$create("Create");', + '$mod.oB = $mod.TClassB.$create("Create");', + 'if ($mod.TClassA.isPrototypeOf($mod.oO));', + '$mod.oB = rtl.as($mod.oO, $mod.TClassB);', + 'rtl.as($mod.oO, $mod.TClassB).ProcB();' ])); end; @@ -5843,7 +5865,7 @@ begin ConvertProgram; CheckSource('TestClass_AbstractMethod', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -5896,7 +5918,7 @@ begin ConvertProgram; CheckSource('TestClass_CallInherited_NoParams', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -5906,14 +5928,14 @@ begin ' this.DoIt = function () {', ' };', '});', - 'rtl.createClass(this, "TA", this.TObject, function () {', + 'rtl.createClass($mod, "TA", $mod.TObject, function () {', ' this.DoAbstract = function () {', - ' pas.program.TObject.DoVirtual.call(this);', + ' $mod.TObject.DoVirtual.call(this);', ' };', ' this.DoVirtual = function () {', - ' pas.program.TObject.DoVirtual.apply(this, arguments);', - ' pas.program.TObject.DoVirtual.call(this);', - ' pas.program.TObject.DoVirtual.call(this);', + ' $mod.TObject.DoVirtual.apply(this, arguments);', + ' $mod.TObject.DoVirtual.call(this);', + ' $mod.TObject.DoVirtual.call(this);', ' this.DoIt();', ' this.DoIt();', ' };', @@ -5968,7 +5990,7 @@ begin ConvertProgram; CheckSource('TestClass_CallInherited_WithParams', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -5980,15 +6002,15 @@ begin ' this.DoIt2 = function (pA,pB) {', ' };', '});', - 'rtl.createClass(this, "TClassA", this.TObject, function () {', + 'rtl.createClass($mod, "TClassA", $mod.TObject, function () {', ' this.DoAbstract = function (pA,pB) {', - ' pas.program.TObject.DoVirtual.call(this,pA,pB);', - ' pas.program.TObject.DoVirtual.call(this,pA,0);', + ' $mod.TObject.DoVirtual.call(this,pA,pB);', + ' $mod.TObject.DoVirtual.call(this,pA,0);', ' };', ' this.DoVirtual = function (pA,pB) {', - ' pas.program.TObject.DoVirtual.apply(this, arguments);', - ' pas.program.TObject.DoVirtual.call(this,pA,pB);', - ' pas.program.TObject.DoVirtual.call(this,pA,0);', + ' $mod.TObject.DoVirtual.apply(this, arguments);', + ' $mod.TObject.DoVirtual.call(this,pA,pB);', + ' $mod.TObject.DoVirtual.call(this,pA,0);', ' this.DoIt(pA,pB);', ' this.DoIt(pA,0);', ' this.DoIt2(pA,2);', @@ -6054,7 +6076,7 @@ begin ConvertProgram; CheckSource('TestClass_CallInheritedConstructor', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -6065,15 +6087,15 @@ begin ' this.Create();', ' };', '});', - 'rtl.createClass(this, "TA", this.TObject, function () {', + 'rtl.createClass($mod, "TA", $mod.TObject, function () {', ' this.Create = function () {', - ' pas.program.TObject.Create.apply(this, arguments);', - ' pas.program.TObject.Create.call(this);', - ' pas.program.TObject.CreateWithB.call(this, false);', + ' $mod.TObject.Create.apply(this, arguments);', + ' $mod.TObject.Create.call(this);', + ' $mod.TObject.CreateWithB.call(this, false);', ' };', ' this.CreateWithC = function (c) {', - ' pas.program.TObject.Create.call(this);', - ' pas.program.TObject.CreateWithB.call(this, true);', + ' $mod.TObject.Create.call(this);', + ' $mod.TObject.CreateWithB.call(this, true);', ' this.DoIt();', ' this.DoIt();', ' this.$class.DoSome();', @@ -6130,7 +6152,7 @@ begin ConvertProgram; CheckSource('TestClass_ClassVar', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.vI = 0;', ' this.Sub = null;', ' this.$init = function () {', @@ -6151,13 +6173,13 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj = this.TObject.$create("Create");', - 'this.TObject.vI = 3;', - 'if (this.TObject.vI == 4);', - 'this.TObject.Sub=null;', - 'this.Obj.$class.Sub=null;', - 'this.Obj.Sub.$class.Sub=null;', + LinesToStr([ // $mod.$main + '$mod.Obj = $mod.TObject.$create("Create");', + '$mod.TObject.vI = 3;', + 'if ($mod.TObject.vI == 4);', + '$mod.TObject.Sub=null;', + '$mod.Obj.$class.Sub=null;', + '$mod.Obj.Sub.$class.Sub=null;', ''])); end; @@ -6206,7 +6228,7 @@ begin ConvertProgram; CheckSource('TestClass_CallClassMethod', LinesToStr([ // statements - 'rtl.createClass(this,"TObject",null,function(){', + 'rtl.createClass($mod,"TObject",null,function(){', ' this.vI = 0;', ' this.Sub = null;', ' this.$init = function () {', @@ -6238,14 +6260,14 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj = this.TObject.$create("Create");', - 'this.TObject.GetIt(5);', - 'this.Obj.$class.GetIt(6);', - 'this.Obj.Sub.$class.GetIt(7);', - 'this.Obj.Sub.$class.GetIt(8).$class.Sub=null;', - 'this.Obj.Sub.$class.GetIt(9).$class.GetIt(10);', - 'this.Obj.Sub.$class.GetIt(11).Sub.$class.GetIt(12);', + LinesToStr([ // $mod.$main + '$mod.Obj = $mod.TObject.$create("Create");', + '$mod.TObject.GetIt(5);', + '$mod.Obj.$class.GetIt(6);', + '$mod.Obj.Sub.$class.GetIt(7);', + '$mod.Obj.Sub.$class.GetIt(8).$class.Sub=null;', + '$mod.Obj.Sub.$class.GetIt(9).$class.GetIt(10);', + '$mod.Obj.Sub.$class.GetIt(11).Sub.$class.GetIt(12);', ''])); end; @@ -6287,7 +6309,7 @@ begin ConvertProgram; CheckSource('TestClass_Property', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.Fx = 0;', ' this.Fy = 0;', @@ -6312,11 +6334,11 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj.Fy = this.Obj.Fx + 1;', - 'if (this.Obj.GetInt() == 2);', - 'this.Obj.SetInt(this.Obj.GetInt() + 2);', - 'this.Obj.SetInt(this.Obj.Fx);' + LinesToStr([ // $mod.$main + '$mod.Obj.Fy = $mod.Obj.Fx + 1;', + 'if ($mod.Obj.GetInt() == 2);', + '$mod.Obj.SetInt($mod.Obj.GetInt() + 2);', + '$mod.Obj.SetInt($mod.Obj.Fx);' ])); end; @@ -6360,7 +6382,7 @@ begin ConvertProgram; CheckSource('TestClass_Property_ClassMethod', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.Fx = 0;', ' this.Fy = 0;', ' this.$init = function () {', @@ -6383,15 +6405,15 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.TObject.Fy = this.TObject.Fx + 1;', - 'if (this.TObject.GetInt() == 2);', - 'this.TObject.SetInt(this.TObject.GetInt() + 2);', - 'this.TObject.SetInt(this.TObject.Fx);', - 'this.Obj.$class.Fy = this.Obj.Fx + 1;', - 'if (this.Obj.$class.GetInt() == 2);', - 'this.Obj.$class.SetInt(this.Obj.$class.GetInt() + 2);', - 'this.Obj.$class.SetInt(this.Obj.Fx);' + LinesToStr([ // $mod.$main + '$mod.TObject.Fy = $mod.TObject.Fx + 1;', + 'if ($mod.TObject.GetInt() == 2);', + '$mod.TObject.SetInt($mod.TObject.GetInt() + 2);', + '$mod.TObject.SetInt($mod.TObject.Fx);', + '$mod.Obj.$class.Fy = $mod.Obj.Fx + 1;', + 'if ($mod.Obj.$class.GetInt() == 2);', + '$mod.Obj.$class.SetInt($mod.Obj.$class.GetInt() + 2);', + '$mod.Obj.$class.SetInt($mod.Obj.Fx);' ])); end; @@ -6427,7 +6449,7 @@ begin ConvertProgram; CheckSource('TestClass_Property_Index', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FItems = [];', ' };', @@ -6451,8 +6473,8 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj.SetItems(11,this.Obj.GetItems(12));' + LinesToStr([ // $mod.$main + '$mod.Obj.SetItems(11,$mod.Obj.GetItems(12));' ])); end; @@ -6492,7 +6514,7 @@ begin ConvertProgram; CheckSource('TestClass_PropertyOfTypeArray', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FItems = [];', ' };', @@ -6519,10 +6541,10 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj.SetItems([]);', - 'this.Obj.SetItems(this.Obj.GetItems());', - 'this.Obj.GetItems()[11] = this.Obj.GetItems()[12];' + LinesToStr([ // $mod.$main + '$mod.Obj.SetItems([]);', + '$mod.Obj.SetItems($mod.Obj.GetItems());', + '$mod.Obj.GetItems()[11] = $mod.Obj.GetItems()[12];' ])); end; @@ -6555,7 +6577,7 @@ begin ConvertProgram; CheckSource('TestClass_PropertyDefault', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FItems = [];', ' };', @@ -6575,10 +6597,10 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj.SetItems(11, 12);', - 'this.Obj.SetItems(13, this.Obj.GetItems(14));', - 'this.Obj.SetItems(this.Obj.GetItems(15), this.Obj.GetItems(this.Obj.GetItems(15)));' + LinesToStr([ // $mod.$main + '$mod.Obj.SetItems(11, 12);', + '$mod.Obj.SetItems(13, $mod.Obj.GetItems(14));', + '$mod.Obj.SetItems($mod.Obj.GetItems(15), $mod.Obj.GetItems($mod.Obj.GetItems(15)));' ])); end; @@ -6607,25 +6629,25 @@ begin ConvertProgram; CheckSource('TestClass_PropertyOverride', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FItem = 0;', ' };', ' this.$final = function () {', ' };', '});', - 'rtl.createClass(this, "TCar", this.TObject, function () {', + 'rtl.createClass($mod, "TCar", $mod.TObject, function () {', ' this.$init = function () {', - ' pas.program.TObject.$init.call(this);', + ' $mod.TObject.$init.call(this);', ' this.FBag = 0;', ' };', '});', 'this.Obj = null;', 'this.Car = null;', '']), - LinesToStr([ // this.$main - 'this.Obj.SetItem(this.Obj.GetItem());', - 'this.Car.SetItem(this.Car.GetBag());', + LinesToStr([ // $mod.$main + '$mod.Obj.SetItem($mod.Obj.GetItem());', + '$mod.Car.SetItem($mod.Car.GetBag());', ''])); end; @@ -6644,7 +6666,7 @@ begin ConvertProgram; CheckSource('TestClass_Assigned', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -6653,9 +6675,9 @@ begin 'this.Obj = null;', 'this.b = false;' ]), - LinesToStr([ // this.$main - 'if (this.Obj != null);', - 'this.b = (this.Obj != null) || false;' + LinesToStr([ // $mod.$main + 'if ($mod.Obj != null);', + '$mod.b = ($mod.Obj != null) || false;' ])); end; @@ -6691,7 +6713,7 @@ begin ConvertProgram; CheckSource('TestClass_WithClassDoCreate', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.aBool = false;', ' this.Arr = [];', @@ -6705,20 +6727,20 @@ begin 'this.Obj = null;', 'this.b = false;' ]), - LinesToStr([ // this.$main - 'var $with1 = this.TObject.$create("Create");', - 'this.b = $with1.aBool;', - '$with1.aBool = this.b;', - 'this.b = $with1.Arr[1];', - '$with1.Arr[2] = this.b;', - 'var $with2 = this.TObject;', - 'this.Obj = $with2.$create("Create");', - 'var $with3 = this.Obj;', + LinesToStr([ // $mod.$main + 'var $with1 = $mod.TObject.$create("Create");', + '$mod.b = $with1.aBool;', + '$with1.aBool = $mod.b;', + '$mod.b = $with1.Arr[1];', + '$with1.Arr[2] = $mod.b;', + 'var $with2 = $mod.TObject;', + '$mod.Obj = $with2.$create("Create");', + 'var $with3 = $mod.Obj;', '$with3.Create();', - 'this.b = $with3.aBool;', - '$with3.aBool = this.b;', - 'this.b = $with3.Arr[3];', - '$with3.Arr[4] = this.b;', + '$mod.b = $with3.aBool;', + '$with3.aBool = $mod.b;', + '$mod.b = $with3.Arr[3];', + '$with3.Arr[4] = $mod.b;', ''])); end; @@ -6756,7 +6778,7 @@ begin ConvertProgram; CheckSource('TestClass_WithClassInstDoProperty', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FInt = 0;', ' };', @@ -6774,17 +6796,17 @@ begin 'this.Obj = null;', 'this.i = 0;' ]), - LinesToStr([ // this.$main - 'var $with1 = this.TObject.$create("Create");', - 'this.i = $with1.FInt;', - '$with1.FInt = this.i;', - 'this.i = $with1.GetSize();', - '$with1.SetSize(this.i);', - 'var $with2 = this.Obj;', - 'this.i = $with2.FInt;', - '$with2.FInt = this.i;', - 'this.i = $with2.GetSize();', - '$with2.SetSize(this.i);', + LinesToStr([ // $mod.$main + 'var $with1 = $mod.TObject.$create("Create");', + '$mod.i = $with1.FInt;', + '$with1.FInt = $mod.i;', + '$mod.i = $with1.GetSize();', + '$with1.SetSize($mod.i);', + 'var $with2 = $mod.Obj;', + '$mod.i = $with2.FInt;', + '$with2.FInt = $mod.i;', + '$mod.i = $with2.GetSize();', + '$with2.SetSize($mod.i);', ''])); end; @@ -6816,7 +6838,7 @@ begin ConvertProgram; CheckSource('TestClass_WithClassInstDoPropertyWithParams', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -6833,13 +6855,13 @@ begin 'this.Obj = null;', 'this.i = 0;' ]), - LinesToStr([ // this.$main - 'var $with1 = this.TObject.$create("Create");', - 'this.i = $with1.GetItems(1);', - '$with1.SetItems(2, this.i);', - 'var $with2 = this.Obj;', - 'this.i = $with2.GetItems(3);', - '$with2.SetItems(4, this.i);', + LinesToStr([ // $mod.$main + 'var $with1 = $mod.TObject.$create("Create");', + '$mod.i = $with1.GetItems(1);', + '$with1.SetItems(2, $mod.i);', + 'var $with2 = $mod.Obj;', + '$mod.i = $with2.GetItems(3);', + '$with2.SetItems(4, $mod.i);', ''])); end; @@ -6872,7 +6894,7 @@ begin ConvertProgram; CheckSource('TestClass_WithClassInstDoFunc', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -6889,15 +6911,15 @@ begin 'this.Obj = null;', 'this.i = 0;' ]), - LinesToStr([ // this.$main - 'var $with1 = this.TObject.$create("Create");', - 'this.i = $with1.GetSize();', - 'this.i = $with1.GetSize();', - '$with1.SetSize(this.i);', - 'var $with2 = this.Obj;', - 'this.i = $with2.GetSize();', - 'this.i = $with2.GetSize();', - '$with2.SetSize(this.i);', + LinesToStr([ // $mod.$main + 'var $with1 = $mod.TObject.$create("Create");', + '$mod.i = $with1.GetSize();', + '$mod.i = $with1.GetSize();', + '$with1.SetSize($mod.i);', + 'var $with2 = $mod.Obj;', + '$mod.i = $with2.GetSize();', + '$mod.i = $with2.GetSize();', + '$with2.SetSize($mod.i);', ''])); end; @@ -6928,7 +6950,7 @@ begin ConvertProgram; CheckSource('TestClass_TypeCast', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.Next = null;', ' };', @@ -6938,14 +6960,14 @@ begin ' this.Create = function () {', ' };', '});', - 'rtl.createClass(this, "TControl", this.TObject, function () {', + 'rtl.createClass($mod, "TControl", $mod.TObject, function () {', ' this.$init = function () {', - ' pas.program.TObject.$init.call(this);', + ' $mod.TObject.$init.call(this);', ' this.Arr = [];', ' };', ' this.$final = function () {', ' this.Arr = undefined;', - ' pas.program.TObject.$final.call(this);', + ' $mod.TObject.$final.call(this);', ' };', ' this.GetIt = function (vI) {', ' var Result = null;', @@ -6954,14 +6976,14 @@ begin '});', 'this.Obj = null;' ]), - LinesToStr([ // this.$main - 'this.Obj = this.Obj.Next;', - 'this.Obj = null;', - 'this.Obj = this.Obj;', - 'this.Obj = this.Obj.GetIt(0);', - 'this.Obj = this.Obj.GetIt(0);', - 'this.Obj = this.Obj.GetIt(1);', - 'this.Obj = this.Obj.GetIt(0).Arr[2];', + LinesToStr([ // $mod.$main + '$mod.Obj = $mod.Obj.Next;', + '$mod.Obj = null;', + '$mod.Obj = $mod.Obj;', + '$mod.Obj = $mod.Obj.GetIt(0);', + '$mod.Obj = $mod.Obj.GetIt(0);', + '$mod.Obj = $mod.Obj.GetIt(1);', + '$mod.Obj = $mod.Obj.GetIt(0).Arr[2];', ''])); end; @@ -6997,7 +7019,7 @@ begin ConvertProgram; CheckSource('TestClass_TypeCastUntypedParam', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -7021,9 +7043,9 @@ begin '};', 'this.o = null;', '']), - LinesToStr([ // this.$main - 'this.ProcA({', - ' p: this,', + LinesToStr([ // $mod.$main + '$mod.ProcA({', + ' p: $mod,', ' get: function () {', ' return this.p.o;', ' },', @@ -7031,8 +7053,8 @@ begin ' this.p.o = v;', ' }', '});', - 'this.ProcB({', - ' p: this,', + '$mod.ProcB({', + ' p: $mod,', ' get: function () {', ' return this.p.o;', ' },', @@ -7040,7 +7062,7 @@ begin ' this.p.o = v;', ' }', '});', - 'this.ProcC(this.o);', + '$mod.ProcC($mod.o);', ''])); end; @@ -7062,7 +7084,7 @@ begin ConvertProgram; CheckSource('TestClass_Overloads', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -7075,7 +7097,7 @@ begin ' };', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -7111,7 +7133,7 @@ begin ConvertProgram; CheckSource('TestClass_OverloadsAncestor', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -7123,18 +7145,18 @@ begin ' this.DoIt$1 = function (vA, vB) {', ' };', '});', - 'rtl.createClass(this, "TCar", this.TObject, function () {', + 'rtl.createClass($mod, "TCar", $mod.TObject, function () {', ' this.DoIt$2 = function (vA) {', ' this.DoIt$2(1);', ' this.DoIt$3(1, 2);', - ' pas.program.TObject.DoIt.call(this, 1);', - ' pas.program.TObject.DoIt$1.call(this, 1, 2);', + ' $mod.TObject.DoIt.call(this, 1);', + ' $mod.TObject.DoIt$1.call(this, 1, 2);', ' };', ' this.DoIt$3 = function (vA, vB) {', ' };', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -7172,7 +7194,7 @@ begin ConvertProgram; CheckSource('TestClass_OverloadConstructor', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -7184,22 +7206,22 @@ begin ' this.Create$1 = function (vA, vB) {', ' };', '});', - 'rtl.createClass(this, "TCar", this.TObject, function () {', + 'rtl.createClass($mod, "TCar", $mod.TObject, function () {', ' this.Create$2 = function (vA) {', ' this.Create$2(1);', ' this.Create$3(1, 2);', - ' pas.program.TObject.Create.call(this, 1);', - ' pas.program.TObject.Create$1.call(this, 1, 2);', + ' $mod.TObject.Create.call(this, 1);', + ' $mod.TObject.Create$1.call(this, 1, 2);', ' };', ' this.Create$3 = function (vA, vB) {', ' };', '});', '']), - LinesToStr([ // this.$main - 'this.TObject.$create("Create", [1]);', - 'this.TObject.$create("Create$1", [1, 2]);', - 'this.TCar.$create("Create$2", [1]);', - 'this.TCar.$create("Create$3", [1, 2]);', + LinesToStr([ // $mod.$main + '$mod.TObject.$create("Create", [1]);', + '$mod.TObject.$create("Create$1", [1, 2]);', + '$mod.TCar.$create("Create$2", [1]);', + '$mod.TCar.$create("Create$3", [1, 2]);', ''])); end; @@ -7229,20 +7251,20 @@ begin ConvertProgram; CheckSource('TestClass_ReintroducedVar', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.Some = 0;', ' };', ' this.$final = function () {', ' };', '});', - 'rtl.createClass(this, "TMobile", this.TObject, function () {', + 'rtl.createClass($mod, "TMobile", $mod.TObject, function () {', ' this.$init = function () {', - ' pas.program.TObject.$init.call(this);', + ' $mod.TObject.$init.call(this);', ' this.Some$1 = "";', ' };', '});', - 'rtl.createClass(this, "TCar", this.TMobile, function () {', + 'rtl.createClass($mod, "TCar", $mod.TMobile, function () {', ' this.Some$2 = function () {', ' this.Some$2();', ' this.Some$3(1);', @@ -7251,7 +7273,7 @@ begin ' };', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -7273,7 +7295,7 @@ begin ConvertProgram; CheckSource('TestClass_RaiseDescendant', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -7281,14 +7303,14 @@ begin ' this.Create = function (Msg) {', ' };', '});', - 'rtl.createClass(this, "Exception", this.TObject, function () {', + 'rtl.createClass($mod, "Exception", $mod.TObject, function () {', '});', - 'rtl.createClass(this, "EConvertError", this.Exception, function () {', + 'rtl.createClass($mod, "EConvertError", $mod.Exception, function () {', '});', '']), - LinesToStr([ // this.$main - 'throw this.Exception.$create("Create",["Bar1"]);', - 'throw this.EConvertError.$create("Create",["Bar2"]);', + LinesToStr([ // $mod.$main + 'throw $mod.Exception.$create("Create",["Bar1"]);', + 'throw $mod.EConvertError.$create("Create",["Bar2"]);', ''])); end; @@ -7339,8 +7361,8 @@ begin ConvertUnit; CheckSource('TestClass_ExternalMethod', LinesToStr([ - 'var $impl = this.$impl;', - 'rtl.createClass(this, "TCar", pas.unit2.TObject, function () {', + 'var $impl = $mod.$impl;', + 'rtl.createClass($mod, "TCar", pas.unit2.TObject, function () {', ' this.DoIt = function () {', ' this.$DoIntern();', ' this.$DoIntern();', @@ -7437,8 +7459,8 @@ begin ConvertUnit; CheckSource('TestClass_ExternalVar', LinesToStr([ - 'var $impl = this.$impl;', - 'rtl.createClass(this, "TCar", pas.unit2.TObject, function () {', + 'var $impl = $mod.$impl;', + 'rtl.createClass($mod, "TCar", pas.unit2.TObject, function () {', ' this.DoIt = function () {', ' this.$Intern = this.$Intern + 1;', ' this.$Intern2 = this.$Intern2 + 2;', @@ -7505,7 +7527,7 @@ begin ConvertProgram; CheckSource('TestClass_Const', LinesToStr([ - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.cI = 3;', ' this.$init = function () {', ' };', @@ -7534,18 +7556,250 @@ begin 'this.Cla = null;', '']), LinesToStr([ - 'if (this.TObject.cI == 21) ;', - 'if (this.Obj.cI == 22) ;', - 'if (this.Cla.cI == 23) ;', - 'var $with1 = this.Obj;', + 'if ($mod.TObject.cI == 21) ;', + 'if ($mod.Obj.cI == 22) ;', + 'if ($mod.Cla.cI == 23) ;', + 'var $with1 = $mod.Obj;', 'if ($with1.cI == 24) ;', - 'var $with2 = this.TObject;', + 'var $with2 = $mod.TObject;', 'if ($with2.cI == 25) ;', - 'var $with3 = this.Cla;', + 'var $with3 = $mod.Cla;', 'if ($with3.cI == 26) ;', ''])); end; +procedure TTestModule.TestClass_LocalVarSelfFail; +begin + StartProgram(false); + Add([ + 'type', + ' TObject = class', + ' constructor Create;', + ' end;', + 'constructor tobject.create;', + 'var self: longint;', + 'begin', + 'end', + 'begin', + '']); + SetExpectedPasResolverError('Duplicate identifier "self" at (0)',nDuplicateIdentifier); + ConvertProgram; +end; + +procedure TTestModule.TestClass_ArgSelfFail; +begin + StartProgram(false); + Add([ + 'type', + ' TObject = class', + ' procedure DoIt(Self: longint);', + ' end;', + 'procedure tobject.doit(self: longint);', + 'begin', + 'end', + 'begin', + '']); + SetExpectedPasResolverError('Duplicate identifier "Self" at test1.pp(5,23)',nDuplicateIdentifier); + ConvertProgram; +end; + +procedure TTestModule.TestClass_NestedSelf; +begin + StartProgram(false); + Add([ + 'type', + ' TObject = class', + ' Key: longint;', + ' class var State: longint;', + ' procedure DoIt;', + ' function GetSize: longint; virtual; abstract;', + ' procedure SetSize(Value: longint); virtual; abstract;', + ' property Size: longint read GetSize write SetSize;', + ' end;', + 'procedure tobject.doit;', + ' procedure Sub;', + ' begin', + ' key:=key+2;', + ' self.key:=self.key+3;', + ' state:=state+4;', + ' self.state:=self.state+5;', + ' tobject.state:=tobject.state+6;', + ' size:=size+7;', + ' self.size:=self.size+8;', + ' end;', + 'begin', + ' sub;', + ' key:=key+12;', + ' self.key:=self.key+13;', + ' state:=state+14;', + ' self.state:=self.state+15;', + ' tobject.state:=tobject.state+16;', + ' size:=size+17;', + ' self.size:=self.size+18;', + 'end;', + 'begin', + '']); + ConvertProgram; + CheckSource('TestClass_NestedSelf', + LinesToStr([ // statements + 'rtl.createClass($mod, "TObject", null, function () {', + ' this.State = 0;', + ' this.$init = function () {', + ' this.Key = 0;', + ' };', + ' this.$final = function () {', + ' };', + ' this.DoIt = function () {', + ' var Self = this;', + ' function Sub() {', + ' Self.Key = Self.Key + 2;', + ' Self.Key = Self.Key + 3;', + ' Self.$class.State = Self.State + 4;', + ' Self.$class.State = Self.State + 5;', + ' $mod.TObject.State = $mod.TObject.State + 6;', + ' Self.SetSize(Self.GetSize() + 7);', + ' Self.SetSize(Self.GetSize() + 8);', + ' };', + ' Sub();', + ' Self.Key = Self.Key + 12;', + ' Self.Key = Self.Key + 13;', + ' Self.$class.State = Self.State + 14;', + ' Self.$class.State = Self.State + 15;', + ' $mod.TObject.State = $mod.TObject.State + 16;', + ' Self.SetSize(Self.GetSize() + 17);', + ' Self.SetSize(Self.GetSize() + 18);', + ' };', + '});', + '']), + LinesToStr([ // $mod.$main + ''])); +end; + +procedure TTestModule.TestClass_NestedClassSelf; +begin + StartProgram(false); + Add([ + 'type', + ' TObject = class', + ' class var State: longint;', + ' class procedure DoIt;', + ' class function GetSize: longint; virtual; abstract;', + ' class procedure SetSize(Value: longint); virtual; abstract;', + ' class property Size: longint read GetSize write SetSize;', + ' end;', + 'class procedure tobject.doit;', + ' procedure Sub;', + ' begin', + ' state:=state+2;', + ' self.state:=self.state+3;', + ' tobject.state:=tobject.state+4;', + ' size:=size+5;', + ' self.size:=self.size+6;', + ' tobject.size:=tobject.size+7;', + ' end;', + 'begin', + ' sub;', + ' state:=state+12;', + ' self.state:=self.state+13;', + ' tobject.state:=tobject.state+14;', + ' size:=size+15;', + ' self.size:=self.size+16;', + ' tobject.size:=tobject.size+17;', + 'end;', + 'begin', + '']); + ConvertProgram; + CheckSource('TestClass_NestedClassSelf', + LinesToStr([ // statements + 'rtl.createClass($mod, "TObject", null, function () {', + ' this.State = 0;', + ' this.$init = function () {', + ' };', + ' this.$final = function () {', + ' };', + ' this.DoIt = function () {', + ' var Self = this;', + ' function Sub() {', + ' Self.State = Self.State + 2;', + ' Self.State = Self.State + 3;', + ' $mod.TObject.State = $mod.TObject.State + 4;', + ' Self.SetSize(Self.GetSize() + 5);', + ' Self.SetSize(Self.GetSize() + 6);', + ' $mod.TObject.SetSize($mod.TObject.GetSize() + 7);', + ' };', + ' Sub();', + ' Self.State = Self.State + 12;', + ' Self.State = Self.State + 13;', + ' $mod.TObject.State = $mod.TObject.State + 14;', + ' Self.SetSize(Self.GetSize() + 15);', + ' Self.SetSize(Self.GetSize() + 16);', + ' $mod.TObject.SetSize($mod.TObject.GetSize() + 17);', + ' };', + '});', + '']), + LinesToStr([ // $mod.$main + ''])); +end; + +procedure TTestModule.TestClass_NestedCallInherited; +begin + StartProgram(false); + Add([ + 'type', + ' TObject = class', + ' function DoIt(k: boolean): longint; virtual;', + ' end;', + ' TBird = class', + ' function DoIt(k: boolean): longint; override;', + ' end;', + 'function tobject.doit(k: boolean): longint;', + 'begin', + 'end;', + 'function tbird.doit(k: boolean): longint;', + ' procedure Sub;', + ' begin', + ' inherited DoIt(true);', + //' if inherited DoIt(false)=4 then ;', + ' end;', + 'begin', + ' Sub;', + ' inherited;', + ' inherited DoIt(true);', + //' if inherited DoIt(false)=14 then ;', + 'end;', + 'begin', + '']); + ConvertProgram; + CheckSource('TestClass_NestedCallInherited', + LinesToStr([ // statements + 'rtl.createClass($mod, "TObject", null, function () {', + ' this.$init = function () {', + ' };', + ' this.$final = function () {', + ' };', + ' this.DoIt = function (k) {', + ' var Result = 0;', + ' return Result;', + ' };', + '});', + 'rtl.createClass($mod, "TBird", $mod.TObject, function () {', + ' this.DoIt = function (k) {', + ' var Self = this;', + ' var Result = 0;', + ' function Sub() {', + ' $mod.TObject.DoIt.call(Self, true);', + ' };', + ' Sub();', + ' $mod.TObject.DoIt.apply(Self, arguments);', + ' $mod.TObject.DoIt.call(Self, true);', + ' return Result;', + ' };', + '});', + '']), + LinesToStr([ // $mod.$main + ''])); +end; + procedure TTestModule.TestClassOf_Create; begin StartProgram(false); @@ -7564,7 +7818,7 @@ begin ConvertProgram; CheckSource('TestClassOf_Create', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -7575,10 +7829,10 @@ begin 'this.Obj = null;', 'this.C = null;' ]), - LinesToStr([ // this.$main - 'this.Obj = this.C.$create("Create");', - 'var $with1 = this.C;', - 'this.Obj = $with1.$create("Create");', + LinesToStr([ // $mod.$main + '$mod.Obj = $mod.C.$create("Create");', + 'var $with1 = $mod.C;', + '$mod.Obj = $with1.$create("Create");', ''])); end; @@ -7599,7 +7853,7 @@ begin ConvertProgram; CheckSource('TestClassOf_Call', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -7609,9 +7863,9 @@ begin '});', 'this.C = null;' ]), - LinesToStr([ // this.$main - 'this.C.DoIt();', - 'var $with1 = this.C;', + LinesToStr([ // $mod.$main + '$mod.C.DoIt();', + 'var $with1 = $mod.C;', '$with1.DoIt();', ''])); end; @@ -7633,7 +7887,7 @@ begin ConvertProgram; CheckSource('TestClassOf_Assign', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.ClassType = null;', ' };', @@ -7644,9 +7898,9 @@ begin 'this.Obj = null;', 'this.C = null;' ]), - LinesToStr([ // this.$main - 'this.C = null;', - 'this.C = this.Obj.ClassType;', + LinesToStr([ // $mod.$main + '$mod.C = null;', + '$mod.C = $mod.Obj.ClassType;', ''])); end; @@ -7670,21 +7924,21 @@ begin ConvertProgram; CheckSource('TestClassOf_Is', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', ' };', '});', - 'rtl.createClass(this, "TCar", this.TObject, function () {', + 'rtl.createClass($mod, "TCar", $mod.TObject, function () {', '});', 'this.Obj = null;', 'this.C = null;', 'this.Cars = null;' ]), - LinesToStr([ // this.$main - 'if(rtl.is(this.C,this.TCar));', - 'if(rtl.is(this.C,this.TCar));', + LinesToStr([ // $mod.$main + 'if(rtl.is($mod.C,$mod.TCar));', + 'if(rtl.is($mod.C,$mod.TCar));', ''])); end; @@ -7716,7 +7970,7 @@ begin ConvertProgram; CheckSource('TestClassOf_Compare', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.ClassType = null;', ' };', @@ -7728,19 +7982,19 @@ begin 'this.Obj = null;', 'this.C = null;' ]), - LinesToStr([ // this.$main - 'this.b = this.C == null;', - 'this.b = null == this.C;', - 'this.b = this.C == this.Obj.ClassType;', - 'this.b = this.Obj.ClassType == this.C;', - 'this.b = this.C == this.TObject;', - 'this.b = this.TObject == this.C;', - 'this.b = this.C != null;', - 'this.b = null != this.C;', - 'this.b = this.C != this.Obj.ClassType;', - 'this.b = this.Obj.ClassType != this.C;', - 'this.b = this.C != this.TObject;', - 'this.b = this.TObject != this.C;', + LinesToStr([ // $mod.$main + '$mod.b = $mod.C == null;', + '$mod.b = null == $mod.C;', + '$mod.b = $mod.C == $mod.Obj.ClassType;', + '$mod.b = $mod.Obj.ClassType == $mod.C;', + '$mod.b = $mod.C == $mod.TObject;', + '$mod.b = $mod.TObject == $mod.C;', + '$mod.b = $mod.C != null;', + '$mod.b = null != $mod.C;', + '$mod.b = $mod.C != $mod.Obj.ClassType;', + '$mod.b = $mod.Obj.ClassType != $mod.C;', + '$mod.b = $mod.C != $mod.TObject;', + '$mod.b = $mod.TObject != $mod.C;', ''])); end; @@ -7759,7 +8013,7 @@ begin ConvertProgram; CheckSource('TestClassOf_ClassVar', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.id = 0;', ' this.$init = function () {', ' };', @@ -7768,8 +8022,8 @@ begin '});', 'this.C = null;' ]), - LinesToStr([ // this.$main - 'this.C.id = this.C.id;', + LinesToStr([ // $mod.$main + '$mod.C.id = $mod.C.id;', ''])); end; @@ -7793,7 +8047,7 @@ begin ConvertProgram; CheckSource('TestClassOf_ClassMethod', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -7806,11 +8060,11 @@ begin 'this.i = 0;', 'this.C = null;' ]), - LinesToStr([ // this.$main - 'this.C.DoIt(0);', - 'this.C.DoIt(0);', - 'this.i = this.C.DoIt(0);', - 'this.i = this.C.DoIt(0);', + LinesToStr([ // $mod.$main + '$mod.C.DoIt(0);', + '$mod.C.DoIt(0);', + '$mod.i = $mod.C.DoIt(0);', + '$mod.i = $mod.C.DoIt(0);', ''])); end; @@ -7851,7 +8105,7 @@ begin ConvertProgram; CheckSource('TestClassOf_ClassProperty', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.FA = 0;', ' this.$init = function () {', ' };', @@ -7868,22 +8122,22 @@ begin 'this.Obj = null;', 'this.Cla = null;' ]), - LinesToStr([ // this.$main - 'this.Obj.$class.FA = this.Obj.FA;', - 'this.Obj.$class.SetA(this.Obj.$class.GetA());', - 'this.b = this.Obj.FA == 4;', - 'this.b = this.Obj.$class.GetA() == this.Obj.$class.GetA();', - 'this.b = 5 == this.Obj.FA;', - 'this.Cla.FA = 6;', - 'this.Cla.FA = this.Cla.FA;', - 'this.Cla.SetA(this.Cla.GetA());', - 'this.b = this.Cla.FA == 7;', - 'this.b = this.Cla.GetA() == this.Cla.GetA();', - 'this.b = 8 == this.Cla.FA;', - 'this.TObject.FA = 9;', - 'this.TObject.SetA(this.TObject.GetA());', - 'this.b = this.TObject.FA == 10;', - 'this.b = 11 == this.TObject.FA;', + LinesToStr([ // $mod.$main + '$mod.Obj.$class.FA = $mod.Obj.FA;', + '$mod.Obj.$class.SetA($mod.Obj.$class.GetA());', + '$mod.b = $mod.Obj.FA == 4;', + '$mod.b = $mod.Obj.$class.GetA() == $mod.Obj.$class.GetA();', + '$mod.b = 5 == $mod.Obj.FA;', + '$mod.Cla.FA = 6;', + '$mod.Cla.FA = $mod.Cla.FA;', + '$mod.Cla.SetA($mod.Cla.GetA());', + '$mod.b = $mod.Cla.FA == 7;', + '$mod.b = $mod.Cla.GetA() == $mod.Cla.GetA();', + '$mod.b = 8 == $mod.Cla.FA;', + '$mod.TObject.FA = 9;', + '$mod.TObject.SetA($mod.TObject.GetA());', + '$mod.b = $mod.TObject.FA == 10;', + '$mod.b = 11 == $mod.TObject.FA;', ''])); end; @@ -7908,7 +8162,7 @@ begin ConvertProgram; CheckSource('TestClassOf_ClassMethodSelf', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.GlobalId = 0;', ' this.$init = function () {', ' };', @@ -7924,7 +8178,7 @@ begin ' };', '});' ]), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -7976,7 +8230,7 @@ begin ConvertProgram; CheckSource('TestClassOf_TypeCast', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -7986,14 +8240,14 @@ begin ' this.DoIt$1();', ' };', '});', - 'rtl.createClass(this, "TMobile", this.TObject, function () {', + 'rtl.createClass($mod, "TMobile", $mod.TObject, function () {', ' this.DoIt$1 = function () {', ' this.DoIt();', ' this.DoIt$1();', ' this.DoIt$2();', ' };', '});', - 'rtl.createClass(this, "TCar", this.TMobile, function () {', + 'rtl.createClass($mod, "TCar", $mod.TMobile, function () {', ' this.DoIt$2 = function () {', ' };', '});', @@ -8001,19 +8255,19 @@ begin 'this.MobileC = null;', 'this.CarC = null;', '']), - LinesToStr([ // this.$main - 'this.ObjC.DoIt();', - 'this.MobileC.DoIt$1();', - 'this.CarC.DoIt$2();', - 'this.ObjC.DoIt();', - 'this.ObjC.DoIt$1();', - 'this.ObjC.DoIt$2();', - 'this.MobileC.DoIt();', - 'this.MobileC.DoIt$1();', - 'this.MobileC.DoIt$2();', - 'this.CarC.DoIt();', - 'this.CarC.DoIt$1();', - 'this.CarC.DoIt$2();', + LinesToStr([ // $mod.$main + '$mod.ObjC.DoIt();', + '$mod.MobileC.DoIt$1();', + '$mod.CarC.DoIt$2();', + '$mod.ObjC.DoIt();', + '$mod.ObjC.DoIt$1();', + '$mod.ObjC.DoIt$2();', + '$mod.MobileC.DoIt();', + '$mod.MobileC.DoIt$1();', + '$mod.MobileC.DoIt$2();', + '$mod.CarC.DoIt();', + '$mod.CarC.DoIt$1();', + '$mod.CarC.DoIt$2();', ''])); end; @@ -8038,7 +8292,7 @@ begin ConvertProgram; CheckSource('TestClassOf_ImplicitFunctionCall', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -8055,11 +8309,11 @@ begin 'this.Obj = null;', 'this.vI = 0;', '']), - LinesToStr([ // this.$main - 'this.Obj.CurNow();', - 'this.vI = this.Obj.CurNow();', - 'this.TObject.Now();', - 'this.vI = this.TObject.Now();', + LinesToStr([ // $mod.$main + '$mod.Obj.CurNow();', + '$mod.vI = $mod.Obj.CurNow();', + '$mod.TObject.Now();', + '$mod.vI = $mod.TObject.Now();', ''])); end; @@ -8081,9 +8335,9 @@ begin LinesToStr([ // statements 'this.Obj = null;', '']), - LinesToStr([ // this.$main - 'this.Obj.$Id = this.Obj.$Id + 1;', - 'this.Obj.B = this.Obj.B + 1;', + LinesToStr([ // $mod.$main + '$mod.Obj.$Id = $mod.Obj.$Id + 1;', + '$mod.Obj.B = $mod.Obj.B + 1;', ''])); end; @@ -8127,11 +8381,11 @@ begin LinesToStr([ // statements 'this.Obj = null;', '']), - LinesToStr([ // this.$main - 'this.Obj.$Execute(1);', - 'this.Obj.$Execute(1);', - 'this.Obj.$Execute(2);', - 'var $with1 = this.Obj;', + LinesToStr([ // $mod.$main + '$mod.Obj.$Execute(1);', + '$mod.Obj.$Execute(1);', + '$mod.Obj.$Execute(2);', + 'var $with1 = $mod.Obj;', '$with1.$Execute(1);', '$with1.$Execute(1);', '$with1.$Execute(3);', @@ -8170,7 +8424,7 @@ begin ConvertProgram; CheckSource('TestExternalClass_NonExternalOverride', LinesToStr([ // statements - 'rtl.createClassExt(this, "TExtC", ExtObjB, "", function () {', + 'rtl.createClassExt($mod, "TExtC", ExtObjB, "", function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -8186,10 +8440,10 @@ begin 'this.B = null;', 'this.C = null;', '']), - LinesToStr([ // this.$main - 'this.A.ProcA();', - 'this.B.ProcA();', - 'this.C.ProcA();', + LinesToStr([ // $mod.$main + '$mod.A.ProcA();', + '$mod.B.ProcA();', + '$mod.C.ProcA();', ''])); end; @@ -8220,7 +8474,7 @@ begin ConvertProgram; CheckSource('TestExternalClass_NonExternalOverride', LinesToStr([ // statements - 'rtl.createClassExt(this, "TExtB", ExtA, "", function () {', + 'rtl.createClassExt($mod, "TExtB", ExtA, "", function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -8232,9 +8486,9 @@ begin 'this.A = null;', 'this.B = null;', '']), - LinesToStr([ // this.$main - 'this.A.setYear(this.A.getYear()+1);', - 'this.B.OtherSetYear(this.B.getYear()+2);', + LinesToStr([ // $mod.$main + '$mod.A.setYear($mod.A.getYear()+1);', + '$mod.B.OtherSetYear($mod.B.getYear()+2);', ''])); end; @@ -8277,7 +8531,7 @@ begin ConvertProgram; CheckSource('TestExternalClass_ClassProperty', LinesToStr([ // statements - 'rtl.createClassExt(this, "TExtB", ExtA, "", function () {', + 'rtl.createClassExt($mod, "TExtB", ExtA, "", function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -8290,20 +8544,20 @@ begin ' this.setYear(Value + 11);', ' ExtA.setYear(ExtA.getYear() + 12);', ' this.setYear(this.getYear() + 13);', - ' pas.program.TExtB.SetCentury(pas.program.TExtB.GetCentury() + 14);', + ' $mod.TExtB.SetCentury($mod.TExtB.GetCentury() + 14);', ' this.SetCentury(this.GetCentury() + 15);', ' };', '});', 'this.A = null;', 'this.B = null;', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main 'ExtA.setYear(ExtA.getYear() + 1);', - 'this.TExtB.setYear(this.TExtB.getYear() + 2);', + '$mod.TExtB.setYear($mod.TExtB.getYear() + 2);', 'ExtA.setYear(ExtA.getYear() + 3);', - 'this.B.setYear(this.B.getYear() + 4);', - 'this.TExtB.SetCentury(this.TExtB.GetCentury() + 5);', - 'this.B.$class.SetCentury(this.B.$class.GetCentury() + 6);', + '$mod.B.setYear($mod.B.getYear() + 4);', + '$mod.TExtB.SetCentury($mod.TExtB.GetCentury() + 5);', + '$mod.B.$class.SetCentury($mod.B.$class.GetCentury() + 6);', ''])); end; @@ -8339,7 +8593,7 @@ begin ConvertProgram; CheckSource('TestExternalClass_ClassOf', LinesToStr([ // statements - 'rtl.createClassExt(this, "TExtC", ExtB, "", function () {', + 'rtl.createClassExt($mod, "TExtC", ExtB, "", function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -8354,13 +8608,13 @@ begin 'this.C = null;', 'this.ClC = null;', '']), - LinesToStr([ // this.$main - 'this.ClA = ExtA;', - 'this.ClA = ExtB;', - 'this.ClA = this.TExtC;', - 'this.ClB = ExtB;', - 'this.ClB = this.TExtC;', - 'this.ClC = this.TExtC;', + LinesToStr([ // $mod.$main + '$mod.ClA = ExtA;', + '$mod.ClA = ExtB;', + '$mod.ClA = $mod.TExtC;', + '$mod.ClB = ExtB;', + '$mod.ClB = $mod.TExtC;', + '$mod.ClC = $mod.TExtC;', ''])); end; @@ -8419,7 +8673,7 @@ begin ConvertProgram; CheckSource('TestExternalClass_Is', LinesToStr([ // statements - 'rtl.createClassExt(this, "TExtC", ExtB, "", function () {', + 'rtl.createClassExt($mod, "TExtC", ExtB, "", function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -8432,13 +8686,13 @@ begin 'this.C = null;', 'this.ClC = null;', '']), - LinesToStr([ // this.$main - 'if (rtl.isExt(this.A, ExtB)) ;', - 'if (this.TExtC.isPrototypeOf(this.A)) ;', - 'if (this.TExtC.isPrototypeOf(this.B)) ;', - 'if (rtl.isExt(this.ClA, ExtB)) ;', - 'if (rtl.is(this.ClA, this.TExtC)) ;', - 'if (rtl.is(this.ClB, this.TExtC)) ;', + LinesToStr([ // $mod.$main + 'if (rtl.isExt($mod.A, ExtB)) ;', + 'if ($mod.TExtC.isPrototypeOf($mod.A)) ;', + 'if ($mod.TExtC.isPrototypeOf($mod.B)) ;', + 'if (rtl.isExt($mod.ClA, ExtB)) ;', + 'if (rtl.is($mod.ClA, $mod.TExtC)) ;', + 'if (rtl.is($mod.ClB, $mod.TExtC)) ;', ''])); end; @@ -8464,7 +8718,7 @@ begin ConvertProgram; CheckSource('TestExternalClass_Is', LinesToStr([ // statements - 'rtl.createClassExt(this, "TExtC", ExtB, "", function () {', + 'rtl.createClassExt($mod, "TExtC", ExtB, "", function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -8474,10 +8728,10 @@ begin 'this.B = null;', 'this.C = null;', '']), - LinesToStr([ // this.$main - 'this.B = rtl.asExt(this.A, ExtB);', - 'this.C = rtl.as(this.A, this.TExtC);', - 'this.C = rtl.as(this.B, this.TExtC);', + LinesToStr([ // $mod.$main + '$mod.B = rtl.asExt($mod.A, ExtB);', + '$mod.C = rtl.as($mod.A, $mod.TExtC);', + '$mod.C = rtl.as($mod.B, $mod.TExtC);', ''])); end; @@ -8522,17 +8776,17 @@ begin LinesToStr([ // statements 'this.A = null;', '']), - LinesToStr([ // this.$main - 'this.A = new ExtA();', - 'this.A = new ExtA();', - 'this.A = new ExtA(1,2);', + LinesToStr([ // $mod.$main + '$mod.A = new ExtA();', + '$mod.A = new ExtA();', + '$mod.A = new ExtA(1,2);', 'var $with1 = ExtA;', - 'this.A = new $with1();', - 'this.A = new $with1();', - 'this.A = new $with1(2,2);', - 'this.A = new ExtA();', - 'this.A = new ExtA();', - 'this.A = new ExtA(3,2);', + '$mod.A = new $with1();', + '$mod.A = new $with1();', + '$mod.A = new $with1(2,2);', + '$mod.A = new ExtA();', + '$mod.A = new ExtA();', + '$mod.A = new ExtA(3,2);', ''])); end; @@ -8563,14 +8817,14 @@ begin 'this.A = null;', 'this.C = null;', '']), - LinesToStr([ // this.$main - 'this.A = new this.C();', - 'this.A = new this.C();', - 'var $with1 = this.C;', - 'this.A = new $with1();', - 'this.A = new $with1();', - 'this.A = new this.C();', - 'this.A = new this.C();', + LinesToStr([ // $mod.$main + '$mod.A = new $mod.C();', + '$mod.A = new $mod.C();', + 'var $with1 = $mod.C;', + '$mod.A = new $with1();', + '$mod.A = new $with1();', + '$mod.A = new $mod.C();', + '$mod.A = new $mod.C();', ''])); end; @@ -8608,14 +8862,14 @@ begin '};', 'this.A = null;', '']), - LinesToStr([ // this.$main - 'this.A = new (this.GetCreator())();', - 'this.A = new (this.GetCreator())();', - 'this.A = new (this.GetCreator())();', - 'this.A = new (this.GetCreator())();', - 'var $with1 = this.GetCreator();', - 'this.A = new $with1();', - 'this.A = new $with1();', + LinesToStr([ // $mod.$main + '$mod.A = new ($mod.GetCreator())();', + '$mod.A = new ($mod.GetCreator())();', + '$mod.A = new ($mod.GetCreator())();', + '$mod.A = new ($mod.GetCreator())();', + 'var $with1 = $mod.GetCreator();', + '$mod.A = new $with1();', + '$mod.A = new $with1();', ''])); end; @@ -8647,8 +8901,8 @@ begin '};', 'this.A = null;', '']), - LinesToStr([ // this.$main - 'this.A = new ExtA();', + LinesToStr([ // $mod.$main + '$mod.A = new ExtA();', ''])); end; @@ -8668,7 +8922,7 @@ begin ConvertProgram; CheckSource('TestExternalClass_ReintroduceOverload', LinesToStr([ // statements - 'rtl.createClassExt(this, "TMyA", ExtA, "", function () {', + 'rtl.createClassExt($mod, "TMyA", ExtA, "", function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -8677,7 +8931,7 @@ begin ' };', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -8714,7 +8968,7 @@ begin ConvertProgram; CheckSource('TestExternalClass_ReintroduceOverload', LinesToStr([ // statements - 'rtl.createClassExt(this, "TMyC", ExtB, "", function () {', + 'rtl.createClassExt($mod, "TMyC", ExtB, "", function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -8733,7 +8987,7 @@ begin ' };', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -8768,7 +9022,7 @@ begin ConvertProgram; CheckSource('TestExternalClass_NewInstance', LinesToStr([ // statements - 'rtl.createClassExt(this, "TMyB", ExtA, "NewInstance", function () {', + 'rtl.createClassExt($mod, "TMyB", ExtA, "NewInstance", function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -8779,7 +9033,7 @@ begin ' };', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -8866,7 +9120,7 @@ begin ConvertProgram; CheckSource('TestExternalClass_PascalProperty', LinesToStr([ // statements - 'rtl.createClassExt(this, "TControl", ExtA, "", function () {', + 'rtl.createClassExt($mod, "TControl", ExtA, "", function () {', ' this.$init = function () {', ' this.FOnClick = null;', ' };', @@ -8879,9 +9133,9 @@ begin '});', 'this.Ctrl = null;', '']), - LinesToStr([ // this.$main - 'this.Ctrl.FOnClick = rtl.createCallback(this.Ctrl, "Click");', - 'this.Ctrl.FOnClick(this.Ctrl);', + LinesToStr([ // $mod.$main + '$mod.Ctrl.FOnClick = rtl.createCallback($mod.Ctrl, "Click");', + '$mod.Ctrl.FOnClick($mod.Ctrl);', ''])); end; @@ -8921,13 +9175,13 @@ begin ConvertProgram; CheckSource('TestExternalClass_TypeCastToRootClass', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', ' };', '});', - 'rtl.createClass(this, "TChild", this.TObject, function () {', + 'rtl.createClass($mod, "TChild", $mod.TObject, function () {', '});', 'this.Obj = null;', 'this.Child = null;', @@ -8936,15 +9190,15 @@ begin 'this.RootB = null;', 'this.ChildB = null;', '']), - LinesToStr([ // this.$main - 'this.Obj = this.RootA;', - 'this.Obj = this.ChildA;', - 'this.Child = this.RootA;', - 'this.RootA = this.Obj;', - 'this.RootA = this.Child;', - 'this.RootA = this.RootB;', - 'this.RootA = this.ChildB;', - 'this.ChildA = this.Obj;', + LinesToStr([ // $mod.$main + '$mod.Obj = $mod.RootA;', + '$mod.Obj = $mod.ChildA;', + '$mod.Child = $mod.RootA;', + '$mod.RootA = $mod.Obj;', + '$mod.RootA = $mod.Child;', + '$mod.RootA = $mod.RootB;', + '$mod.RootA = $mod.ChildB;', + '$mod.ChildA = $mod.Obj;', ''])); end; @@ -8968,10 +9222,10 @@ begin LinesToStr([ // statements 'this.s = "";', '']), - LinesToStr([ // this.$main - 'this.s = String.fromCharCode(65, 66);', - 'this.s = this.s.anchor(this.s);', - 'this.s = "foo".anchor(this.s);', + LinesToStr([ // $mod.$main + '$mod.s = String.fromCharCode(65, 66);', + '$mod.s = $mod.s.anchor($mod.s);', + '$mod.s = "foo".anchor($mod.s);', ''])); end; @@ -9030,19 +9284,19 @@ begin 'this.i = 0;', 'this.v = undefined;', '']), - LinesToStr([ // this.$main - 'this.v = this.Arr[0];', - 'this.v = this.Arr[1];', - 'this.Arr[2] = this.s;', - 'this.Arr[3] = this.s;', - 'this.Arr[4] = this.i;', - 'this.Arr[5] = this.Arr[6];', - 'this.Arr[7] = this.Arr[8];', - 'var $with1 = this.Arr;', + LinesToStr([ // $mod.$main + '$mod.v = $mod.Arr[0];', + '$mod.v = $mod.Arr[1];', + '$mod.Arr[2] = $mod.s;', + '$mod.Arr[3] = $mod.s;', + '$mod.Arr[4] = $mod.i;', + '$mod.Arr[5] = $mod.Arr[6];', + '$mod.Arr[7] = $mod.Arr[8];', + 'var $with1 = $mod.Arr;', '$with1[9] = $with1[10];', - 'this.DoIt(this.Arr[7], this.Arr[8], {', + '$mod.DoIt($mod.Arr[7], $mod.Arr[8], {', ' a: 9,', - ' p: this.Arr,', + ' p: $mod.Arr,', ' get: function () {', ' return this.p[this.a];', ' },', @@ -9051,7 +9305,7 @@ begin ' }', '}, {', ' a: 10,', - ' p: this.Arr,', + ' p: $mod.Arr,', ' get: function () {', ' return this.p[this.a];', ' },', @@ -9105,12 +9359,12 @@ begin 'this.Arr = null;', 'this.v = undefined;', '']), - LinesToStr([ // this.$main - 'this.v = this.Arr[0];', - 'this.v = this.Arr[1];', - 'var $with1 = this.Arr;', - 'this.v = $with1[2];', - 'this.DoIt(this.Arr[3], this.Arr[4]);', + LinesToStr([ // $mod.$main + '$mod.v = $mod.Arr[0];', + '$mod.v = $mod.Arr[1];', + 'var $with1 = $mod.Arr;', + '$mod.v = $with1[2];', + '$mod.DoIt($mod.Arr[3], $mod.Arr[4]);', ''])); end; @@ -9141,12 +9395,12 @@ begin 'this.i = 0;', 'this.v = undefined;', '']), - LinesToStr([ // this.$main - 'this.Arr[2] = this.s;', - 'this.Arr[3] = this.s;', - 'this.Arr[4] = this.i;', - 'var $with1 = this.Arr;', - '$with1[5] = this.i;', + LinesToStr([ // $mod.$main + '$mod.Arr[2] = $mod.s;', + '$mod.Arr[3] = $mod.s;', + '$mod.Arr[4] = $mod.i;', + 'var $with1 = $mod.Arr;', + '$with1[5] = $mod.i;', ''])); end; @@ -9180,14 +9434,14 @@ begin 'this.i = 0;', 'this.v = undefined;', '']), - LinesToStr([ // this.$main - 'this.Arr[2] = this.s;', - 'this.Arr[3] = this.s;', - 'this.Arr[4] = this.i;', - 'var $with1 = this.Arr;', - '$with1[5] = this.i;', - 'var $with2 = this.Arr;', - '$with2[6] = this.i;', + LinesToStr([ // $mod.$main + '$mod.Arr[2] = $mod.s;', + '$mod.Arr[3] = $mod.s;', + '$mod.Arr[4] = $mod.i;', + 'var $with1 = $mod.Arr;', + '$with1[5] = $mod.i;', + 'var $with2 = $mod.Arr;', + '$with2[6] = $mod.i;', ''])); end; @@ -9228,24 +9482,24 @@ begin 'this.vP = null;', 'this.vQ = null;' ]), - LinesToStr([ // this.$main - 'this.vP = null;', - 'this.vP = this.vP;', - 'this.vP = rtl.createCallback(this,"DoIt");', - 'this.vP(1);', - 'this.vP(1);', - 'this.vP(2);', - 'this.b = this.vP == null;', - 'this.b = null == this.vP;', - 'this.b = rtl.eqCallback(this.vP,this.vQ);', - 'this.b = rtl.eqCallback(this.vP, rtl.createCallback(this, "DoIt"));', - 'this.b = rtl.eqCallback(rtl.createCallback(this, "DoIt"), this.vP);', - 'this.b = this.vP != null;', - 'this.b = null != this.vP;', - 'this.b = !rtl.eqCallback(this.vP,this.vQ);', - 'this.b = !rtl.eqCallback(this.vP, rtl.createCallback(this, "DoIt"));', - 'this.b = !rtl.eqCallback(rtl.createCallback(this, "DoIt"), this.vP);', - 'this.b = this.vP != null;', + LinesToStr([ // $mod.$main + '$mod.vP = null;', + '$mod.vP = $mod.vP;', + '$mod.vP = $mod.DoIt;', + '$mod.vP(1);', + '$mod.vP(1);', + '$mod.vP(2);', + '$mod.b = $mod.vP == null;', + '$mod.b = null == $mod.vP;', + '$mod.b = rtl.eqCallback($mod.vP,$mod.vQ);', + '$mod.b = rtl.eqCallback($mod.vP, $mod.DoIt);', + '$mod.b = rtl.eqCallback($mod.DoIt, $mod.vP);', + '$mod.b = $mod.vP != null;', + '$mod.b = null != $mod.vP;', + '$mod.b = !rtl.eqCallback($mod.vP,$mod.vQ);', + '$mod.b = !rtl.eqCallback($mod.vP, $mod.DoIt);', + '$mod.b = !rtl.eqCallback($mod.DoIt, $mod.vP);', + '$mod.b = $mod.vP != null;', ''])); end; @@ -9296,28 +9550,28 @@ begin 'this.vP = null;', 'this.vQ = null;' ]), - LinesToStr([ // this.$main - 'this.vP = null;', - 'this.vP = this.vP;', - 'this.vP = rtl.createCallback(this,"DoIt");', - 'this.vP(1);', - 'this.vP(1);', - 'this.vP(2);', - 'this.b = this.vP == null;', - 'this.b = null == this.vP;', - 'this.b = rtl.eqCallback(this.vP,this.vQ);', - 'this.b = rtl.eqCallback(this.vP, rtl.createCallback(this, "DoIt"));', - 'this.b = rtl.eqCallback(rtl.createCallback(this, "DoIt"), this.vP);', - 'this.b = 4 == this.vP(1);', - 'this.b = this.vP != null;', - 'this.b = null != this.vP;', - 'this.b = !rtl.eqCallback(this.vP,this.vQ);', - 'this.b = !rtl.eqCallback(this.vP, rtl.createCallback(this, "DoIt"));', - 'this.b = !rtl.eqCallback(rtl.createCallback(this, "DoIt"), this.vP);', - 'this.b = 6 != this.vP(1);', - 'this.b = this.vP != null;', - 'this.DoIt(this.vP(1));', - 'this.DoIt(this.vP(2));', + LinesToStr([ // $mod.$main + '$mod.vP = null;', + '$mod.vP = $mod.vP;', + '$mod.vP = $mod.DoIt;', + '$mod.vP(1);', + '$mod.vP(1);', + '$mod.vP(2);', + '$mod.b = $mod.vP == null;', + '$mod.b = null == $mod.vP;', + '$mod.b = rtl.eqCallback($mod.vP,$mod.vQ);', + '$mod.b = rtl.eqCallback($mod.vP, $mod.DoIt);', + '$mod.b = rtl.eqCallback($mod.DoIt, $mod.vP);', + '$mod.b = 4 == $mod.vP(1);', + '$mod.b = $mod.vP != null;', + '$mod.b = null != $mod.vP;', + '$mod.b = !rtl.eqCallback($mod.vP,$mod.vQ);', + '$mod.b = !rtl.eqCallback($mod.vP, $mod.DoIt);', + '$mod.b = !rtl.eqCallback($mod.DoIt, $mod.vP);', + '$mod.b = 6 != $mod.vP(1);', + '$mod.b = $mod.vP != null;', + '$mod.DoIt($mod.vP(1));', + '$mod.DoIt($mod.vP(2));', ''])); end; @@ -9369,24 +9623,24 @@ begin 'this.vP = null;', 'this.vQ = null;' ]), - LinesToStr([ // this.$main - 'this.vP = null;', - 'this.vP = this.vP;', - 'this.vP = rtl.createCallback(this,"DoIt");', - 'this.vP = rtl.createCallback(this,"DoIt");', - 'this.vP(1);', - 'this.vP(1);', - 'this.vP(2);', - 'this.b = this.vP(1) == this.vQ(1);', - 'this.b = this.vP(1) == 3;', - 'this.b = 4 == this.vP(1);', - 'this.b = this.vP(1) != this.vQ(1);', - 'this.b = this.vP(1) != 5;', - 'this.b = 6 != this.vP(1);', - 'this.b = this.vP != null;', - 'this.DoIt(this.vP(1));', - 'this.DoIt(this.vP(1));', - 'this.DoIt(this.vP(2));', + LinesToStr([ // $mod.$main + '$mod.vP = null;', + '$mod.vP = $mod.vP;', + '$mod.vP = $mod.DoIt;', + '$mod.vP = $mod.DoIt;', + '$mod.vP(1);', + '$mod.vP(1);', + '$mod.vP(2);', + '$mod.b = $mod.vP(1) == $mod.vQ(1);', + '$mod.b = $mod.vP(1) == 3;', + '$mod.b = 4 == $mod.vP(1);', + '$mod.b = $mod.vP(1) != $mod.vQ(1);', + '$mod.b = $mod.vP(1) != 5;', + '$mod.b = 6 != $mod.vP(1);', + '$mod.b = $mod.vP != null;', + '$mod.DoIt($mod.vP(1));', + '$mod.DoIt($mod.vP(1));', + '$mod.DoIt($mod.vP(2));', ''])); end; @@ -9417,7 +9671,7 @@ begin ' vG = vG;', ' vJ = vH;', ' vI.set(vI.get());', - ' this.DoIt(vG, vG, {', + ' $mod.DoIt(vG, vG, {', ' get: function () {', ' return vG;', ' },', @@ -9425,7 +9679,7 @@ begin ' vG = v;', ' }', ' });', - ' this.DoIt(vH, vH, {', + ' $mod.DoIt(vH, vH, {', ' get: function () {', ' return vJ;', ' },', @@ -9433,8 +9687,8 @@ begin ' vJ = v;', ' }', ' });', - ' this.DoIt(vI.get(), vI.get(), vI);', - ' this.DoIt(vJ, vJ, {', + ' $mod.DoIt(vI.get(), vI.get(), vI);', + ' $mod.DoIt(vJ, vJ, {', ' get: function () {', ' return vJ;', ' },', @@ -9446,8 +9700,8 @@ begin 'this.i = null;' ]), LinesToStr([ - 'this.DoIt(this.i,this.i,{', - ' p: this,', + '$mod.DoIt($mod.i,$mod.i,{', + ' p: $mod,', ' get: function () {', ' return this.p.i;', ' },', @@ -9486,7 +9740,7 @@ begin ConvertProgram; CheckSource('TestProcType_MethodFPC', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -9501,14 +9755,14 @@ begin 'this.b = false;' ]), LinesToStr([ - 'this.vP = rtl.createCallback(this.Obj, "DoIt");', - 'this.vP(1);', - 'this.vP(1);', - 'this.vP(2);', - 'this.b = rtl.eqCallback(this.vP, rtl.createCallback(this.Obj, "DoIt"));', - 'this.b = rtl.eqCallback(rtl.createCallback(this.Obj, "DoIt"), this.vP);', - 'this.b = !rtl.eqCallback(this.vP, rtl.createCallback(this.Obj, "DoIt"));', - 'this.b = !rtl.eqCallback(rtl.createCallback(this.Obj, "DoIt"), this.vP);', + '$mod.vP = rtl.createCallback($mod.Obj, "DoIt");', + '$mod.vP(1);', + '$mod.vP(1);', + '$mod.vP(2);', + '$mod.b = rtl.eqCallback($mod.vP, rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.b = rtl.eqCallback(rtl.createCallback($mod.Obj, "DoIt"), $mod.vP);', + '$mod.b = !rtl.eqCallback($mod.vP, rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.b = !rtl.eqCallback(rtl.createCallback($mod.Obj, "DoIt"), $mod.vP);', ''])); end; @@ -9541,7 +9795,7 @@ begin ConvertProgram; CheckSource('TestProcType_MethodDelphi', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -9556,11 +9810,11 @@ begin 'this.b = false;' ]), LinesToStr([ - 'this.vP = rtl.createCallback(this.Obj, "DoIt");', - 'this.vP = rtl.createCallback(this.Obj, "DoIt");', - 'this.vP(1);', - 'this.vP(1);', - 'this.vP(2);', + '$mod.vP = rtl.createCallback($mod.Obj, "DoIt");', + '$mod.vP = rtl.createCallback($mod.Obj, "DoIt");', + '$mod.vP(1);', + '$mod.vP(1);', + '$mod.vP(2);', ''])); end; @@ -9635,7 +9889,7 @@ begin ConvertProgram; CheckSource('TestProcType_PropertyFPC', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FOnFoo = null;', ' };', @@ -9664,44 +9918,44 @@ begin 'this.b = false;' ]), LinesToStr([ - 'this.Obj.FOnFoo = null;', - 'this.Obj.SetFoo(null);', - 'this.Obj.SetEvents(1, null);', - 'this.Obj.FOnFoo = this.Obj.FOnFoo;', - 'this.Obj.SetFoo(this.Obj.GetFoo());', - 'this.Obj.SetEvents(2, this.Obj.GetEvents(3));', - 'this.Obj.FOnFoo = rtl.createCallback(this.Obj, "DoIt");', - 'this.Obj.SetFoo(rtl.createCallback(this.Obj, "DoIt"));', - 'this.Obj.SetEvents(4, rtl.createCallback(this.Obj, "DoIt"));', - 'this.Obj.FOnFoo(1);', - 'this.Obj.GetFoo();', - 'this.Obj.FOnFoo(1);', - 'this.Obj.GetFoo()(1);', - 'this.Obj.GetEvents(6)(1);', - 'this.b = this.Obj.FOnFoo == null;', - 'this.b = this.Obj.GetFoo() == null;', - 'this.b = this.Obj.GetEvents(7) == null;', - 'this.b = this.Obj.FOnFoo != null;', - 'this.b = this.Obj.GetFoo() != null;', - 'this.b = this.Obj.GetEvents(8) != null;', - 'this.b = rtl.eqCallback(this.Obj.FOnFoo, this.vP);', - 'this.b = rtl.eqCallback(this.Obj.GetFoo(), this.vP);', - 'this.b = rtl.eqCallback(this.Obj.GetEvents(9), this.vP);', - 'this.b = rtl.eqCallback(this.Obj.FOnFoo, this.Obj.FOnFoo);', - 'this.b = rtl.eqCallback(this.Obj.GetFoo(), this.Obj.FOnFoo);', - 'this.b = rtl.eqCallback(this.Obj.GetEvents(10), this.Obj.FOnFoo);', - 'this.b = !rtl.eqCallback(this.Obj.FOnFoo, this.Obj.FOnFoo);', - 'this.b = !rtl.eqCallback(this.Obj.GetFoo(), this.Obj.FOnFoo);', - 'this.b = !rtl.eqCallback(this.Obj.GetEvents(11), this.Obj.FOnFoo);', - 'this.b = rtl.eqCallback(this.Obj.FOnFoo, rtl.createCallback(this.Obj, "DoIt"));', - 'this.b = rtl.eqCallback(this.Obj.GetFoo(), rtl.createCallback(this.Obj, "DoIt"));', - 'this.b = rtl.eqCallback(this.Obj.GetEvents(12), rtl.createCallback(this.Obj, "DoIt"));', - 'this.b = !rtl.eqCallback(this.Obj.FOnFoo, rtl.createCallback(this.Obj, "DoIt"));', - 'this.b = !rtl.eqCallback(this.Obj.GetFoo(), rtl.createCallback(this.Obj, "DoIt"));', - 'this.b = !rtl.eqCallback(this.Obj.GetEvents(12), rtl.createCallback(this.Obj, "DoIt"));', - 'this.b = this.Obj.FOnFoo != null;', - 'this.b = this.Obj.GetFoo() != null;', - 'this.b = this.Obj.GetEvents(13) != null;', + '$mod.Obj.FOnFoo = null;', + '$mod.Obj.SetFoo(null);', + '$mod.Obj.SetEvents(1, null);', + '$mod.Obj.FOnFoo = $mod.Obj.FOnFoo;', + '$mod.Obj.SetFoo($mod.Obj.GetFoo());', + '$mod.Obj.SetEvents(2, $mod.Obj.GetEvents(3));', + '$mod.Obj.FOnFoo = rtl.createCallback($mod.Obj, "DoIt");', + '$mod.Obj.SetFoo(rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.Obj.SetEvents(4, rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.Obj.FOnFoo(1);', + '$mod.Obj.GetFoo();', + '$mod.Obj.FOnFoo(1);', + '$mod.Obj.GetFoo()(1);', + '$mod.Obj.GetEvents(6)(1);', + '$mod.b = $mod.Obj.FOnFoo == null;', + '$mod.b = $mod.Obj.GetFoo() == null;', + '$mod.b = $mod.Obj.GetEvents(7) == null;', + '$mod.b = $mod.Obj.FOnFoo != null;', + '$mod.b = $mod.Obj.GetFoo() != null;', + '$mod.b = $mod.Obj.GetEvents(8) != null;', + '$mod.b = rtl.eqCallback($mod.Obj.FOnFoo, $mod.vP);', + '$mod.b = rtl.eqCallback($mod.Obj.GetFoo(), $mod.vP);', + '$mod.b = rtl.eqCallback($mod.Obj.GetEvents(9), $mod.vP);', + '$mod.b = rtl.eqCallback($mod.Obj.FOnFoo, $mod.Obj.FOnFoo);', + '$mod.b = rtl.eqCallback($mod.Obj.GetFoo(), $mod.Obj.FOnFoo);', + '$mod.b = rtl.eqCallback($mod.Obj.GetEvents(10), $mod.Obj.FOnFoo);', + '$mod.b = !rtl.eqCallback($mod.Obj.FOnFoo, $mod.Obj.FOnFoo);', + '$mod.b = !rtl.eqCallback($mod.Obj.GetFoo(), $mod.Obj.FOnFoo);', + '$mod.b = !rtl.eqCallback($mod.Obj.GetEvents(11), $mod.Obj.FOnFoo);', + '$mod.b = rtl.eqCallback($mod.Obj.FOnFoo, rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.b = rtl.eqCallback($mod.Obj.GetFoo(), rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.b = rtl.eqCallback($mod.Obj.GetEvents(12), rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.b = !rtl.eqCallback($mod.Obj.FOnFoo, rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.b = !rtl.eqCallback($mod.Obj.GetFoo(), rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.b = !rtl.eqCallback($mod.Obj.GetEvents(12), rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.b = $mod.Obj.FOnFoo != null;', + '$mod.b = $mod.Obj.GetFoo() != null;', + '$mod.b = $mod.Obj.GetEvents(13) != null;', ''])); end; @@ -9777,7 +10031,7 @@ begin ConvertProgram; CheckSource('TestProcType_PropertyDelphi', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FOnFoo = null;', ' };', @@ -9806,32 +10060,32 @@ begin 'this.b = false;' ]), LinesToStr([ - 'this.Obj.FOnFoo = null;', - 'this.Obj.SetFoo(null);', - 'this.Obj.SetEvents(1, null);', - 'this.Obj.FOnFoo = this.Obj.FOnFoo;', - 'this.Obj.SetFoo(this.Obj.GetFoo());', - 'this.Obj.SetEvents(2, this.Obj.GetEvents(3));', - 'this.Obj.FOnFoo = rtl.createCallback(this.Obj, "DoIt");', - 'this.Obj.SetFoo(rtl.createCallback(this.Obj, "DoIt"));', - 'this.Obj.SetEvents(4, rtl.createCallback(this.Obj, "DoIt"));', - 'this.Obj.FOnFoo = rtl.createCallback(this.Obj, "DoIt");', - 'this.Obj.SetFoo(rtl.createCallback(this.Obj, "DoIt"));', - 'this.Obj.SetEvents(4, rtl.createCallback(this.Obj, "DoIt"));', - 'this.Obj.FOnFoo(1);', - 'this.Obj.GetFoo();', - 'this.Obj.FOnFoo(1);', - 'this.Obj.GetFoo()(1);', - 'this.Obj.GetEvents(6)(1);', - 'this.b = this.Obj.FOnFoo(1) == this.vP(1);', - 'this.b = this.Obj.GetFoo() == this.vP(1);', - 'this.b = this.Obj.FOnFoo(1) == this.Obj.FOnFoo(1);', - 'this.b = this.Obj.GetFoo() == this.Obj.FOnFoo(1);', - 'this.b = this.Obj.FOnFoo(1) != this.Obj.FOnFoo(1);', - 'this.b = this.Obj.GetFoo() != this.Obj.FOnFoo(1);', - 'this.b = this.Obj.FOnFoo != null;', - 'this.b = this.Obj.GetFoo() != null;', - 'this.b = this.Obj.GetEvents(13) != null;', + '$mod.Obj.FOnFoo = null;', + '$mod.Obj.SetFoo(null);', + '$mod.Obj.SetEvents(1, null);', + '$mod.Obj.FOnFoo = $mod.Obj.FOnFoo;', + '$mod.Obj.SetFoo($mod.Obj.GetFoo());', + '$mod.Obj.SetEvents(2, $mod.Obj.GetEvents(3));', + '$mod.Obj.FOnFoo = rtl.createCallback($mod.Obj, "DoIt");', + '$mod.Obj.SetFoo(rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.Obj.SetEvents(4, rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.Obj.FOnFoo = rtl.createCallback($mod.Obj, "DoIt");', + '$mod.Obj.SetFoo(rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.Obj.SetEvents(4, rtl.createCallback($mod.Obj, "DoIt"));', + '$mod.Obj.FOnFoo(1);', + '$mod.Obj.GetFoo();', + '$mod.Obj.FOnFoo(1);', + '$mod.Obj.GetFoo()(1);', + '$mod.Obj.GetEvents(6)(1);', + '$mod.b = $mod.Obj.FOnFoo(1) == $mod.vP(1);', + '$mod.b = $mod.Obj.GetFoo() == $mod.vP(1);', + '$mod.b = $mod.Obj.FOnFoo(1) == $mod.Obj.FOnFoo(1);', + '$mod.b = $mod.Obj.GetFoo() == $mod.Obj.FOnFoo(1);', + '$mod.b = $mod.Obj.FOnFoo(1) != $mod.Obj.FOnFoo(1);', + '$mod.b = $mod.Obj.GetFoo() != $mod.Obj.FOnFoo(1);', + '$mod.b = $mod.Obj.FOnFoo != null;', + '$mod.b = $mod.Obj.GetFoo() != null;', + '$mod.b = $mod.Obj.GetEvents(13) != null;', ''])); end; @@ -9903,7 +10157,7 @@ begin ConvertProgram; CheckSource('TestProcType_WithClassInstDoPropertyFPC', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FOnFoo = null;', ' };', @@ -9926,7 +10180,7 @@ begin 'this.b = false;' ]), LinesToStr([ - 'var $with1 = this.Obj;', + 'var $with1 = $mod.Obj;', '$with1.FOnFoo = null;', '$with1.FOnFoo = null;', '$with1.SetFoo(null);', @@ -9942,64 +10196,66 @@ begin '$with1.FOnFoo(1);', '$with1.FOnFoo(1);', '$with1.GetFoo()(1);', - 'this.b = $with1.FOnFoo == null;', - 'this.b = $with1.FOnFoo == null;', - 'this.b = $with1.GetFoo() == null;', - 'this.b = $with1.FOnFoo != null;', - 'this.b = $with1.FOnFoo != null;', - 'this.b = $with1.GetFoo() != null;', - 'this.b = rtl.eqCallback($with1.FOnFoo, this.vP);', - 'this.b = rtl.eqCallback($with1.FOnFoo, this.vP);', - 'this.b = rtl.eqCallback($with1.GetFoo(), this.vP);', - 'this.b = rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);', - 'this.b = rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);', - 'this.b = rtl.eqCallback($with1.GetFoo(), $with1.FOnFoo);', - 'this.b = !rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);', - 'this.b = !rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);', - 'this.b = !rtl.eqCallback($with1.GetFoo(), $with1.FOnFoo);', - 'this.b = rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));', - 'this.b = rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));', - 'this.b = rtl.eqCallback($with1.GetFoo(), rtl.createCallback($with1, "DoIt"));', - 'this.b = !rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));', - 'this.b = !rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));', - 'this.b = !rtl.eqCallback($with1.GetFoo(), rtl.createCallback($with1, "DoIt"));', - 'this.b = $with1.FOnFoo != null;', - 'this.b = $with1.FOnFoo != null;', - 'this.b = $with1.GetFoo() != null;', + '$mod.b = $with1.FOnFoo == null;', + '$mod.b = $with1.FOnFoo == null;', + '$mod.b = $with1.GetFoo() == null;', + '$mod.b = $with1.FOnFoo != null;', + '$mod.b = $with1.FOnFoo != null;', + '$mod.b = $with1.GetFoo() != null;', + '$mod.b = rtl.eqCallback($with1.FOnFoo, $mod.vP);', + '$mod.b = rtl.eqCallback($with1.FOnFoo, $mod.vP);', + '$mod.b = rtl.eqCallback($with1.GetFoo(), $mod.vP);', + '$mod.b = rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);', + '$mod.b = rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);', + '$mod.b = rtl.eqCallback($with1.GetFoo(), $with1.FOnFoo);', + '$mod.b = !rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);', + '$mod.b = !rtl.eqCallback($with1.FOnFoo, $with1.FOnFoo);', + '$mod.b = !rtl.eqCallback($with1.GetFoo(), $with1.FOnFoo);', + '$mod.b = rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));', + '$mod.b = rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));', + '$mod.b = rtl.eqCallback($with1.GetFoo(), rtl.createCallback($with1, "DoIt"));', + '$mod.b = !rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));', + '$mod.b = !rtl.eqCallback($with1.FOnFoo, rtl.createCallback($with1, "DoIt"));', + '$mod.b = !rtl.eqCallback($with1.GetFoo(), rtl.createCallback($with1, "DoIt"));', + '$mod.b = $with1.FOnFoo != null;', + '$mod.b = $with1.FOnFoo != null;', + '$mod.b = $with1.GetFoo() != null;', ''])); end; procedure TTestModule.TestProcType_Nested; begin StartProgram(false); - Add('type'); - Add(' TProcInt = procedure(vI: longint = 1);'); - Add('procedure DoIt(vJ: longint);'); - Add('var aProc: TProcInt;'); - Add(' b: boolean;'); - Add(' procedure Sub(vK: longint);'); - Add(' var aSub: TProcInt;'); - Add(' procedure SubSub(vK: longint);'); - Add(' var aSubSub: TProcInt;'); - Add(' begin;'); - Add(' aProc:=@DoIt;'); - Add(' aSub:=@DoIt;'); - Add(' aSubSub:=@DoIt;'); - Add(' aProc:=@Sub;'); - Add(' aSub:=@Sub;'); - Add(' aSubSub:=@Sub;'); - Add(' aProc:=@SubSub;'); - Add(' aSub:=@SubSub;'); - Add(' aSubSub:=@SubSub;'); - Add(' end;'); - Add(' begin;'); - Add(' end;'); - Add('begin;'); - Add(' aProc:=@Sub;'); - Add(' b:=aProc=@Sub;'); - Add(' b:=@Sub=aProc;'); - Add('end;'); - Add('begin'); + Add([ + 'type', + ' TProcInt = procedure(vI: longint = 1);', + 'procedure DoIt(vJ: longint);', + 'var aProc: TProcInt;', + ' b: boolean;', + ' procedure Sub(vK: longint);', + ' var aSub: TProcInt;', + ' procedure SubSub(vK: longint);', + ' var aSubSub: TProcInt;', + ' begin;', + ' aProc:=@DoIt;', + ' aSub:=@DoIt;', + ' aSubSub:=@DoIt;', + ' aProc:=@Sub;', + ' aSub:=@Sub;', + ' aSubSub:=@Sub;', + ' aProc:=@SubSub;', + ' aSub:=@SubSub;', + ' aSubSub:=@SubSub;', + ' end;', + ' begin;', + ' end;', + 'begin;', + ' aProc:=@Sub;', + ' b:=aProc=@Sub;', + ' b:=@Sub=aProc;', + 'end;', + 'begin', + '']); ConvertProgram; CheckSource('TestProcType_Nested', LinesToStr([ // statements @@ -10010,23 +10266,96 @@ begin ' var aSub = null;', ' function SubSub(vK) {', ' var aSubSub = null;', - ' aProc = rtl.createCallback(this, "DoIt");', - ' aSub = rtl.createCallback(this, "DoIt");', - ' aSubSub = rtl.createCallback(this, "DoIt");', - ' aProc = rtl.createCallback(this, Sub);', - ' aSub = rtl.createCallback(this, Sub);', - ' aSubSub = rtl.createCallback(this, Sub);', - ' aProc = rtl.createCallback(this, SubSub);', - ' aSub = rtl.createCallback(this, SubSub);', - ' aSubSub = rtl.createCallback(this, SubSub);', + ' aProc = $mod.DoIt;', + ' aSub = $mod.DoIt;', + ' aSubSub = $mod.DoIt;', + ' aProc = Sub;', + ' aSub = Sub;', + ' aSubSub = Sub;', + ' aProc = SubSub;', + ' aSub = SubSub;', + ' aSubSub = SubSub;', ' };', ' };', - ' aProc = rtl.createCallback(this, Sub);', - ' b = rtl.eqCallback(aProc, rtl.createCallback(this, Sub));', - ' b = rtl.eqCallback(rtl.createCallback(this, Sub), aProc);', + ' aProc = Sub;', + ' b = rtl.eqCallback(aProc, Sub);', + ' b = rtl.eqCallback(Sub, aProc);', '};', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main + ''])); +end; + +procedure TTestModule.TestProcType_NestedOfObject; +begin + StartProgram(false); + Add([ + 'type', + ' TProcInt = procedure(vI: longint = 1) of object;', + ' TObject = class', + ' procedure DoIt(vJ: longint);', + ' end;', + 'procedure TObject.DoIt(vJ: longint);', + 'var aProc: TProcInt;', + ' b: boolean;', + ' procedure Sub(vK: longint);', + ' var aSub: TProcInt;', + ' procedure SubSub(vK: longint);', + ' var aSubSub: TProcInt;', + ' begin;', + ' aProc:=@DoIt;', + ' aSub:=@DoIt;', + ' aSubSub:=@DoIt;', + ' aProc:=@Sub;', + ' aSub:=@Sub;', + ' aSubSub:=@Sub;', + ' aProc:=@SubSub;', + ' aSub:=@SubSub;', + ' aSubSub:=@SubSub;', + ' end;', + ' begin;', + ' end;', + 'begin;', + ' aProc:=@Sub;', + ' b:=aProc=@Sub;', + ' b:=@Sub=aProc;', + 'end;', + 'begin', + '']); + ConvertProgram; + CheckSource('TestProcType_Nested', + LinesToStr([ // statements + 'rtl.createClass($mod, "TObject", null, function () {', + ' this.$init = function () {', + ' };', + ' this.$final = function () {', + ' };', + ' this.DoIt = function (vJ) {', + ' var Self = this;', + ' var aProc = null;', + ' var b = false;', + ' function Sub(vK) {', + ' var aSub = null;', + ' function SubSub(vK) {', + ' var aSubSub = null;', + ' aProc = rtl.createCallback(Self, "DoIt");', + ' aSub = rtl.createCallback(Self, "DoIt");', + ' aSubSub = rtl.createCallback(Self, "DoIt");', + ' aProc = Sub;', + ' aSub = Sub;', + ' aSubSub = Sub;', + ' aProc = SubSub;', + ' aSub = SubSub;', + ' aSubSub = SubSub;', + ' };', + ' };', + ' aProc = Sub;', + ' b = rtl.eqCallback(aProc, Sub);', + ' b = rtl.eqCallback(Sub, aProc);', + ' };', + '});', + '']), + LinesToStr([ // $mod.$main ''])); end; @@ -10068,21 +10397,21 @@ begin 'this.FuncB = null;', 'this.p = null;', '']), - LinesToStr([ // this.$main - 'this.Notify = this.Event;', - 'this.Event = this.Event;', - 'this.Event = this.Notify;', - 'this.ProcA = this.FuncB;', - 'this.FuncB = this.FuncB;', - 'this.FuncB = this.ProcA;', - 'this.ProcA = this.p;', - 'this.FuncB = this.p;', - 'this.p = this.Notify;', - 'this.p = this.Notify;', - 'this.p = this.ProcA;', - 'this.p = this.ProcA;', - 'this.p = this.FuncB;', - 'this.p = this.FuncB;', + LinesToStr([ // $mod.$main + '$mod.Notify = $mod.Event;', + '$mod.Event = $mod.Event;', + '$mod.Event = $mod.Notify;', + '$mod.ProcA = $mod.FuncB;', + '$mod.FuncB = $mod.FuncB;', + '$mod.FuncB = $mod.ProcA;', + '$mod.ProcA = $mod.p;', + '$mod.FuncB = $mod.p;', + '$mod.p = $mod.Notify;', + '$mod.p = $mod.Notify;', + '$mod.p = $mod.ProcA;', + '$mod.p = $mod.ProcA;', + '$mod.p = $mod.FuncB;', + '$mod.p = $mod.FuncB;', ''])); end; @@ -10116,7 +10445,7 @@ begin ConvertProgram; CheckSource('TestPointer', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -10128,20 +10457,20 @@ begin 'this.a = [];', 'this.p = null;', '']), - LinesToStr([ // this.$main - 'this.p = this.p;', - 'this.p = null;', - 'if (this.p == null) ;', - 'if (null == this.p) ;', - 'if (this.p != null) ;', - 'this.p = this.v;', - 'this.p = this.Obj;', - 'this.p = this.C;', - 'this.p = this.a;', - 'this.p = this.TObject;', - 'this.Obj = this.p;', - 'this.C = this.p;', - 'this.a = this.p;', + LinesToStr([ // $mod.$main + '$mod.p = $mod.p;', + '$mod.p = null;', + 'if ($mod.p == null) ;', + 'if (null == $mod.p) ;', + 'if ($mod.p != null) ;', + '$mod.p = $mod.v;', + '$mod.p = $mod.Obj;', + '$mod.p = $mod.C;', + '$mod.p = $mod.a;', + '$mod.p = $mod.TObject;', + '$mod.Obj = $mod.p;', + '$mod.C = $mod.p;', + '$mod.a = $mod.p;', ''])); end; @@ -10162,7 +10491,7 @@ begin ConvertProgram; CheckSource('TestPointer_Proc', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -10173,9 +10502,9 @@ begin 'this.o = null;', 'this.p = null;', '']), - LinesToStr([ // this.$main - 'this.p = rtl.createCallback(this, "DoSome");', - 'this.p = rtl.createCallback(this.o, "DoIt");', + LinesToStr([ // $mod.$main + '$mod.p = $mod.DoSome;', + '$mod.p = rtl.createCallback($mod.o, "DoIt");', ''])); end; @@ -10255,21 +10584,21 @@ begin 'this.d = 0.0;', 'this.p = null;', '']), - LinesToStr([ // this.$main - 'this.v = this.v;', - 'this.v = 1;', - 'this.v = this.i;', - 'this.v = "";', - 'this.v = "c";', - 'this.v = "foo";', - 'this.v = this.s;', - 'this.v = false;', - 'this.v = true;', - 'this.v = this.b;', - 'this.v = 0.1;', - 'this.v = this.d;', - 'this.v = null;', - 'this.v = this.p;', + LinesToStr([ // $mod.$main + '$mod.v = $mod.v;', + '$mod.v = 1;', + '$mod.v = $mod.i;', + '$mod.v = "";', + '$mod.v = "c";', + '$mod.v = "foo";', + '$mod.v = $mod.s;', + '$mod.v = false;', + '$mod.v = true;', + '$mod.v = $mod.b;', + '$mod.v = 0.1;', + '$mod.v = $mod.d;', + '$mod.v = null;', + '$mod.v = $mod.p;', ''])); end; @@ -10310,17 +10639,17 @@ begin 'this.d = 0.0;', 'this.c = "";', '']), - LinesToStr([ // this.$main - 'this.i = Math.floor(this.v);', - 'this.i = Math.floor(this.v);', - 'this.s = "" + this.v;', - 'this.s = "" + this.v;', - 'this.b = !(this.v == false);', - 'this.b = !(this.v == false);', - 'this.d = rtl.getNumber(this.v);', - 'this.d = rtl.getNumber(this.v);', - 'this.c = rtl.getChar(this.v);', - 'this.c = rtl.getChar(this.v);', + LinesToStr([ // $mod.$main + '$mod.i = Math.floor($mod.v);', + '$mod.i = Math.floor($mod.v);', + '$mod.s = "" + $mod.v;', + '$mod.s = "" + $mod.v;', + '$mod.b = !($mod.v == false);', + '$mod.b = !($mod.v == false);', + '$mod.d = rtl.getNumber($mod.v);', + '$mod.d = rtl.getNumber($mod.v);', + '$mod.c = rtl.getChar($mod.v);', + '$mod.c = rtl.getChar($mod.v);', ''])); end; @@ -10381,34 +10710,34 @@ begin 'this.c = "";', 'this.m = undefined;', '']), - LinesToStr([ // this.$main - 'this.b = this.v == this.v;', - 'this.b = this.v != this.v;', - 'this.b = this.v == 1;', - 'this.b = this.v != 1;', - 'this.b = 2 == this.v;', - 'this.b = 2 != this.v;', - 'this.b = this.v == this.i;', - 'this.b = this.i == this.v;', - 'this.b = this.v == null;', - 'this.b = null == this.v;', - 'this.b = this.v == false;', - 'this.b = true == this.v;', - 'this.b = this.v == this.b;', - 'this.b = this.b == this.v;', - 'this.b = this.v == this.s;', - 'this.b = this.s == this.v;', - 'this.b = this.v == "foo";', - 'this.b = "" == this.v;', - 'this.b = this.v == this.d;', - 'this.b = this.d == this.v;', - 'this.b = this.v == 3.4;', - 'this.b = 5.6 == this.v;', - 'this.b = this.v == this.c;', - 'this.b = this.c == this.v;', - 'this.b = this.m == this.m;', - 'this.b = this.v == this.m;', - 'this.b = this.m == this.v;', + LinesToStr([ // $mod.$main + '$mod.b = $mod.v == $mod.v;', + '$mod.b = $mod.v != $mod.v;', + '$mod.b = $mod.v == 1;', + '$mod.b = $mod.v != 1;', + '$mod.b = 2 == $mod.v;', + '$mod.b = 2 != $mod.v;', + '$mod.b = $mod.v == $mod.i;', + '$mod.b = $mod.i == $mod.v;', + '$mod.b = $mod.v == null;', + '$mod.b = null == $mod.v;', + '$mod.b = $mod.v == false;', + '$mod.b = true == $mod.v;', + '$mod.b = $mod.v == $mod.b;', + '$mod.b = $mod.b == $mod.v;', + '$mod.b = $mod.v == $mod.s;', + '$mod.b = $mod.s == $mod.v;', + '$mod.b = $mod.v == "foo";', + '$mod.b = "" == $mod.v;', + '$mod.b = $mod.v == $mod.d;', + '$mod.b = $mod.d == $mod.v;', + '$mod.b = $mod.v == 3.4;', + '$mod.b = 5.6 == $mod.v;', + '$mod.b = $mod.v == $mod.c;', + '$mod.b = $mod.c == $mod.v;', + '$mod.b = $mod.m == $mod.m;', + '$mod.b = $mod.v == $mod.m;', + '$mod.b = $mod.m == $mod.v;', ''])); end; @@ -10439,12 +10768,12 @@ begin 'this.v = undefined;', 'this.e = 0;', '']), - LinesToStr([ // this.$main - 'this.v = this.e;', - 'this.v = this.e;', - 'this.v = this.e;', - 'this.e = this.v;', - 'this.e = this.v;', + LinesToStr([ // $mod.$main + '$mod.v = $mod.e;', + '$mod.v = $mod.e;', + '$mod.v = $mod.e;', + '$mod.e = $mod.v;', + '$mod.e = $mod.v;', ''])); end; @@ -10467,7 +10796,7 @@ begin ConvertProgram; CheckSource('TestJSValue_ClassInstance', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -10476,12 +10805,12 @@ begin 'this.v = undefined;', 'this.o = null;', '']), - LinesToStr([ // this.$main - 'this.v = this.o;', - 'this.v = this.o;', - 'this.v = this.o;', - 'this.o = rtl.getObject(this.v);', - 'this.o = rtl.getObject(this.v);', + LinesToStr([ // $mod.$main + '$mod.v = $mod.o;', + '$mod.v = $mod.o;', + '$mod.v = $mod.o;', + '$mod.o = rtl.getObject($mod.v);', + '$mod.o = rtl.getObject($mod.v);', ''])); end; @@ -10507,24 +10836,24 @@ begin ConvertProgram; CheckSource('TestJSValue_ClassOf', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', ' };', '});', - 'rtl.createClass(this, "TBird", this.TObject, function () {', + 'rtl.createClass($mod, "TBird", $mod.TObject, function () {', '});', 'this.v = undefined;', 'this.c = null;', '']), - LinesToStr([ // this.$main - 'this.v = this.c;', - 'this.v = this.TObject;', - 'this.v = this.c;', - 'this.v = this.c;', - 'this.c = rtl.getObject(this.v);', - 'this.c = rtl.getObject(this.v);', + LinesToStr([ // $mod.$main + '$mod.v = $mod.c;', + '$mod.v = $mod.TObject;', + '$mod.v = $mod.c;', + '$mod.v = $mod.c;', + '$mod.c = rtl.getObject($mod.v);', + '$mod.c = rtl.getObject($mod.v);', ''])); end; @@ -10567,22 +10896,22 @@ begin 'this.i = 0;', 'this.ArrInt = [];', '']), - LinesToStr([ // this.$main - 'this.Arr = this.TheArray;', - 'this.TheArray = this.Arr;', - 'this.Arr = rtl.arraySetLength(this.Arr,2,undefined);', - 'this.TheArray = rtl.arraySetLength(this.TheArray,3,undefined);', - 'this.Arr[4] = this.v;', - 'this.Arr[5] = rtl.length(this.TheArray);', - 'this.Arr[6] = null;', - 'this.Arr[7] = this.TheArray[8];', - 'this.Arr[0] = rtl.length(this.TheArray) - 1;', - 'this.Arr = this.ArrInt;', - 'this.ArrInt = this.Arr;', - 'if (rtl.length(this.TheArray) == 0) ;', - 'if (rtl.length(this.TheArray) == 0) ;', - 'if (rtl.length(this.TheArray) > 0) ;', - 'if (rtl.length(this.TheArray) > 0) ;', + LinesToStr([ // $mod.$main + '$mod.Arr = $mod.TheArray;', + '$mod.TheArray = $mod.Arr;', + '$mod.Arr = rtl.arraySetLength($mod.Arr,2,undefined);', + '$mod.TheArray = rtl.arraySetLength($mod.TheArray,3,undefined);', + '$mod.Arr[4] = $mod.v;', + '$mod.Arr[5] = rtl.length($mod.TheArray);', + '$mod.Arr[6] = null;', + '$mod.Arr[7] = $mod.TheArray[8];', + '$mod.Arr[0] = rtl.length($mod.TheArray) - 1;', + '$mod.Arr = $mod.ArrInt;', + '$mod.ArrInt = $mod.Arr;', + 'if (rtl.length($mod.TheArray) == 0) ;', + 'if (rtl.length($mod.TheArray) == 0) ;', + 'if (rtl.length($mod.TheArray) > 0) ;', + 'if (rtl.length($mod.TheArray) > 0) ;', ''])); end; @@ -10644,9 +10973,9 @@ begin 'this.s = "";', 'this.c = "";', '']), - LinesToStr([ // this.$main - 'this.v = this.DoIt(this.v, this.v, {', - ' p: this,', + LinesToStr([ // $mod.$main + '$mod.v = $mod.DoIt($mod.v, $mod.v, {', + ' p: $mod,', ' get: function () {', ' return this.p.v;', ' },', @@ -10654,7 +10983,7 @@ begin ' this.p.v = v;', ' }', '}, {', - ' p: this,', + ' p: $mod,', ' get: function () {', ' return this.p.v;', ' },', @@ -10662,11 +10991,11 @@ begin ' this.p.v = v;', ' }', '});', - 'this.i = Math.floor(this.DoSome(this.i, this.i));', - 'this.b = !(this.DoSome(this.b, this.b) == false);', - 'this.d = rtl.getNumber(this.DoSome(this.d, this.d));', - 'this.s = "" + this.DoSome(this.s, this.s);', - 'this.c = rtl.getChar(this.DoSome(this.c, this.c));', + '$mod.i = Math.floor($mod.DoSome($mod.i, $mod.i));', + '$mod.b = !($mod.DoSome($mod.b, $mod.b) == false);', + '$mod.d = rtl.getNumber($mod.DoSome($mod.d, $mod.d));', + '$mod.s = "" + $mod.DoSome($mod.s, $mod.s);', + '$mod.c = rtl.getChar($mod.DoSome($mod.c, $mod.c));', ''])); end; @@ -10698,9 +11027,9 @@ begin '};', 'this.i = 0;', '']), - LinesToStr([ // this.$main - 'this.DoIt(this.i, {', - ' p: this,', + LinesToStr([ // $mod.$main + '$mod.DoIt($mod.i, {', + ' p: $mod,', ' get: function () {', ' return this.p.i;', ' },', @@ -10708,7 +11037,7 @@ begin ' this.p.i = v;', ' }', '}, {', - ' p: this,', + ' p: $mod,', ' get: function () {', ' return this.p.i;', ' },', @@ -10750,11 +11079,11 @@ begin 'this.V = undefined;', 'this.i = 0;', '']), - LinesToStr([ // this.$main - 'if (this.Compare(this.V, this.V) > 0) ;', - 'if (this.Compare(this.i, this.i) > 1) ;', - 'if (this.Compare(null, false) > 2) ;', - 'if (this.Compare(1, true) > 3) ;', + LinesToStr([ // $mod.$main + 'if ($mod.Compare($mod.V, $mod.V) > 0) ;', + 'if ($mod.Compare($mod.i, $mod.i) > 1) ;', + 'if ($mod.Compare(null, false) > 2) ;', + 'if ($mod.Compare(1, true) > 3) ;', ''])); end; @@ -10796,7 +11125,7 @@ begin ConvertProgram; CheckSource('TestJSValue_ProcType_Assign', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -10821,16 +11150,16 @@ begin 'this.GetIt = function (i) {', ' var Result = 0;', ' var v3 = undefined;', - ' v3 = rtl.createCallback(this, "GetIt");', + ' v3 = $mod.GetIt;', ' return Result;', '};', 'this.V = undefined;', 'this.o = null;', '']), - LinesToStr([ // this.$main - 'this.V = rtl.createCallback(this, "GetIt");', - 'this.V = rtl.createCallback(this.o, "Getter");', - 'this.V = rtl.createCallback(this.o.$class, "GetGlob");', + LinesToStr([ // $mod.$main + '$mod.V = $mod.GetIt;', + '$mod.V = rtl.createCallback($mod.o, "Getter");', + '$mod.V = rtl.createCallback($mod.o.$class, "GetGlob");', ''])); end; @@ -10875,7 +11204,7 @@ begin ConvertProgram; CheckSource('TestJSValue_ProcType_Equal', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -10900,19 +11229,19 @@ begin 'this.GetIt = function (i) {', ' var Result = 0;', ' var v3 = undefined;', - ' if (rtl.eqCallback(v3, rtl.createCallback(this, "GetIt"))) ;', + ' if (rtl.eqCallback(v3, $mod.GetIt)) ;', ' return Result;', '};', 'this.V = undefined;', 'this.o = null;', '']), - LinesToStr([ // this.$main - 'if (rtl.eqCallback(this.V, rtl.createCallback(this, "GetIt"))) ;', - 'if (rtl.eqCallback(this.V, rtl.createCallback(this.o, "Getter"))) ;', - 'if (rtl.eqCallback(this.V, rtl.createCallback(this.o.$class, "GetGlob"))) ;', - 'if (rtl.eqCallback(rtl.createCallback(this, "GetIt"), this.V)) ;', - 'if (rtl.eqCallback(rtl.createCallback(this.o, "Getter"), this.V)) ;', - 'if (rtl.eqCallback(rtl.createCallback(this.o.$class, "GetGlob"), this.V)) ;', + LinesToStr([ // $mod.$main + 'if (rtl.eqCallback($mod.V, $mod.GetIt)) ;', + 'if (rtl.eqCallback($mod.V, rtl.createCallback($mod.o, "Getter"))) ;', + 'if (rtl.eqCallback($mod.V, rtl.createCallback($mod.o.$class, "GetGlob"))) ;', + 'if (rtl.eqCallback($mod.GetIt, $mod.V)) ;', + 'if (rtl.eqCallback(rtl.createCallback($mod.o, "Getter"), $mod.V)) ;', + 'if (rtl.eqCallback(rtl.createCallback($mod.o.$class, "GetGlob"), $mod.V)) ;', ''])); end; @@ -10933,29 +11262,29 @@ begin ConvertProgram; CheckSource('TestRTTI_ProcType', LinesToStr([ // statements - 'this.$rtti.$ProcVar("TProcA", {', + '$mod.$rtti.$ProcVar("TProcA", {', ' procsig: rtl.newTIProcSig(null)', '});', - 'this.$rtti.$MethodVar("TMethodB", {', + '$mod.$rtti.$MethodVar("TMethodB", {', ' procsig: rtl.newTIProcSig(null),', ' methodkind: 0', '});', - 'this.$rtti.$ProcVar("TProcC", {', + '$mod.$rtti.$ProcVar("TProcC", {', ' procsig: rtl.newTIProcSig(null, 2)', '});', - 'this.$rtti.$ProcVar("TProcD", {', + '$mod.$rtti.$ProcVar("TProcD", {', ' procsig: rtl.newTIProcSig([["i", rtl.longint], ["j", rtl.string, 2], ["c", rtl.char, 1], ["d", rtl.double, 4]])', '});', - 'this.$rtti.$ProcVar("TProcE", {', + '$mod.$rtti.$ProcVar("TProcE", {', ' procsig: rtl.newTIProcSig(null, rtl.longint)', '});', - 'this.$rtti.$ProcVar("TProcF", {', - ' procsig: rtl.newTIProcSig([["p", this.$rtti["TProcA"], 2]], rtl.longint)', + '$mod.$rtti.$ProcVar("TProcF", {', + ' procsig: rtl.newTIProcSig([["p", $mod.$rtti["TProcA"], 2]], rtl.longint)', '});', 'this.p = null;', '']), - LinesToStr([ // this.$main - 'this.p = this.$rtti["TProcA"];', + LinesToStr([ // $mod.$main + '$mod.p = $mod.$rtti["TProcA"];', ''])); end; @@ -10984,17 +11313,17 @@ begin ConvertUnit; CheckSource('TestRTTI_ProcType_ArgFromOtherUnit', LinesToStr([ // statements - 'var $impl = this.$impl;', - 'this.$rtti.$ProcVar("TProcA", {', + 'var $impl = $mod.$impl;', + '$mod.$rtti.$ProcVar("TProcA", {', ' procsig: rtl.newTIProcSig([["o", pas.unit2.$rtti["TObject"]]], pas.unit2.$rtti["TObject"])', '});', '']), LinesToStr([ // this.$init - '$impl.p = this.$rtti["TProcA"];', - '$impl.p = this.$rtti["TProcB"];', + '$impl.p = $mod.$rtti["TProcA"];', + '$impl.p = $mod.$rtti["TProcB"];', '']), LinesToStr([ // implementation - 'this.$rtti.$ProcVar("TProcB", {', + '$mod.$rtti.$ProcVar("TProcB", {', ' procsig: rtl.newTIProcSig([["o", pas.unit2.$rtti["TObject"]]], pas.unit2.$rtti["TObject"])', '});', '$impl.p = null;', @@ -11022,22 +11351,22 @@ begin ' "1": "dark",', ' dark: 1', '};', - 'this.$rtti.$Enum("TFlag", {', + '$mod.$rtti.$Enum("TFlag", {', ' minvalue: 0,', ' maxvalue: 1,', ' enumtype: this.TFlag', '});', - 'this.$rtti.$Set("TFlags", {', - ' comptype: this.$rtti["TFlag"]', + '$mod.$rtti.$Set("TFlags", {', + ' comptype: $mod.$rtti["TFlag"]', '});', - 'this.$rtti.$ProcVar("TProc", {', - ' procsig: rtl.newTIProcSig([["f", this.$rtti["TFlags"]]], this.$rtti["TFlag"])', + '$mod.$rtti.$ProcVar("TProc", {', + ' procsig: rtl.newTIProcSig([["f", $mod.$rtti["TFlags"]]], $mod.$rtti["TFlag"])', '});', 'this.p = null;', '']), - LinesToStr([ // this.$main - 'this.p = this.$rtti["TFlag"];', - 'this.p = this.$rtti["TFlags"];', + LinesToStr([ // $mod.$main + '$mod.p = $mod.$rtti["TFlag"];', + '$mod.p = $mod.$rtti["TFlags"];', ''])); end; @@ -11060,18 +11389,18 @@ begin ' "1": "green",', ' green: 1', '};', - 'this.$rtti.$Enum("TFlags$a", {', + '$mod.$rtti.$Enum("TFlags$a", {', ' minvalue: 0,', ' maxvalue: 1,', ' enumtype: this.TFlags$a', '});', - 'this.$rtti.$Set("TFlags", {', - ' comptype: this.$rtti["TFlags$a"]', + '$mod.$rtti.$Set("TFlags", {', + ' comptype: $mod.$rtti["TFlags$a"]', '});', 'this.f = {};', '']), LinesToStr([ - 'this.f = rtl.includeSet(this.f, this.TFlags$a.red);', + '$mod.f = rtl.includeSet($mod.f, $mod.TFlags$a.red);', ''])); end; @@ -11097,27 +11426,27 @@ begin ' "1": "dark",', ' dark: 1', '};', - 'this.$rtti.$Enum("TFlag", {', + '$mod.$rtti.$Enum("TFlag", {', ' minvalue: 0,', ' maxvalue: 1,', ' enumtype: this.TFlag', '});', - 'this.$rtti.$StaticArray("TFlagNames", {', + '$mod.$rtti.$StaticArray("TFlagNames", {', ' dims: [2],', ' eltype: rtl.string', '});', - 'this.$rtti.$StaticArray("TBoolNames", {', + '$mod.$rtti.$StaticArray("TBoolNames", {', ' dims: [2],', ' eltype: rtl.string', '});', - 'this.$rtti.$ProcVar("TProc", {', - ' procsig: rtl.newTIProcSig([["f", this.$rtti["TBoolNames"]]], this.$rtti["TFlagNames"])', + '$mod.$rtti.$ProcVar("TProc", {', + ' procsig: rtl.newTIProcSig([["f", $mod.$rtti["TBoolNames"]]], $mod.$rtti["TFlagNames"])', '});', 'this.p = null;', '']), - LinesToStr([ // this.$main - 'this.p = this.$rtti["TFlagNames"];', - 'this.p = this.$rtti["TBoolNames"];', + LinesToStr([ // $mod.$main + '$mod.p = $mod.$rtti["TFlagNames"];', + '$mod.p = $mod.$rtti["TBoolNames"];', ''])); end; @@ -11136,20 +11465,20 @@ begin ConvertProgram; CheckSource('TestRTTI_DynArray', LinesToStr([ // statements - 'this.$rtti.$DynArray("TArrStr", {', + '$mod.$rtti.$DynArray("TArrStr", {', ' eltype: rtl.string', '});', - 'this.$rtti.$DynArray("TArr2Dim", {', - ' eltype: this.$rtti["TArrStr"]', + '$mod.$rtti.$DynArray("TArr2Dim", {', + ' eltype: $mod.$rtti["TArrStr"]', '});', - 'this.$rtti.$ProcVar("TProc", {', - ' procsig: rtl.newTIProcSig([["f", this.$rtti["TArrStr"]]], this.$rtti["TArr2Dim"])', + '$mod.$rtti.$ProcVar("TProc", {', + ' procsig: rtl.newTIProcSig([["f", $mod.$rtti["TArrStr"]]], $mod.$rtti["TArr2Dim"])', '});', 'this.p = null;', '']), - LinesToStr([ // this.$main - 'this.p = this.$rtti["TArrStr"];', - 'this.p = this.$rtti["TArr2Dim"];', + LinesToStr([ // $mod.$main + '$mod.p = $mod.$rtti["TArrStr"];', + '$mod.p = $mod.$rtti["TArr2Dim"];', ''])); end; @@ -11164,15 +11493,15 @@ begin ConvertProgram; CheckSource('TestRTTI_ArrayNestedAnonymous', LinesToStr([ // statements - 'this.$rtti.$DynArray("TArr$a", {', + '$mod.$rtti.$DynArray("TArr$a", {', ' eltype: rtl.longint', '});', - 'this.$rtti.$DynArray("TArr", {', - ' eltype: this.$rtti["TArr$a"]', + '$mod.$rtti.$DynArray("TArr", {', + ' eltype: $mod.$rtti["TArr$a"]', '});', 'this.a = [];', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ])); end; @@ -11285,7 +11614,7 @@ begin ConvertProgram; CheckSource('TestRTTI_Class_Field', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FPropA = "";', ' this.VarLI = 0;', @@ -11317,10 +11646,10 @@ begin 'this.p = null;', 'this.Obj = null;', '']), - LinesToStr([ // this.$main - 'this.p = this.$rtti["TObject"];', - 'this.p = rtl.pointer;', - 'this.p = this.Obj.$rtti;', + LinesToStr([ // $mod.$main + '$mod.p = $mod.$rtti["TObject"];', + '$mod.p = rtl.pointer;', + '$mod.p = $mod.Obj.$rtti;', ''])); end; @@ -11342,7 +11671,7 @@ begin ConvertProgram; CheckSource('TestRTTI_Class_Method', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -11356,7 +11685,7 @@ begin ' });', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -11391,7 +11720,7 @@ begin ConvertProgram; CheckSource('TestRTTI_Class_Property', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FColor = 0;', ' this.FColorStored = false;', @@ -11417,7 +11746,7 @@ begin ' );', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -11442,7 +11771,7 @@ begin ConvertProgram; CheckSource('TestRTTI_Class_PropertyParams', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -11452,7 +11781,7 @@ begin ' $r.addProperty("Values", 3, rtl.char, "GetValues", "SetValues");', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -11474,7 +11803,7 @@ begin ConvertProgram; CheckSource('TestRTTI_OverrideMethod', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -11482,12 +11811,12 @@ begin ' var $r = this.$rtti;', ' $r.addMethod("DoIt", 0, null);', '});', - 'rtl.createClass(this, "TSky", this.TObject, function () {', + 'rtl.createClass($mod, "TSky", $mod.TObject, function () {', ' this.DoIt = function () {', ' };', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -11510,7 +11839,7 @@ begin ConvertProgram; CheckSource('TestRTTI_OverrideMethod', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FFlag = 0;', ' };', @@ -11519,12 +11848,12 @@ begin ' var $r = this.$rtti;', ' $r.addProperty("Flag", 0, rtl.longint, "FFlag", "");', '});', - 'rtl.createClass(this, "TSky", this.TObject, function () {', + 'rtl.createClass($mod, "TSky", $mod.TObject, function () {', ' var $r = this.$rtti;', ' $r.addProperty("Flag", 0, rtl.longint, "", "FFlag");', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -11553,46 +11882,46 @@ begin ConvertProgram; CheckSource('TestRTTI_ClassForward', LinesToStr([ // statements - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', ' };', '});', - 'this.$rtti.$Class("TBridge");', - 'this.$rtti.$ProcVar("TProc", {', - ' procsig: rtl.newTIProcSig(null, this.$rtti["TBridge"])', + '$mod.$rtti.$Class("TBridge");', + '$mod.$rtti.$ProcVar("TProc", {', + ' procsig: rtl.newTIProcSig(null, $mod.$rtti["TBridge"])', '});', - 'rtl.createClass(this, "TOger", this.TObject, function () {', + 'rtl.createClass($mod, "TOger", $mod.TObject, function () {', ' this.$init = function () {', - ' pas.program.TObject.$init.call(this);', + ' $mod.TObject.$init.call(this);', ' this.FBridge = null;', ' };', ' this.$final = function () {', ' this.FBridge = undefined;', - ' pas.program.TObject.$final.call(this);', + ' $mod.TObject.$final.call(this);', ' };', ' var $r = this.$rtti;', - ' $r.addField("FBridge", pas.program.$rtti["TBridge"]);', - ' $r.addMethod("SetBridge", 0, [["Value", pas.program.$rtti["TBridge"]]]);', - ' $r.addProperty("Bridge", 2, pas.program.$rtti["TBridge"], "FBridge", "SetBridge");', + ' $r.addField("FBridge", $mod.$rtti["TBridge"]);', + ' $r.addMethod("SetBridge", 0, [["Value", $mod.$rtti["TBridge"]]]);', + ' $r.addProperty("Bridge", 2, $mod.$rtti["TBridge"], "FBridge", "SetBridge");', '});', - 'rtl.createClass(this, "TBridge", this.TObject, function () {', + 'rtl.createClass($mod, "TBridge", $mod.TObject, function () {', ' this.$init = function () {', - ' pas.program.TObject.$init.call(this);', + ' $mod.TObject.$init.call(this);', ' this.FOger = null;', ' };', ' this.$final = function () {', ' this.FOger = undefined;', - ' pas.program.TObject.$final.call(this);', + ' $mod.TObject.$final.call(this);', ' };', '});', 'this.p = null;', 'this.b = null;', '']), - LinesToStr([ // this.$main - 'this.p = this.$rtti["TBridge"];', - 'this.p = this.b.$rtti;', + LinesToStr([ // $mod.$main + '$mod.p = $mod.$rtti["TBridge"];', + '$mod.p = $mod.b.$rtti;', ''])); end; @@ -11619,14 +11948,14 @@ begin ConvertProgram; CheckSource('TestRTTI_ClassOf', LinesToStr([ // statements - 'this.$rtti.$Class("TObject");', - 'this.$rtti.$ClassRef("TClass", {', - ' instancetype: this.$rtti["TObject"]', + '$mod.$rtti.$Class("TObject");', + '$mod.$rtti.$ClassRef("TClass", {', + ' instancetype: $mod.$rtti["TObject"]', '});', - 'this.$rtti.$ProcVar("TProcA", {', - ' procsig: rtl.newTIProcSig(null, this.$rtti["TClass"])', + '$mod.$rtti.$ProcVar("TProcA", {', + ' procsig: rtl.newTIProcSig(null, $mod.$rtti["TClass"])', '});', - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.C = null;', ' };', @@ -11634,27 +11963,27 @@ begin ' this.C = undefined;', ' };', ' var $r = this.$rtti;', - ' $r.addField("C", pas.program.$rtti["TClass"]);', + ' $r.addField("C", $mod.$rtti["TClass"]);', '});', - 'this.$rtti.$Class("TFox");', - 'rtl.createClass(this, "TBird", this.TObject, function () {', + '$mod.$rtti.$Class("TFox");', + 'rtl.createClass($mod, "TBird", $mod.TObject, function () {', '});', - 'this.$rtti.$ClassRef("TBirds", {', - ' instancetype: this.$rtti["TBird"]', + '$mod.$rtti.$ClassRef("TBirds", {', + ' instancetype: $mod.$rtti["TBird"]', '});', - 'rtl.createClass(this, "TFox", this.TObject, function () {', + 'rtl.createClass($mod, "TFox", $mod.TObject, function () {', '});', - 'this.$rtti.$ClassRef("TFoxes", {', - ' instancetype: this.$rtti["TFox"]', + '$mod.$rtti.$ClassRef("TFoxes", {', + ' instancetype: $mod.$rtti["TFox"]', '});', - 'this.$rtti.$Class("TCow");', - 'this.$rtti.$ClassRef("TCows", {', - ' instancetype: this.$rtti["TCow"]', + '$mod.$rtti.$Class("TCow");', + '$mod.$rtti.$ClassRef("TCows", {', + ' instancetype: $mod.$rtti["TCow"]', '});', - 'rtl.createClass(this, "TCow", this.TObject, function () {', + 'rtl.createClass($mod, "TCow", $mod.TObject, function () {', '});', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -11688,14 +12017,14 @@ begin ' return (this.x == b.x) && (this.y == b.y);', ' };', '};', - 'this.$rtti.$Record("TPoint", {}).addFields("x", rtl.longint, "y", rtl.longint);', + '$mod.$rtti.$Record("TPoint", {}).addFields("x", rtl.longint, "y", rtl.longint);', 'this.p = null;', - 'this.r = new this.TPoint();', + 'this.r = new $mod.TPoint();', '']), - LinesToStr([ // this.$main - 'this.p = this.$rtti["TPoint"];', - 'this.p = this.$rtti["TPoint"];', - 'this.p = rtl.longint;', + LinesToStr([ // $mod.$main + '$mod.p = $mod.$rtti["TPoint"];', + '$mod.p = $mod.$rtti["TPoint"];', + '$mod.p = rtl.longint;', ''])); end; @@ -11730,7 +12059,7 @@ begin ' };', '};', '']), - LinesToStr([ // this.$main + LinesToStr([ // $mod.$main ''])); end; @@ -11780,29 +12109,29 @@ begin LinesToStr([ // statements 'this.p = null;', '']), - LinesToStr([ // this.$main - 'this.p = rtl.string;', - 'this.p = rtl.string;', - 'this.p = rtl.boolean;', - 'this.p = rtl.boolean;', - 'this.p = rtl.char;', - 'this.p = rtl.char;', - 'this.p = rtl.double;', - 'this.p = rtl.double;', - 'this.p = rtl.pointer;', - 'this.p = rtl.pointer;', - 'this.p = rtl.shortint;', - 'this.p = rtl.shortint;', - 'this.p = rtl.byte;', - 'this.p = rtl.byte;', - 'this.p = rtl.smallint;', - 'this.p = rtl.smallint;', - 'this.p = rtl.word;', - 'this.p = rtl.word;', - 'this.p = rtl.longword;', - 'this.p = rtl.longword;', - 'this.p = rtl.jsvalue;', - 'this.p = rtl.jsvalue;', + LinesToStr([ // $mod.$main + '$mod.p = rtl.string;', + '$mod.p = rtl.string;', + '$mod.p = rtl.boolean;', + '$mod.p = rtl.boolean;', + '$mod.p = rtl.char;', + '$mod.p = rtl.char;', + '$mod.p = rtl.double;', + '$mod.p = rtl.double;', + '$mod.p = rtl.pointer;', + '$mod.p = rtl.pointer;', + '$mod.p = rtl.shortint;', + '$mod.p = rtl.shortint;', + '$mod.p = rtl.byte;', + '$mod.p = rtl.byte;', + '$mod.p = rtl.smallint;', + '$mod.p = rtl.smallint;', + '$mod.p = rtl.word;', + '$mod.p = rtl.word;', + '$mod.p = rtl.longword;', + '$mod.p = rtl.longword;', + '$mod.p = rtl.jsvalue;', + '$mod.p = rtl.jsvalue;', ''])); end; @@ -11865,33 +12194,33 @@ begin ' "1": "down",', ' down: 1', '};', - 'this.$rtti.$Enum("TFlag", {', + '$mod.$rtti.$Enum("TFlag", {', ' minvalue: 0,', ' maxvalue: 1,', ' enumtype: this.TFlag', '});', - 'this.$rtti.$Set("TFlags", {', - ' comptype: this.$rtti["TFlag"]', + '$mod.$rtti.$Set("TFlags", {', + ' comptype: $mod.$rtti["TFlag"]', '});', 'this.ti = null;', 'this.tiInt = null;', 'this.tiEnum = null;', 'this.tiSet = null;', '']), - LinesToStr([ // this.$main - 'this.ti = rtl.string;', - 'this.ti = rtl.boolean;', - 'this.ti = rtl.char;', - 'this.ti = rtl.double;', - 'this.tiInt = rtl.shortint;', - 'this.tiInt = rtl.byte;', - 'this.tiInt = rtl.smallint;', - 'this.tiInt = rtl.word;', - 'this.tiInt = rtl.longint;', - 'this.tiInt = rtl.longword;', - 'this.ti = rtl.jsvalue;', - 'this.tiEnum = this.$rtti["TFlag"];', - 'this.tiSet = this.$rtti["TFlags"];', + LinesToStr([ // $mod.$main + '$mod.ti = rtl.string;', + '$mod.ti = rtl.boolean;', + '$mod.ti = rtl.char;', + '$mod.ti = rtl.double;', + '$mod.tiInt = rtl.shortint;', + '$mod.tiInt = rtl.byte;', + '$mod.tiInt = rtl.smallint;', + '$mod.tiInt = rtl.word;', + '$mod.tiInt = rtl.longint;', + '$mod.tiInt = rtl.longword;', + '$mod.ti = rtl.jsvalue;', + '$mod.tiEnum = $mod.$rtti["TFlag"];', + '$mod.tiSet = $mod.$rtti["TFlags"];', ''])); end; @@ -11931,17 +12260,17 @@ begin ConvertProgram; CheckSource('TestRTTI_TypeInfo_ExtTypeInfoClasses2', LinesToStr([ // statements - ' this.$rtti.$StaticArray("TStaticArr", {', + ' $mod.$rtti.$StaticArray("TStaticArr", {', ' dims: [2],', ' eltype: rtl.string', '});', - 'this.$rtti.$DynArray("TDynArr", {', + '$mod.$rtti.$DynArray("TDynArr", {', ' eltype: rtl.string', '});', - 'this.$rtti.$ProcVar("TProc", {', + '$mod.$rtti.$ProcVar("TProc", {', ' procsig: rtl.newTIProcSig(null)', '});', - 'this.$rtti.$MethodVar("TMethod", {', + '$mod.$rtti.$MethodVar("TMethod", {', ' procsig: rtl.newTIProcSig(null),', ' methodkind: 0', '});', @@ -11954,15 +12283,15 @@ begin 'this.MethodVar = null;', 'this.tiMethodVar = null;', '']), - LinesToStr([ // this.$main - 'this.tiStaticArray = this.$rtti["TStaticArr"];', - 'this.tiStaticArray = this.$rtti["TStaticArr"];', - 'this.tiDynArray = this.$rtti["TDynArr"];', - 'this.tiDynArray = this.$rtti["TDynArr"];', - 'this.tiProcVar = this.$rtti["TProc"];', - 'this.tiProcVar = this.$rtti["TProc"];', - 'this.tiMethodVar = this.$rtti["TMethod"];', - 'this.tiMethodVar = this.$rtti["TMethod"];', + LinesToStr([ // $mod.$main + '$mod.tiStaticArray = $mod.$rtti["TStaticArr"];', + '$mod.tiStaticArray = $mod.$rtti["TStaticArr"];', + '$mod.tiDynArray = $mod.$rtti["TDynArr"];', + '$mod.tiDynArray = $mod.$rtti["TDynArr"];', + '$mod.tiProcVar = $mod.$rtti["TProc"];', + '$mod.tiProcVar = $mod.$rtti["TProc"];', + '$mod.tiMethodVar = $mod.$rtti["TMethod"];', + '$mod.tiMethodVar = $mod.$rtti["TMethod"];', ''])); end; @@ -12002,17 +12331,17 @@ begin LinesToStr([ // statements 'this.TRec = function (s) {', '};', - 'this.$rtti.$Record("TRec", {});', - 'rtl.createClass(this, "TObject", null, function () {', + '$mod.$rtti.$Record("TRec", {});', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', ' };', '});', - 'this.$rtti.$ClassRef("TClass", {', - ' instancetype: this.$rtti["TObject"]', + '$mod.$rtti.$ClassRef("TClass", {', + ' instancetype: $mod.$rtti["TObject"]', '});', - 'this.Rec = new this.TRec();', + 'this.Rec = new $mod.TRec();', 'this.tiRecord = null;', 'this.Obj = null;', 'this.tiClass = null;', @@ -12020,13 +12349,13 @@ begin 'this.tiClassRef = null;', 'this.tiPointer = null;', '']), - LinesToStr([ // this.$main - 'this.tiRecord = this.$rtti["TRec"];', - 'this.tiRecord = this.$rtti["TRec"];', - 'this.tiClass = this.Obj.$rtti;', - 'this.tiClass = this.$rtti["TObject"];', - 'this.tiClassRef = this.$rtti["TClass"];', - 'this.tiClassRef = this.$rtti["TClass"];', + LinesToStr([ // $mod.$main + '$mod.tiRecord = $mod.$rtti["TRec"];', + '$mod.tiRecord = $mod.$rtti["TRec"];', + '$mod.tiClass = $mod.Obj.$rtti;', + '$mod.tiClass = $mod.$rtti["TObject"];', + '$mod.tiClassRef = $mod.$rtti["TClass"];', + '$mod.tiClassRef = $mod.$rtti["TClass"];', ''])); end; diff --git a/packages/pastojs/tests/tcoptimizations.pas b/packages/pastojs/tests/tcoptimizations.pas index 73329a2f5f..f11b5c56c5 100644 --- a/packages/pastojs/tests/tcoptimizations.pas +++ b/packages/pastojs/tests/tcoptimizations.pas @@ -173,7 +173,7 @@ begin ConvertProgram; CheckSource('TestWPO_OmitLocalVar', 'this.b = 0;', - 'this.b = 3;'); + '$mod.b = 3;'); end; procedure TTestOptimizations.TestWPO_OmitLocalProc; @@ -190,7 +190,7 @@ begin '};', '']), LinesToStr([ - 'this.DoIt();', + '$mod.DoIt();', ''])); end; @@ -210,7 +210,7 @@ begin '};', '']), LinesToStr([ - 'this.DoIt();', + '$mod.DoIt();', ''])); end; @@ -239,7 +239,7 @@ begin '};', '']), LinesToStr([ - 'this.DoIt();', + '$mod.DoIt();', ''])); end; @@ -269,7 +269,7 @@ begin '};', '']), LinesToStr([ - 'this.DoIt();', + '$mod.DoIt();', ''])); end; @@ -295,7 +295,7 @@ begin '};', '']), LinesToStr([ - 'this.DoIt();', + '$mod.DoIt();', ''])); end; @@ -320,7 +320,7 @@ begin '};', '']), LinesToStr([ - 'this.DoIt();', + '$mod.DoIt();', ''])); end; @@ -347,7 +347,7 @@ begin '};', '']), LinesToStr([ - 'this.DoIt();', + '$mod.DoIt();', ''])); end; @@ -375,10 +375,10 @@ begin ' return this.a == b.a;', ' };', '};', - 'this.r = new this.TRec();', + 'this.r = new $mod.TRec();', '']), LinesToStr([ - 'this.r.a = 3;', + '$mod.r.a = 3;', ''])); end; @@ -413,7 +413,7 @@ begin ConvertProgram; CheckSource('TestWPO_TObject', LinesToStr([ - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -426,7 +426,7 @@ begin 'this.o = null;', '']), LinesToStr([ - 'this.o = null;'])); + '$mod.o = null;'])); end; procedure TTestOptimizations.TestWPO_OmitClassField; @@ -443,7 +443,7 @@ begin ConvertProgram; CheckSource('TestWPO_OmitClassField', LinesToStr([ - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.a = 0;', ' };', @@ -453,7 +453,7 @@ begin 'this.o = null;', '']), LinesToStr([ - 'this.o.a = 3;'])); + '$mod.o.a = 3;'])); end; procedure TTestOptimizations.TestWPO_OmitClassMethod; @@ -472,7 +472,7 @@ begin ConvertProgram; CheckSource('TestWPO_OmitClassMethod', LinesToStr([ - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -483,7 +483,7 @@ begin 'this.o = null;', '']), LinesToStr([ - 'this.o.ProcB();'])); + '$mod.o.ProcB();'])); end; procedure TTestOptimizations.TestWPO_OmitClassClassMethod; @@ -502,7 +502,7 @@ begin ConvertProgram; CheckSource('TestWPO_OmitClassMethod', LinesToStr([ - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -513,7 +513,7 @@ begin 'this.o = null;', '']), LinesToStr([ - 'this.o.$class.ProcB();'])); + '$mod.o.$class.ProcB();'])); end; procedure TTestOptimizations.TestWPO_OmitPropertyGetter1; @@ -538,7 +538,7 @@ begin ConvertProgram; CheckSource('TestWPO_OmitClassPropertyGetter1', LinesToStr([ - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FFoo = false;', ' };', @@ -548,7 +548,7 @@ begin 'this.o = null;', '']), LinesToStr([ - 'if (this.o.FFoo);', + 'if ($mod.o.FFoo);', ''])); end; @@ -569,7 +569,7 @@ begin ConvertProgram; CheckSource('TestWPO_OmitClassPropertyGetter2', LinesToStr([ - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FFoo = false;', ' };', @@ -584,7 +584,7 @@ begin 'this.o = null;', '']), LinesToStr([ - 'if (this.o.GetFoo()) ;', + 'if ($mod.o.GetFoo()) ;', ''])); end; @@ -610,7 +610,7 @@ begin ConvertProgram; CheckSource('TestWPO_OmitClassPropertySetter1', LinesToStr([ - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FFoo = false;', ' };', @@ -620,7 +620,7 @@ begin 'this.o = null;', '']), LinesToStr([ - 'this.o.FFoo = true;', + '$mod.o.FFoo = true;', ''])); end; @@ -641,7 +641,7 @@ begin ConvertProgram; CheckSource('TestWPO_OmitClassPropertySetter2', LinesToStr([ - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.FFoo = false;', ' };', @@ -654,7 +654,7 @@ begin 'this.o = null;', '']), LinesToStr([ - 'this.o.SetFoo(true);', + '$mod.o.SetFoo(true);', ''])); end; @@ -687,7 +687,7 @@ begin ConvertProgram; CheckSource('TestWPO_CallInherited', LinesToStr([ - 'rtl.createClass(this, "TObject", null, function () {', + 'rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' };', ' this.$final = function () {', @@ -697,19 +697,19 @@ begin ' this.DoB = function () {', ' };', '});', - ' rtl.createClass(this, "TMobile", this.TObject, function () {', + ' rtl.createClass($mod, "TMobile", $mod.TObject, function () {', ' this.DoA$1 = function () {', - ' pas.program.TObject.DoA.apply(this, arguments);', + ' $mod.TObject.DoA.apply(this, arguments);', ' };', ' this.DoC = function () {', - ' pas.program.TObject.DoB.call(this);', + ' $mod.TObject.DoB.call(this);', ' };', '});', 'this.o = null;', '']), LinesToStr([ - 'this.o.DoA$1();', - 'this.o.DoC();', + '$mod.o.DoA$1();', + '$mod.o.DoC();', ''])); end; @@ -741,7 +741,8 @@ begin ActualSrc:=JSToStr(JSModule); ExpectedSrc:=LinesToStr([ 'rtl.module("program", ["system", "unit2"], function () {', - ' this.$main = function () {', + ' var $mod = this;', + ' $mod.$main = function () {', ' pas.unit2.j = 3;', ' };', '});', @@ -764,10 +765,11 @@ begin ActualSrc:=JSToStr(JSModule); ExpectedSrc:=LinesToStr([ 'rtl.module("program", ["system"], function () {', + ' var $mod = this;', ' this.vPublic = 0;', ' this.DoPublic =function(){', ' };', - ' this.$main = function () {', + ' $mod.$main = function () {', ' };', '});', '']); @@ -797,10 +799,11 @@ begin ActualSrc:=JSToStr(JSModule); ExpectedSrc:=LinesToStr([ 'rtl.module("program", ["system"], function () {', - 'this.$rtti.$DynArray("TArrB", {', - ' eltype: rtl.string', - '});', - ' rtl.createClass(this, "TObject", null, function () {', + ' var $mod = this;', + ' $mod.$rtti.$DynArray("TArrB", {', + ' eltype: rtl.string', + ' });', + ' rtl.createClass($mod, "TObject", null, function () {', ' this.$init = function () {', ' this.PublicA = [];', ' this.PublishedB = [];', @@ -810,11 +813,11 @@ begin ' this.PublishedB = undefined;', ' };', ' var $r = this.$rtti;', - ' $r.addField("PublishedB", pas.program.$rtti["TArrB"]);', + ' $r.addField("PublishedB", $mod.$rtti["TArrB"]);', ' });', ' this.C = null;', - ' this.$main = function () {', - ' this.C.PublicA = [];', + ' $mod.$main = function () {', + ' $mod.C.PublicA = [];', ' };', '});', '']); @@ -841,15 +844,16 @@ begin ActualSrc:=JSToStr(JSModule); ExpectedSrc:=LinesToStr([ 'rtl.module("program", ["system"], function () {', - 'this.$rtti.$DynArray("TArrB", {', - ' eltype: rtl.string', - '});', + ' var $mod = this;', + ' $mod.$rtti.$DynArray("TArrB", {', + ' eltype: rtl.string', + ' });', ' this.A = [];', ' this.B = [];', ' this.p = null;', - ' this.$main = function () {', - ' this.A = [];', - ' this.p = this.$rtti["TArrB"];', + ' $mod.$main = function () {', + ' $mod.A = [];', + ' $mod.p = $mod.$rtti["TArrB"];', ' };', '});', '']);