2006-05-30 16:23:25 +02:00
|
|
|
unit uPSComponent;
|
|
|
|
{$I PascalScript.inc}
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
SysUtils, Classes, uPSRuntime, uPSDebugger, uPSUtils,
|
|
|
|
uPSCompiler, uPSC_dll, uPSR_dll, uPSPreProcessor;
|
|
|
|
|
|
|
|
const
|
|
|
|
{alias to @link(ifps3.cdRegister)}
|
|
|
|
cdRegister = uPSRuntime.cdRegister;
|
|
|
|
{alias to @link(ifps3.cdPascal)}
|
|
|
|
cdPascal = uPSRuntime.cdPascal;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
CdCdecl = uPSRuntime.CdCdecl;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
CdStdCall = uPSRuntime.CdStdCall;
|
|
|
|
|
|
|
|
type
|
|
|
|
TPSScript = class;
|
|
|
|
|
|
|
|
TDelphiCallingConvention = uPSRuntime.TPSCallingConvention;
|
|
|
|
{Alias to @link(ifps3.TPSRuntimeClassImporter)}
|
|
|
|
TPSRuntimeClassImporter = uPSRuntime.TPSRuntimeClassImporter;
|
|
|
|
|
|
|
|
TPSPlugin = class(TComponent)
|
2009-03-19 09:48:53 +01:00
|
|
|
public
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure CompOnUses(CompExec: TPSScript); virtual;
|
2009-03-19 09:48:53 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure ExecOnUses(CompExec: TPSScript); virtual;
|
2009-03-19 09:48:53 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure CompileImport1(CompExec: TPSScript); virtual;
|
2009-03-19 09:48:53 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure CompileImport2(CompExec: TPSScript); virtual;
|
2009-03-19 09:48:53 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); virtual;
|
2009-03-19 09:48:53 +01:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure ExecImport2(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TIFPS3Plugin = class(TPSPlugin);
|
|
|
|
|
|
|
|
TPSDllPlugin = class(TPSPlugin)
|
2009-03-19 09:48:53 +01:00
|
|
|
public
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure CompOnUses(CompExec: TPSScript); override;
|
|
|
|
procedure ExecOnUses(CompExec: TPSScript); override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TIFPS3DllPlugin = class(TPSDllPlugin);
|
|
|
|
|
|
|
|
|
|
|
|
TPSPluginItem = class(TCollectionItem)
|
|
|
|
private
|
|
|
|
FPlugin: TPSPlugin;
|
|
|
|
procedure SetPlugin(const Value: TPSPlugin);
|
|
|
|
protected
|
|
|
|
function GetDisplayName: string; override;
|
|
|
|
public
|
|
|
|
procedure Assign(Source: TPersistent); override; //Birb
|
|
|
|
published
|
|
|
|
property Plugin: TPSPlugin read FPlugin write SetPlugin;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TIFPS3CEPluginItem = class(TPSPluginItem);
|
|
|
|
|
|
|
|
|
|
|
|
TPSPlugins = class(TCollection)
|
|
|
|
private
|
|
|
|
FCompExec: TPSScript;
|
|
|
|
protected
|
|
|
|
|
|
|
|
function GetOwner: TPersistent; override;
|
|
|
|
public
|
|
|
|
|
|
|
|
constructor Create(CE: TPSScript);
|
|
|
|
end;
|
|
|
|
|
|
|
|
TIFPS3CEPlugins = class(TPSPlugins);
|
|
|
|
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
TPSOnGetNotVariant = function (Sender: TPSScript; const Name: tbtstring): Variant of object;
|
|
|
|
TPSOnSetNotVariant = procedure (Sender: TPSScript; const Name: tbtstring; V: Variant) of object;
|
2006-05-30 16:23:25 +02:00
|
|
|
TPSCompOptions = set of (icAllowNoBegin, icAllowUnit, icAllowNoEnd, icBooleanShortCircuit);
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
TPSVerifyProc = procedure (Sender: TPSScript; Proc: TPSInternalProcedure; const Decl: tbtstring; var Error: Boolean) of object;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
TPSEvent = procedure (Sender: TPSScript) of object;
|
|
|
|
|
|
|
|
TPSOnCompImport = procedure (Sender: TObject; x: TPSPascalCompiler) of object;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
TPSOnExecImport = procedure (Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter) of object;
|
|
|
|
{Script engine event function}
|
2008-08-01 13:23:09 +02:00
|
|
|
TPSOnNeedFile = function (Sender: TObject; const OrginFileName: tbtstring; var FileName, Output: tbtstring): Boolean of object;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
TPSOnProcessDirective = procedure (
|
|
|
|
Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser;
|
|
|
|
const Active: Boolean;
|
2008-08-01 13:23:09 +02:00
|
|
|
const DirectiveName, DirectiveParam: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
Var Continue: Boolean) of Object; // jgv
|
|
|
|
|
|
|
|
TPSScript = class(TComponent)
|
|
|
|
private
|
|
|
|
FOnGetNotificationVariant: TPSOnGetNotVariant;
|
|
|
|
FOnSetNotificationVariant: TPSOnSetNotVariant;
|
|
|
|
FCanAdd: Boolean;
|
|
|
|
FComp: TPSPascalCompiler;
|
|
|
|
FCompOptions: TPSCompOptions;
|
|
|
|
FExec: TPSDebugExec;
|
|
|
|
FSuppressLoadData: Boolean;
|
|
|
|
FScript: TStrings;
|
|
|
|
FOnLine: TNotifyEvent;
|
|
|
|
FUseDebugInfo: Boolean;
|
|
|
|
FOnAfterExecute, FOnCompile, FOnExecute: TPSEvent;
|
|
|
|
FOnCompImport: TPSOnCompImport;
|
|
|
|
FOnExecImport: TPSOnExecImport;
|
|
|
|
RI: TPSRuntimeClassImporter;
|
|
|
|
FPlugins: TPSPlugins;
|
|
|
|
FPP: TPSPreProcessor;
|
2008-08-01 13:23:09 +02:00
|
|
|
FMainFileName: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
FOnNeedFile: TPSOnNeedFile;
|
|
|
|
FUsePreProcessor: Boolean;
|
|
|
|
FDefines: TStrings;
|
|
|
|
FOnVerifyProc: TPSVerifyProc;
|
|
|
|
FOnProcessDirective: TPSOnProcessDirective;
|
|
|
|
FOnProcessUnknowDirective: TPSOnProcessDirective;
|
2006-08-18 10:34:39 +02:00
|
|
|
FOnFindUnknownFile: TPSOnNeedFile;
|
2006-05-30 16:23:25 +02:00
|
|
|
function GetRunning: Boolean;
|
|
|
|
procedure SetScript(const Value: TStrings);
|
|
|
|
function GetCompMsg(i: Integer): TPSPascalCompilerMessage;
|
|
|
|
function GetCompMsgCount: Longint;
|
2008-08-01 13:23:09 +02:00
|
|
|
function GetAbout: tbtstring;
|
|
|
|
function ScriptUses(Sender: TPSPascalCompiler; const Name: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
function GetExecErrorByteCodePosition: Cardinal;
|
|
|
|
function GetExecErrorCode: TIFError;
|
2008-08-01 13:23:09 +02:00
|
|
|
function GetExecErrorParam: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
function GetExecErrorProcNo: Cardinal;
|
2008-08-01 13:23:09 +02:00
|
|
|
function GetExecErrorString: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
function GetExecErrorPosition: Cardinal;
|
|
|
|
function GetExecErrorCol: Cardinal;
|
|
|
|
function GetExecErrorRow: Cardinal;
|
2008-08-01 13:23:09 +02:00
|
|
|
function GetExecErrorFileName: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure SetDefines(const Value: TStrings);
|
|
|
|
protected
|
|
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
|
|
|
|
|
|
|
protected
|
|
|
|
//jgv move where private before - not very usefull
|
|
|
|
procedure OnLineEvent; virtual;
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure SetMainFileName(const Value: tbtstring); virtual;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
//--jgv new
|
2008-08-01 13:23:09 +02:00
|
|
|
function DoOnNeedFile (Sender: TObject; const OrginFileName: tbtstring; var FileName, Output: tbtstring): Boolean; virtual;
|
|
|
|
function DoOnUnknowUses (Sender: TPSPascalCompiler; const Name: tbtstring): Boolean; virtual; // return true if processed
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure DoOnCompImport; virtual;
|
|
|
|
procedure DoOnCompile; virtual;
|
2008-08-01 13:23:09 +02:00
|
|
|
function DoVerifyProc (Sender: TPSScript; Proc: TPSInternalProcedure; const Decl: tbtstring): Boolean; virtual;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
procedure DoOnExecImport (RunTimeImporter: TPSRuntimeClassImporter); virtual;
|
|
|
|
procedure DoOnExecute (RunTimeImporter: TPSRuntimeClassImporter); virtual;
|
|
|
|
procedure DoAfterExecute; virtual;
|
2008-08-01 13:23:09 +02:00
|
|
|
function DoOnGetNotificationVariant (const Name: tbtstring): Variant; virtual;
|
|
|
|
procedure DoOnSetNotificationVariant (const Name: tbtstring; V: Variant); virtual;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
procedure DoOnProcessDirective (Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser;
|
|
|
|
const Active: Boolean;
|
2008-08-01 13:23:09 +02:00
|
|
|
const DirectiveName, DirectiveParam: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
Var Continue: Boolean); virtual;
|
|
|
|
procedure DoOnProcessUnknowDirective (Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser;
|
|
|
|
const Active: Boolean;
|
2008-08-01 13:23:09 +02:00
|
|
|
const DirectiveName, DirectiveParam: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
Var Continue: Boolean); virtual;
|
|
|
|
public
|
2009-03-19 09:48:53 +01:00
|
|
|
property RuntimeImporter: TPSRuntimeClassImporter read RI;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function FindNamedType(const Name: tbtstring): TPSTypeRec;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
function FindBaseType(Bt: TPSBaseType): TPSTypeRec;
|
|
|
|
|
|
|
|
property SuppressLoadData: Boolean read FSuppressLoadData write FSuppressLoadData;
|
|
|
|
|
|
|
|
function LoadExec: Boolean;
|
|
|
|
|
|
|
|
procedure Stop; virtual;
|
|
|
|
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
|
function Compile: Boolean; virtual;
|
|
|
|
|
|
|
|
function Execute: Boolean; virtual;
|
|
|
|
|
|
|
|
property Running: Boolean read GetRunning;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure GetCompiled(var data: tbtstring);
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure SetCompiled(const Data: tbtstring);
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
property Comp: TPSPascalCompiler read FComp;
|
|
|
|
|
|
|
|
property Exec: TPSDebugExec read FExec;
|
|
|
|
|
|
|
|
property CompilerMessageCount: Longint read GetCompMsgCount;
|
|
|
|
|
|
|
|
property CompilerMessages[i: Longint]: TPSPascalCompilerMessage read GetCompMsg;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function CompilerErrorToStr(I: Longint): tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
property ExecErrorCode: TIFError read GetExecErrorCode;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
property ExecErrorParam: tbtstring read GetExecErrorParam;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
property ExecErrorToString: tbtstring read GetExecErrorString;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
property ExecErrorProcNo: Cardinal read GetExecErrorProcNo;
|
|
|
|
|
|
|
|
property ExecErrorByteCodePosition: Cardinal read GetExecErrorByteCodePosition;
|
|
|
|
|
|
|
|
property ExecErrorPosition: Cardinal read GetExecErrorPosition;
|
|
|
|
|
|
|
|
property ExecErrorRow: Cardinal read GetExecErrorRow;
|
|
|
|
|
|
|
|
property ExecErrorCol: Cardinal read GetExecErrorCol;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
property ExecErrorFileName: tbtstring read GetExecErrorFileName;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function AddFunctionEx(Ptr: Pointer; const Decl: tbtstring; CallingConv: TDelphiCallingConvention): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function AddFunction(Ptr: Pointer; const Decl: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function AddMethodEx(Slf, Ptr: Pointer; const Decl: tbtstring; CallingConv: TDelphiCallingConvention): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function AddMethod(Slf, Ptr: Pointer; const Decl: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function AddRegisteredVariable(const VarName, VarType: tbtstring): Boolean;
|
|
|
|
function AddNotificationVariant(const VarName: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function AddRegisteredPTRVariable(const VarName, VarType: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function GetVariable(const Name: tbtstring): PIFVariant;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function SetVarToInstance(const VarName: tbtstring; cl: TObject): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure SetPointerToData(const VarName: tbtstring; Data: Pointer; aType: TIFTypeRec);
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TranslatePositionPos(Proc, Position: Cardinal; var Pos: Cardinal; var fn: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TranslatePositionRC(Proc, Position: Cardinal; var Row, Col: Cardinal; var fn: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function GetProcMethod(const ProcName: tbtstring): TMethod;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function ExecuteFunction(const Params: array of Variant; const ProcName: tbtstring): Variant;
|
2006-05-30 16:23:25 +02:00
|
|
|
published
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
property About: tbtstring read GetAbout stored false;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
property Script: TStrings read FScript write SetScript;
|
|
|
|
|
|
|
|
property CompilerOptions: TPSCompOptions read FCompOptions write FCompOptions;
|
|
|
|
|
|
|
|
property OnLine: TNotifyEvent read FOnLine write FOnLine;
|
|
|
|
|
|
|
|
property OnCompile: TPSEvent read FOnCompile write FOnCompile;
|
|
|
|
|
|
|
|
property OnExecute: TPSEvent read FOnExecute write FOnExecute;
|
|
|
|
|
|
|
|
property OnAfterExecute: TPSEvent read FOnAfterExecute write FOnAfterExecute;
|
|
|
|
|
|
|
|
property OnCompImport: TPSOnCompImport read FOnCompImport write FOnCompImport;
|
|
|
|
|
|
|
|
property OnExecImport: TPSOnExecImport read FOnExecImport write FOnExecImport;
|
|
|
|
|
|
|
|
property UseDebugInfo: Boolean read FUseDebugInfo write FUseDebugInfo default True;
|
|
|
|
|
|
|
|
property Plugins: TPSPlugins read FPlugins write FPlugins;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
property MainFileName: tbtstring read FMainFileName write SetMainFileName;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
property UsePreProcessor: Boolean read FUsePreProcessor write FUsePreProcessor;
|
|
|
|
|
|
|
|
property OnNeedFile: TPSOnNeedFile read FOnNeedFile write FOnNeedFile;
|
|
|
|
|
|
|
|
property Defines: TStrings read FDefines write SetDefines;
|
|
|
|
|
|
|
|
property OnVerifyProc: TPSVerifyProc read FOnVerifyProc write FOnVerifyProc;
|
|
|
|
property OnGetNotificationVariant: TPSOnGetNotVariant read FOnGetNotificationVariant write FOnGetNotificationVariant;
|
|
|
|
property OnSetNotificationVariant: TPSOnSetNotVariant read FOnSetNotificationVariant write FOnSetNotificationVariant;
|
2006-08-18 10:34:39 +02:00
|
|
|
property OnFindUnknownFile: TPSOnNeedFile read FOnFindUnknownFile write FOnFindUnknownFile;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
published
|
|
|
|
//-- jgv
|
|
|
|
property OnProcessDirective: TPSOnProcessDirective read FOnProcessDirective write FOnProcessDirective;
|
|
|
|
property OnProcessUnknowDirective: TPSOnProcessDirective read FOnProcessUnknowDirective write FOnProcessUnknowDirective;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TIFPS3CompExec = class(TPSScript);
|
|
|
|
|
|
|
|
|
|
|
|
TPSBreakPointInfo = class
|
|
|
|
private
|
|
|
|
FLine: Longint;
|
|
|
|
FFileNameHash: Longint;
|
2008-08-01 13:23:09 +02:00
|
|
|
FFileName: tbtstring;
|
|
|
|
procedure SetFileName(const Value: tbtstring);
|
2006-05-30 16:23:25 +02:00
|
|
|
public
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
property FileName: tbtstring read FFileName write SetFileName;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
property FileNameHash: Longint read FFileNameHash;
|
|
|
|
|
|
|
|
property Line: Longint read FLine write FLine;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
TPSOnLineInfo = procedure (Sender: TObject; const FileName: tbtstring; Position, Row, Col: Cardinal) of object;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
TPSScriptDebugger = class(TPSScript)
|
|
|
|
private
|
|
|
|
FOnIdle: TNotifyEvent;
|
|
|
|
FBreakPoints: TIFList;
|
|
|
|
FOnLineInfo: TPSOnLineInfo;
|
|
|
|
FLastRow: Cardinal;
|
|
|
|
FOnBreakpoint: TPSOnLineInfo;
|
|
|
|
function GetBreakPoint(I: Integer): TPSBreakPointInfo;
|
|
|
|
function GetBreakPointCount: Longint;
|
|
|
|
protected
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure SetMainFileName(const Value: tbtstring); override;
|
2006-05-30 16:23:25 +02:00
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
|
|
|
|
|
procedure Pause; virtual;
|
|
|
|
|
|
|
|
procedure Resume; virtual;
|
|
|
|
|
|
|
|
|
|
|
|
procedure StepInto; virtual;
|
|
|
|
|
|
|
|
procedure StepOver; virtual;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure SetBreakPoint(const Fn: tbtstring; Line: Longint);
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure ClearBreakPoint(const Fn: tbtstring; Line: Longint);
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property BreakPointCount: Longint read GetBreakPointCount;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property BreakPoint[I: Longint]: TPSBreakPointInfo read GetBreakPoint;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function HasBreakPoint(const Fn: tbtstring; Line: Longint): Boolean;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
procedure ClearBreakPoints;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function GetVarContents(const Name: tbtstring): tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
published
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property OnIdle: TNotifyEvent read FOnIdle write FOnIdle;
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
property OnLineInfo: TPSOnLineInfo read FOnLineInfo write FOnLineInfo;
|
|
|
|
|
|
|
|
property OnBreakpoint: TPSOnLineInfo read FOnBreakpoint write FOnBreakpoint;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TIFPS3DebugCompExec = class(TPSScriptDebugger);
|
2006-08-18 10:34:39 +02:00
|
|
|
|
|
|
|
TPSCustumPlugin = class(TPSPlugin)
|
|
|
|
private
|
|
|
|
FOnCompileImport2: TPSEvent;
|
|
|
|
FOnExecOnUses: TPSEvent;
|
|
|
|
FOnCompOnUses: TPSEvent;
|
|
|
|
FOnCompileImport1: TPSEvent;
|
|
|
|
FOnExecImport1: TPSOnExecImport;
|
|
|
|
FOnExecImport2: TPSOnExecImport;
|
2009-03-19 09:48:53 +01:00
|
|
|
public
|
2006-08-18 10:34:39 +02:00
|
|
|
procedure CompOnUses(CompExec: TPSScript); override;
|
|
|
|
procedure ExecOnUses(CompExec: TPSScript); override;
|
|
|
|
procedure CompileImport1(CompExec: TPSScript); override;
|
|
|
|
procedure CompileImport2(CompExec: TPSScript); override;
|
|
|
|
procedure ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); override;
|
|
|
|
|
|
|
|
procedure ExecImport2(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); override;
|
|
|
|
public
|
|
|
|
published
|
|
|
|
property OnCompOnUses : TPSEvent read FOnCompOnUses write FOnCompOnUses;
|
|
|
|
property OnExecOnUses: TPSEvent read FOnExecOnUses write FOnExecOnUses;
|
|
|
|
property OnCompileImport1: TPSEvent read FOnCompileImport1 write FOnCompileImport1;
|
|
|
|
property OnCompileImport2: TPSEvent read FOnCompileImport2 write FOnCompileImport2;
|
|
|
|
property OnExecImport1: TPSOnExecImport read FOnExecImport1 write FOnExecImport1;
|
|
|
|
property OnExecImport2: TPSOnExecImport read FOnExecImport2 write FOnExecImport2;
|
|
|
|
end;
|
2006-05-30 16:23:25 +02:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
{$IFDEF DELPHI3UP }
|
|
|
|
resourceString
|
|
|
|
{$ELSE }
|
|
|
|
const
|
|
|
|
{$ENDIF }
|
|
|
|
|
|
|
|
RPS_UnableToReadVariant = 'Unable to read variant';
|
|
|
|
RPS_UnableToWriteVariant = 'Unable to write variant';
|
|
|
|
RPS_ScripEngineAlreadyRunning = 'Script engine already running';
|
|
|
|
RPS_ScriptNotCompiled = 'Script is not compiled';
|
|
|
|
RPS_NotRunning = 'Not running';
|
|
|
|
RPS_UnableToFindVariable = 'Unable to find variable';
|
|
|
|
RPS_UnknownIdentifier = 'Unknown Identifier';
|
|
|
|
RPS_NoScript = 'No script';
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function MyGetVariant(Sender: TPSExec; const Name: tbtstring): Variant;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := TPSScript (Sender.Id).DoOnGetNotificationVariant(Name);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure MySetVariant(Sender: TPSExec; const Name: tbtstring; V: Variant);
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
TPSScript (Sender.Id).DoOnSetNotificationVariant(Name, V);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function CompScriptUses(Sender: TPSPascalCompiler; const Name: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := TPSScript(Sender.ID).ScriptUses(Sender, Name);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure ExecOnLine(Sender: TPSExec);
|
|
|
|
begin
|
|
|
|
if assigned(TPSScript(Sender.ID).FOnLine) then
|
|
|
|
begin
|
|
|
|
TPSScript(Sender.ID).OnLineEvent;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function CompExportCheck(Sender: TPSPascalCompiler; Proc: TPSInternalProcedure; const ProcDecl: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := TPSScript(Sender.ID).DoVerifyProc (Sender.ID, Proc, ProcDecl);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure callObjectOnProcessDirective (
|
|
|
|
Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser;
|
|
|
|
const Active: Boolean;
|
2008-08-01 13:23:09 +02:00
|
|
|
const DirectiveName, DirectiveParam: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
Var Continue: Boolean);
|
|
|
|
begin
|
|
|
|
TPSScript (Sender.ID).DoOnProcessUnknowDirective(Sender, Parser, Active, DirectiveName, DirectiveParam, Continue);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure callObjectOnProcessUnknowDirective (
|
|
|
|
Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser;
|
|
|
|
const Active: Boolean;
|
2008-08-01 13:23:09 +02:00
|
|
|
const DirectiveName, DirectiveParam: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
Var Continue: Boolean);
|
|
|
|
begin
|
|
|
|
TPSScript (Sender.ID).DoOnProcessDirective(Sender, Parser, Active, DirectiveName, DirectiveParam, Continue);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TPSPlugin }
|
|
|
|
procedure TPSPlugin.CompileImport1(CompExec: TPSScript);
|
|
|
|
begin
|
|
|
|
// do nothing
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSPlugin.CompileImport2(CompExec: TPSScript);
|
|
|
|
begin
|
|
|
|
// do nothing
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSPlugin.CompOnUses(CompExec: TPSScript);
|
|
|
|
begin
|
|
|
|
// do nothing
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSPlugin.ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter);
|
|
|
|
begin
|
|
|
|
// do nothing
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSPlugin.ExecImport2(CompExec: TPSScript; const ri: TPSRuntimeClassImporter);
|
|
|
|
begin
|
|
|
|
// do nothing
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSPlugin.ExecOnUses(CompExec: TPSScript);
|
|
|
|
begin
|
|
|
|
// do nothing
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TPSScript }
|
|
|
|
|
|
|
|
function TPSScript.AddFunction(Ptr: Pointer;
|
2008-08-01 13:23:09 +02:00
|
|
|
const Decl: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := AddFunctionEx(Ptr, Decl, cdRegister);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.AddFunctionEx(Ptr: Pointer; const Decl: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
CallingConv: TDelphiCallingConvention): Boolean;
|
|
|
|
var
|
|
|
|
P: TPSRegProc;
|
|
|
|
begin
|
|
|
|
if not FCanAdd then begin Result := False; exit; end;
|
|
|
|
p := Comp.AddDelphiFunction(Decl);
|
|
|
|
if p <> nil then
|
|
|
|
begin
|
|
|
|
Exec.RegisterDelphiFunction(Ptr, p.Name, CallingConv);
|
|
|
|
Result := True;
|
|
|
|
end else Result := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.AddRegisteredVariable(const VarName,
|
2008-08-01 13:23:09 +02:00
|
|
|
VarType: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
FVar: TPSVar;
|
|
|
|
begin
|
|
|
|
if not FCanAdd then begin Result := False; exit; end;
|
|
|
|
FVar := FComp.AddUsedVariableN(varname, vartype);
|
|
|
|
if fvar = nil then
|
|
|
|
result := False
|
|
|
|
else begin
|
|
|
|
fvar.exportname := fvar.Name;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function CENeedFile(Sender: TPSPreProcessor; const callingfilename: tbtstring; var FileName, Output: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := TPSScript (Sender.ID).DoOnNeedFile(Sender.ID, CallingFileName, FileName, Output);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure CompTranslateLineInfo(Sender: TPSPascalCompiler; var Pos, Row, Col: Cardinal; var Name: tbtstring);
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
res: TPSLineInfoResults;
|
|
|
|
begin
|
2008-03-31 08:36:36 +02:00
|
|
|
if TPSScript(Sender.ID).FPP.CurrentLineInfo.GetLineInfo(Name, Pos, Res) then
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Pos := Res.Pos;
|
|
|
|
Row := Res.Row;
|
|
|
|
Col := Res.Col;
|
|
|
|
Name := Res.Name;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.Compile: Boolean;
|
|
|
|
var
|
|
|
|
i: Longint;
|
2008-08-01 13:23:09 +02:00
|
|
|
dta: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
FExec.Clear;
|
|
|
|
FExec.CMD_Err(erNoError);
|
|
|
|
FExec.ClearspecialProcImports;
|
|
|
|
FExec.ClearFunctionList;
|
|
|
|
if ri <> nil then
|
|
|
|
begin
|
|
|
|
RI.Free;
|
|
|
|
RI := nil;
|
|
|
|
end;
|
|
|
|
RI := TPSRuntimeClassImporter.Create;
|
|
|
|
for i := 0 to FPlugins.Count -1 do
|
|
|
|
begin
|
2006-09-19 11:53:35 +02:00
|
|
|
if (TPSPluginItem(FPlugins.Items[i]) <> nil) and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
|
2006-05-30 16:23:25 +02:00
|
|
|
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecImport1(Self, ri);
|
|
|
|
end;
|
|
|
|
|
|
|
|
DoOnExecImport (RI);
|
|
|
|
|
|
|
|
for i := 0 to FPlugins.Count -1 do
|
|
|
|
begin
|
2006-09-19 11:53:35 +02:00
|
|
|
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
|
|
|
|
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecImport2(Self, ri);
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
RegisterClassLibraryRuntime(Exec, RI);
|
|
|
|
for i := 0 to FPlugins.Count -1 do
|
|
|
|
begin
|
2006-09-19 11:53:35 +02:00
|
|
|
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
|
|
|
|
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecOnUses(Self);
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
FCanAdd := True;
|
|
|
|
FComp.BooleanShortCircuit := icBooleanShortCircuit in FCompOptions;
|
|
|
|
FComp.AllowNoBegin := icAllowNoBegin in FCompOptions;
|
|
|
|
FComp.AllowUnit := icAllowUnit in FCompOptions;
|
|
|
|
FComp.AllowNoEnd := icAllowNoEnd in FCompOptions;
|
|
|
|
if FUsePreProcessor then
|
|
|
|
begin
|
2007-10-22 11:13:21 +02:00
|
|
|
FPP.Clear;
|
2006-05-30 16:23:25 +02:00
|
|
|
FPP.Defines.Assign(FDefines);
|
|
|
|
FComp.OnTranslateLineInfo := CompTranslateLineInfo;
|
|
|
|
Fpp.OnProcessDirective := callObjectOnProcessDirective;
|
|
|
|
Fpp.OnProcessUnknowDirective := callObjectOnProcessUnknowDirective;
|
|
|
|
Fpp.MainFile := FScript.Text;
|
|
|
|
Fpp.MainFileName := FMainFileName;
|
2007-10-22 11:13:21 +02:00
|
|
|
Fpp.PreProcess(FMainFileName, dta);
|
|
|
|
if FComp.Compile(dta) then
|
|
|
|
begin
|
|
|
|
FCanAdd := False;
|
|
|
|
if (not SuppressLoadData) and (not LoadExec) then
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
2007-10-22 11:13:21 +02:00
|
|
|
Result := False;
|
|
|
|
end else
|
|
|
|
Result := True;
|
|
|
|
end else Result := False;
|
|
|
|
Fpp.AdjustMessages(Comp);
|
2006-05-30 16:23:25 +02:00
|
|
|
end else
|
|
|
|
begin
|
|
|
|
FComp.OnTranslateLineInfo := nil;
|
|
|
|
if FComp.Compile(FScript.Text) then
|
|
|
|
begin
|
|
|
|
FCanAdd := False;
|
|
|
|
if not LoadExec then
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end else
|
|
|
|
Result := True;
|
|
|
|
end else Result := False;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.CompilerErrorToStr(I: Integer): tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := CompilerMessages[i].MessageToString;
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TPSScript.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
FComp := TPSPascalCompiler.Create;
|
|
|
|
FExec := TPSDebugExec.Create;
|
|
|
|
FScript := TStringList.Create;
|
|
|
|
FPlugins := TPSPlugins.Create(self);
|
|
|
|
|
|
|
|
FComp.ID := Self;
|
|
|
|
FComp.OnUses := CompScriptUses;
|
|
|
|
FComp.OnExportCheck := CompExportCheck;
|
|
|
|
FExec.Id := Self;
|
|
|
|
FExec.OnRunLine:= ExecOnLine;
|
|
|
|
FExec.OnGetNVariant := MyGetVariant;
|
|
|
|
FExec.OnSetNVariant := MySetVariant;
|
|
|
|
|
|
|
|
FUseDebugInfo := True;
|
|
|
|
|
|
|
|
FPP := TPSPreProcessor.Create;
|
|
|
|
FPP.Id := Self;
|
|
|
|
FPP.OnNeedFile := CENeedFile;
|
|
|
|
|
|
|
|
FDefines := TStringList.Create;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TPSScript.Destroy;
|
|
|
|
begin
|
|
|
|
FDefines.Free;
|
|
|
|
|
|
|
|
FPP.Free;
|
|
|
|
RI.Free;
|
|
|
|
FPlugins.Free;
|
2006-09-12 17:07:27 +02:00
|
|
|
FPlugins := nil;
|
2006-05-30 16:23:25 +02:00
|
|
|
FScript.Free;
|
|
|
|
FExec.Free;
|
|
|
|
FComp.Free;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.Execute: Boolean;
|
|
|
|
begin
|
|
|
|
if Running then raise Exception.Create(RPS_ScripEngineAlreadyRunning);
|
|
|
|
if SuppressLoadData then
|
|
|
|
LoadExec;
|
|
|
|
|
|
|
|
DoOnExecute (RI);
|
2006-08-18 10:34:39 +02:00
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
FExec.DebugEnabled := FUseDebugInfo;
|
|
|
|
Result := FExec.RunScript and (FExec.ExceptionCode = erNoError) ;
|
|
|
|
|
|
|
|
DoAfterExecute;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.GetAbout: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := TPSExec.About;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSScript.GetCompiled(var data: tbtstring);
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
if not FComp.GetOutput(Data) then
|
|
|
|
raise Exception.Create(RPS_ScriptNotCompiled);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.GetCompMsg(i: Integer): TPSPascalCompilerMessage;
|
|
|
|
begin
|
|
|
|
Result := FComp.Msg[i];
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.GetCompMsgCount: Longint;
|
|
|
|
begin
|
|
|
|
Result := FComp.MsgCount;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.GetExecErrorByteCodePosition: Cardinal;
|
|
|
|
begin
|
|
|
|
Result := Exec.ExceptionPos;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.GetExecErrorCode: TIFError;
|
|
|
|
begin
|
|
|
|
Result := Exec.ExceptionCode;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.GetExecErrorParam: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := Exec.ExceptionString;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.GetExecErrorPosition: Cardinal;
|
|
|
|
begin
|
|
|
|
Result := FExec.TranslatePosition(Exec.ExceptionProcNo, Exec.ExceptionPos);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.GetExecErrorProcNo: Cardinal;
|
|
|
|
begin
|
|
|
|
Result := Exec.ExceptionProcNo;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.GetExecErrorString: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := TIFErrorToString(Exec.ExceptionCode, Exec.ExceptionString);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.GetVariable(const Name: tbtstring): PIFVariant;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := FExec.GetVar2(name);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.LoadExec: Boolean;
|
|
|
|
var
|
2008-08-01 13:23:09 +02:00
|
|
|
s: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
if (not FComp.GetOutput(s)) or (not FExec.LoadData(s)) then
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
if FUseDebugInfo then
|
|
|
|
begin
|
|
|
|
FComp.GetDebugOutput(s);
|
|
|
|
FExec.LoadDebugData(s);
|
|
|
|
end;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.ScriptUses(Sender: TPSPascalCompiler;
|
2008-08-01 13:23:09 +02:00
|
|
|
const Name: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
i: Longint;
|
|
|
|
begin
|
|
|
|
if Name = 'SYSTEM' then
|
|
|
|
begin
|
|
|
|
for i := 0 to FPlugins.Count -1 do
|
|
|
|
begin
|
2006-09-19 11:53:35 +02:00
|
|
|
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
|
|
|
|
TPSPluginItem(FPlugins.Items[i]).Plugin.CompOnUses(Self);
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
for i := 0 to FPlugins.Count -1 do
|
|
|
|
begin
|
2006-09-19 11:53:35 +02:00
|
|
|
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
|
|
|
|
TPSPluginItem(FPlugins.Items[i]).Plugin.CompileImport1(self);
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
DoOnCompImport;
|
|
|
|
|
|
|
|
for i := 0 to FPlugins.Count -1 do
|
|
|
|
begin
|
2006-09-19 11:53:35 +02:00
|
|
|
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
|
|
|
|
TPSPluginItem(FPlugins.Items[i]).Plugin.CompileImport2(Self);
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
DoOnCompile;
|
|
|
|
|
2009-03-19 12:02:21 +01:00
|
|
|
Result := true;
|
|
|
|
for i := 0 to Sender.MsgCount -1 do begin
|
|
|
|
if Sender.Msg[i] is TPSPascalCompilerError then Result := false;
|
|
|
|
end;
|
2006-05-30 16:23:25 +02:00
|
|
|
end
|
|
|
|
else begin
|
|
|
|
Result := DoOnUnknowUses (Sender, Name);
|
2006-08-18 10:34:39 +02:00
|
|
|
{ If Not Result then
|
|
|
|
Sender.MakeError('', ecUnknownIdentifier, Name);}
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSScript.SetCompiled(const Data: tbtstring);
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
FExec.Clear;
|
|
|
|
FExec.ClearspecialProcImports;
|
|
|
|
FExec.ClearFunctionList;
|
|
|
|
if ri <> nil then
|
|
|
|
begin
|
|
|
|
RI.Free;
|
|
|
|
RI := nil;
|
|
|
|
end;
|
|
|
|
RI := TPSRuntimeClassImporter.Create;
|
|
|
|
for i := 0 to FPlugins.Count -1 do
|
|
|
|
begin
|
2006-09-19 11:53:35 +02:00
|
|
|
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
|
|
|
|
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecImport1(Self, ri);
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
DoOnExecImport(RI);
|
|
|
|
|
|
|
|
for i := 0 to FPlugins.Count -1 do
|
|
|
|
begin
|
2006-09-19 11:53:35 +02:00
|
|
|
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
|
|
|
|
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecImport2(Self, ri);
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
RegisterClassLibraryRuntime(Exec, RI);
|
|
|
|
for i := 0 to FPlugins.Count -1 do
|
|
|
|
begin
|
2006-09-19 11:53:35 +02:00
|
|
|
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
|
|
|
|
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecOnUses(Self);
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
if not FExec.LoadData(Data) then
|
|
|
|
raise Exception.Create(GetExecErrorString);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.SetVarToInstance(const VarName: tbtstring; cl: TObject): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
p: PIFVariant;
|
|
|
|
begin
|
|
|
|
p := GetVariable(VarName);
|
|
|
|
if p <> nil then
|
|
|
|
begin
|
|
|
|
SetVariantToClass(p, cl);
|
|
|
|
result := true;
|
|
|
|
end else result := false;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.SetScript(const Value: TStrings);
|
|
|
|
begin
|
|
|
|
FScript.Assign(Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPSScript.AddMethod(Slf, Ptr: Pointer;
|
2008-08-01 13:23:09 +02:00
|
|
|
const Decl: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := AddMethodEx(Slf, Ptr, Decl, cdRegister);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.AddMethodEx(Slf, Ptr: Pointer; const Decl: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
CallingConv: TDelphiCallingConvention): Boolean;
|
|
|
|
var
|
|
|
|
P: TPSRegProc;
|
|
|
|
begin
|
|
|
|
if not FCanAdd then begin Result := False; exit; end;
|
|
|
|
p := Comp.AddDelphiFunction(Decl);
|
|
|
|
if p <> nil then
|
|
|
|
begin
|
|
|
|
Exec.RegisterDelphiMethod(Slf, Ptr, p.Name, CallingConv);
|
|
|
|
Result := True;
|
|
|
|
end else Result := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.OnLineEvent;
|
|
|
|
begin
|
|
|
|
if @FOnLine <> nil then FOnLine(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.GetRunning: Boolean;
|
|
|
|
begin
|
|
|
|
Result := FExec.Status = isRunning;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.GetExecErrorCol: Cardinal;
|
|
|
|
var
|
2008-08-01 13:23:09 +02:00
|
|
|
s: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
D1: Cardinal;
|
|
|
|
begin
|
|
|
|
if not TranslatePositionRC(Exec.ExceptionProcNo, Exec.ExceptionPos, D1, Result, s) then
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.TranslatePositionPos(Proc, Position: Cardinal;
|
2008-08-01 13:23:09 +02:00
|
|
|
var Pos: Cardinal; var fn: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
D1, D2: Cardinal;
|
|
|
|
begin
|
|
|
|
Result := Exec.TranslatePositionEx(Exec.ExceptionProcNo, Exec.ExceptionPos, Pos, D1, D2, fn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.TranslatePositionRC(Proc, Position: Cardinal;
|
2008-08-01 13:23:09 +02:00
|
|
|
var Row, Col: Cardinal; var fn: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
d1: Cardinal;
|
|
|
|
begin
|
|
|
|
Result := Exec.TranslatePositionEx(Proc, Position, d1, Row, Col, fn);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TPSScript.GetExecErrorRow: Cardinal;
|
|
|
|
var
|
|
|
|
D1: Cardinal;
|
2008-08-01 13:23:09 +02:00
|
|
|
s: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
if not TranslatePositionRC(Exec.ExceptionProcNo, Exec.ExceptionPos, Result, D1, s) then
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.Stop;
|
|
|
|
begin
|
|
|
|
if (FExec.Status = isRunning) or (Fexec.Status = isPaused) then
|
|
|
|
FExec.Stop
|
|
|
|
else
|
|
|
|
raise Exception.Create(RPS_NotRunning);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.GetProcMethod(const ProcName: tbtstring): TMethod;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := FExec.GetProcAsMethodN(ProcName)
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSScript.SetMainFileName(const Value: tbtstring);
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
FMainFileName := Value;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.GetExecErrorFileName: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
D1, D2: Cardinal;
|
|
|
|
begin
|
|
|
|
if not TranslatePositionRC(Exec.ExceptionProcNo, Exec.ExceptionPos, D1, D2, Result) then
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSScript.SetPointerToData(const VarName: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
Data: Pointer; aType: TIFTypeRec);
|
|
|
|
var
|
|
|
|
v: PIFVariant;
|
|
|
|
t: TPSVariantIFC;
|
|
|
|
begin
|
|
|
|
v := GetVariable(VarName);
|
|
|
|
if (Atype = nil) or (v = nil) then raise Exception.Create(RPS_UnableToFindVariable);
|
|
|
|
t.Dta := @PPSVariantData(v).Data;
|
|
|
|
t.aType := v.FType;
|
|
|
|
t.VarParam := false;
|
|
|
|
VNSetPointerTo(t, Data, aType);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.AddRegisteredPTRVariable(const VarName,
|
2008-08-01 13:23:09 +02:00
|
|
|
VarType: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
FVar: TPSVar;
|
|
|
|
begin
|
|
|
|
if not FCanAdd then begin Result := False; exit; end;
|
|
|
|
FVar := FComp.AddUsedVariableN(varname, vartype);
|
|
|
|
if fvar = nil then
|
|
|
|
result := False
|
|
|
|
else begin
|
|
|
|
fvar.exportname := fvar.Name;
|
|
|
|
fvar.SaveAsPointer := true;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.SetDefines(const Value: TStrings);
|
|
|
|
begin
|
|
|
|
FDefines.Assign(Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.ExecuteFunction(const Params: array of Variant;
|
2008-08-01 13:23:09 +02:00
|
|
|
const ProcName: tbtstring): Variant;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
2006-08-18 10:34:39 +02:00
|
|
|
if SuppressLoadData then
|
|
|
|
LoadExec;
|
|
|
|
|
|
|
|
DoOnExecute (RI);
|
|
|
|
|
|
|
|
FExec.DebugEnabled := FUseDebugInfo;
|
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
Result := Exec.RunProcPN(Params, ProcName);
|
2008-08-14 14:36:07 +02:00
|
|
|
|
|
|
|
DoAfterExecute;
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.FindBaseType(Bt: TPSBaseType): TPSTypeRec;
|
|
|
|
begin
|
|
|
|
Result := Exec.FindType2(Bt);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.FindNamedType(const Name: tbtstring): TPSTypeRec;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := Exec.GetTypeNo(Exec.GetType(Name));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.Notification(AComponent: TComponent;
|
|
|
|
Operation: TOperation);
|
|
|
|
var
|
|
|
|
i: Longint;
|
|
|
|
begin
|
|
|
|
inherited Notification(AComponent, Operation);
|
|
|
|
if (Operation = opRemove) and (aComponent is TPSPlugin) then
|
|
|
|
begin
|
|
|
|
for i := Plugins.Count -1 downto 0 do
|
|
|
|
begin
|
|
|
|
if (Plugins.Items[i] as TPSPluginItem).Plugin = aComponent then
|
|
|
|
{$IFDEF FPC_COL_NODELETE}
|
|
|
|
TCollectionItem(Plugins.Items[i]).Free;
|
|
|
|
{$ELSE}
|
|
|
|
Plugins.Delete(i);
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.AddNotificationVariant(const VarName: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Result := AddRegisteredVariable(VarName, '!NOTIFICATIONVARIANT');
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.DoOnProcessDirective(Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
|
2008-08-01 13:23:09 +02:00
|
|
|
const DirectiveName, DirectiveParam: tbtstring; var Continue: Boolean);
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
If Assigned (OnProcessDirective) then
|
|
|
|
OnProcessDirective (Sender, Parser, Active, DirectiveName, DirectiveParam, Continue);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.DoOnProcessUnknowDirective(Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
|
2008-08-01 13:23:09 +02:00
|
|
|
const DirectiveName, DirectiveParam: tbtstring; var Continue: Boolean);
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
If Assigned (OnProcessUnknowDirective) then
|
|
|
|
OnProcessUnknowDirective (Sender, Parser, Active, DirectiveName, DirectiveParam, Continue);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.DoOnNeedFile(Sender: TObject;
|
2008-08-01 13:23:09 +02:00
|
|
|
const OrginFileName: tbtstring; var FileName, Output: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
If Assigned (OnNeedFile) then
|
|
|
|
Result := OnNeedFile(Sender, OrginFileName, FileName, Output)
|
|
|
|
else
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.DoOnUnknowUses(Sender: TPSPascalCompiler;
|
2008-08-01 13:23:09 +02:00
|
|
|
const Name: tbtstring): Boolean;
|
2006-08-18 10:34:39 +02:00
|
|
|
var
|
|
|
|
lPrevAllowUnit: Boolean;
|
2008-08-01 13:23:09 +02:00
|
|
|
lData, lName: tbtstring;
|
2006-08-18 10:34:39 +02:00
|
|
|
begin
|
|
|
|
if assigned(FOnFindUnknownFile) then begin
|
|
|
|
lName := Name;
|
|
|
|
if FOnFindUnknownFile(self, '', lName, lData) then begin
|
|
|
|
lPrevAllowUnit := FComp.AllowUnit;
|
|
|
|
FComp.AllowUnit := true;
|
|
|
|
if FUsePreProcessor then
|
|
|
|
begin
|
|
|
|
FPP.Defines.Assign(FDefines);
|
|
|
|
Fpp.MainFile := lData;
|
|
|
|
Fpp.MainFileName := lName;
|
2007-10-22 11:13:21 +02:00
|
|
|
Fpp.PreProcess(lName, lData);
|
|
|
|
Result := FComp.Compile(lData);
|
|
|
|
Fpp.AdjustMessages(FComp);
|
2006-08-18 10:34:39 +02:00
|
|
|
end else
|
|
|
|
begin
|
|
|
|
FComp.OnTranslateLineInfo := nil;
|
|
|
|
Result := FComp.Compile(lData);
|
|
|
|
end;
|
|
|
|
FComp.AllowUnit := lPrevAllowUnit;
|
2008-09-22 08:22:49 +02:00
|
|
|
end else begin
|
|
|
|
FComp.MakeError(FComp.UnitName, ecUnknownIdentifier, lName);
|
2006-08-18 10:34:39 +02:00
|
|
|
Result := false;
|
2008-09-22 08:22:49 +02:00
|
|
|
end;
|
|
|
|
end else begin
|
|
|
|
FComp.MakeError(FComp.UnitName, ecUnknownIdentifier, lName);
|
2006-08-18 10:34:39 +02:00
|
|
|
result := false;
|
2008-09-22 08:22:49 +02:00
|
|
|
end;
|
2006-05-30 16:23:25 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.DoOnCompImport;
|
|
|
|
begin
|
|
|
|
if assigned(OnCompImport) then
|
|
|
|
OnCompImport(Self, Comp);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.DoOnCompile;
|
|
|
|
begin
|
|
|
|
if assigned(OnCompile) then
|
|
|
|
OnCompile(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.DoOnExecute;
|
|
|
|
begin
|
|
|
|
If Assigned (OnExecute) then
|
|
|
|
OnExecute (Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.DoAfterExecute;
|
|
|
|
begin
|
|
|
|
if Assigned (OnAfterExecute) then
|
|
|
|
OnAfterExecute(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScript.DoVerifyProc(Sender: TPSScript;
|
2008-08-01 13:23:09 +02:00
|
|
|
Proc: TPSInternalProcedure; const Decl: tbtstring): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
if Assigned(OnVerifyProc) then begin
|
|
|
|
Result := false;
|
|
|
|
OnVerifyProc(Sender, Proc, Decl, Result);
|
|
|
|
Result := not Result;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScript.DoOnExecImport(
|
|
|
|
RunTimeImporter: TPSRuntimeClassImporter);
|
|
|
|
begin
|
|
|
|
if assigned(OnExecImport) then
|
|
|
|
OnExecImport(Self, FExec, RunTimeImporter);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScript.DoOnGetNotificationVariant(const Name: tbtstring): Variant;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
if Not Assigned (OnGetNotificationVariant) then
|
|
|
|
raise Exception.Create(RPS_UnableToReadVariant);
|
|
|
|
Result := OnGetNotificationVariant(Self, Name);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSScript.DoOnSetNotificationVariant(const Name: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
V: Variant);
|
|
|
|
begin
|
|
|
|
if Not Assigned (OnSetNotificationVariant) then
|
|
|
|
raise Exception.Create(RPS_UnableToWriteVariant);
|
|
|
|
OnSetNotificationVariant(Self, Name, v);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TPSDllPlugin }
|
|
|
|
|
|
|
|
procedure TPSDllPlugin.CompOnUses;
|
|
|
|
begin
|
|
|
|
CompExec.Comp.OnExternalProc := DllExternalProc;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSDllPlugin.ExecOnUses;
|
|
|
|
begin
|
|
|
|
RegisterDLLRuntime(CompExec.Exec);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ TPS3DebugCompExec }
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure LineInfo(Sender: TPSDebugExec; const FileName: tbtstring; Position, Row, Col: Cardinal);
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
Dc: TPSScriptDebugger;
|
|
|
|
h, i: Longint;
|
|
|
|
bi: TPSBreakPointInfo;
|
2008-08-01 13:23:09 +02:00
|
|
|
lFileName: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Dc := Sender.Id;
|
2007-09-26 10:09:45 +02:00
|
|
|
if FileName = '' then
|
|
|
|
lFileName := dc.MainFileName
|
|
|
|
else
|
|
|
|
lFileName := FileName;
|
|
|
|
|
|
|
|
if @dc.FOnLineInfo <> nil then dc.FOnLineInfo(dc, lFileName, Position, Row, Col);
|
2006-05-30 16:23:25 +02:00
|
|
|
if row = dc.FLastRow then exit;
|
|
|
|
dc.FLastRow := row;
|
2007-09-26 10:09:45 +02:00
|
|
|
h := MakeHash(lFileName);
|
2006-05-30 16:23:25 +02:00
|
|
|
bi := nil;
|
|
|
|
for i := DC.FBreakPoints.Count -1 downto 0 do
|
|
|
|
begin
|
|
|
|
bi := Dc.FBreakpoints[i];
|
2007-09-26 10:09:45 +02:00
|
|
|
if (h = bi.FileNameHash) and (lFileName = bi.FileName) and (Cardinal(bi.Line) = Row) then
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
Bi := nil;
|
|
|
|
end;
|
|
|
|
if bi <> nil then
|
|
|
|
begin
|
2007-09-26 10:09:45 +02:00
|
|
|
if @dc.FOnBreakpoint <> nil then dc.FOnBreakpoint(dc, lFileName, Position, Row, Col);
|
2006-05-30 16:23:25 +02:00
|
|
|
dc.Pause;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure IdleCall(Sender: TPSDebugExec);
|
|
|
|
var
|
|
|
|
Dc: TPSScriptDebugger;
|
|
|
|
begin
|
|
|
|
Dc := Sender.Id;
|
|
|
|
if @dc.FOnIdle <> nil then
|
|
|
|
dc.FOnIdle(DC)
|
|
|
|
else
|
|
|
|
dc.Exec.Run;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSScriptDebugger.ClearBreakPoint(const Fn: tbtstring; Line: Integer);
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
h, i: Longint;
|
|
|
|
bi: TPSBreakPointInfo;
|
|
|
|
begin
|
|
|
|
h := MakeHash(Fn);
|
|
|
|
for i := FBreakPoints.Count -1 downto 0 do
|
|
|
|
begin
|
|
|
|
bi := FBreakpoints[i];
|
|
|
|
if (h = bi.FileNameHash) and (Fn = bi.FileName) and (bi.Line = Line) then
|
|
|
|
begin
|
|
|
|
FBreakPoints.Delete(i);
|
|
|
|
bi.Free;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScriptDebugger.ClearBreakPoints;
|
|
|
|
var
|
|
|
|
i: Longint;
|
|
|
|
begin
|
|
|
|
for i := FBreakPoints.Count -1 downto 0 do
|
|
|
|
TPSBreakPointInfo(FBreakPoints[i]).Free;
|
|
|
|
FBreakPoints.Clear;;
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TPSScriptDebugger.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
FBreakPoints := TIFList.Create;
|
|
|
|
FExec.OnSourceLine := LineInfo;
|
|
|
|
FExec.OnIdleCall := IdleCall;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TPSScriptDebugger.Destroy;
|
|
|
|
var
|
|
|
|
i: Longint;
|
|
|
|
begin
|
|
|
|
for i := FBreakPoints.Count -1 downto 0 do
|
|
|
|
begin
|
|
|
|
TPSBreakPointInfo(FBreakPoints[i]).Free;
|
|
|
|
end;
|
|
|
|
FBreakPoints.Free;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScriptDebugger.GetBreakPoint(I: Integer): TPSBreakPointInfo;
|
|
|
|
begin
|
|
|
|
Result := FBreakPoints[i];
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSScriptDebugger.GetBreakPointCount: Longint;
|
|
|
|
begin
|
|
|
|
Result := FBreakPoints.Count;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScriptDebugger.GetVarContents(const Name: tbtstring): tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
i: Longint;
|
|
|
|
pv: PIFVariant;
|
2008-08-01 13:23:09 +02:00
|
|
|
s1, s: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
s := Uppercase(Name);
|
|
|
|
if pos('.', s) > 0 then
|
|
|
|
begin
|
|
|
|
s1 := copy(s,1,pos('.', s) -1);
|
|
|
|
delete(s,1,pos('.', Name));
|
|
|
|
end else begin
|
|
|
|
s1 := s;
|
|
|
|
s := '';
|
|
|
|
end;
|
|
|
|
pv := nil;
|
|
|
|
for i := 0 to Exec.CurrentProcVars.Count -1 do
|
|
|
|
begin
|
|
|
|
if Uppercase(Exec.CurrentProcVars[i]) = s1 then
|
|
|
|
begin
|
|
|
|
pv := Exec.GetProcVar(i);
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if pv = nil then
|
|
|
|
begin
|
|
|
|
for i := 0 to Exec.CurrentProcParams.Count -1 do
|
|
|
|
begin
|
|
|
|
if Uppercase(Exec.CurrentProcParams[i]) = s1 then
|
|
|
|
begin
|
|
|
|
pv := Exec.GetProcParam(i);
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if pv = nil then
|
|
|
|
begin
|
|
|
|
for i := 0 to Exec.GlobalVarNames.Count -1 do
|
|
|
|
begin
|
|
|
|
if Uppercase(Exec.GlobalVarNames[i]) = s1 then
|
|
|
|
begin
|
|
|
|
pv := Exec.GetGlobalVar(i);
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if pv = nil then
|
|
|
|
Result := RPS_UnknownIdentifier
|
|
|
|
else
|
|
|
|
Result := PSVariantToString(NewTPSVariantIFC(pv, False), s);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
function TPSScriptDebugger.HasBreakPoint(const Fn: tbtstring; Line: Integer): Boolean;
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
h, i: Longint;
|
|
|
|
bi: TPSBreakPointInfo;
|
|
|
|
begin
|
|
|
|
h := MakeHash(Fn);
|
|
|
|
for i := FBreakPoints.Count -1 downto 0 do
|
|
|
|
begin
|
|
|
|
bi := FBreakpoints[i];
|
|
|
|
if (h = bi.FileNameHash) and (Fn = bi.FileName) and (bi.Line = Line) then
|
|
|
|
begin
|
|
|
|
Result := true;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScriptDebugger.Pause;
|
|
|
|
begin
|
|
|
|
if FExec.Status = isRunning then
|
|
|
|
FExec.Pause
|
|
|
|
else
|
|
|
|
raise Exception.Create(RPS_NotRunning);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScriptDebugger.Resume;
|
|
|
|
begin
|
|
|
|
if FExec.Status = isRunning then
|
|
|
|
FExec.Run
|
|
|
|
else
|
|
|
|
raise Exception.Create(RPS_NotRunning);
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSScriptDebugger.SetBreakPoint(const fn: tbtstring; Line: Integer);
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
|
|
|
i, h: Longint;
|
|
|
|
BI: TPSBreakPointInfo;
|
|
|
|
begin
|
|
|
|
h := MakeHash(fn);
|
|
|
|
for i := FBreakPoints.Count -1 downto 0 do
|
|
|
|
begin
|
|
|
|
bi := FBreakpoints[i];
|
|
|
|
if (h = bi.FileNameHash) and (fn = bi.FileName) and (bi.Line = Line) then
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
bi := TPSBreakPointInfo.Create;
|
|
|
|
FBreakPoints.Add(bi);
|
|
|
|
bi.FileName := fn;
|
|
|
|
bi.Line := Line;
|
|
|
|
end;
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSScriptDebugger.SetMainFileName(const Value: tbtstring);
|
2006-05-30 16:23:25 +02:00
|
|
|
var
|
2008-08-01 13:23:09 +02:00
|
|
|
OldFn: tbtstring;
|
2006-05-30 16:23:25 +02:00
|
|
|
h1, h2,i: Longint;
|
|
|
|
bi: TPSBreakPointInfo;
|
|
|
|
begin
|
|
|
|
OldFn := FMainFileName;
|
|
|
|
inherited SetMainFileName(Value);
|
|
|
|
h1 := MakeHash(OldFn);
|
|
|
|
h2 := MakeHash(Value);
|
|
|
|
if OldFn <> Value then
|
|
|
|
begin
|
|
|
|
for i := FBreakPoints.Count -1 downto 0 do
|
|
|
|
begin
|
|
|
|
bi := FBreakPoints[i];
|
|
|
|
if (bi.FileNameHash = h1) and (bi.FileName = OldFn) then
|
|
|
|
begin
|
|
|
|
bi.FFileNameHash := h2;
|
|
|
|
bi.FFileName := Value;
|
|
|
|
end else if (bi.FileNameHash = h2) and (bi.FileName = Value) then
|
|
|
|
begin
|
|
|
|
// It's already the new filename, that can't be right, so remove all the breakpoints there
|
|
|
|
FBreakPoints.Delete(i);
|
|
|
|
bi.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-09-26 10:09:45 +02:00
|
|
|
procedure TPSScriptDebugger.StepInto;
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
if (FExec.Status = isRunning) or (FExec.Status = isLoaded) then
|
|
|
|
FExec.StepInto
|
|
|
|
else
|
|
|
|
raise Exception.Create(RPS_NoScript);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSScriptDebugger.StepOver;
|
|
|
|
begin
|
|
|
|
if (FExec.Status = isRunning) or (FExec.Status = isLoaded) then
|
|
|
|
FExec.StepOver
|
|
|
|
else
|
|
|
|
raise Exception.Create(RPS_NoScript);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ TPSPluginItem }
|
|
|
|
|
|
|
|
procedure TPSPluginItem.Assign(Source: TPersistent); //Birb
|
|
|
|
begin
|
|
|
|
if Source is TPSPluginItem then
|
|
|
|
plugin:=((source as TPSPluginItem).plugin)
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSPluginItem.GetDisplayName: string;
|
|
|
|
begin
|
|
|
|
if FPlugin <> nil then
|
2008-08-01 13:23:09 +02:00
|
|
|
Result := string(FPlugin.Name)
|
2006-05-30 16:23:25 +02:00
|
|
|
else
|
|
|
|
Result := '<nil>';
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSPluginItem.SetPlugin(const Value: TPSPlugin);
|
|
|
|
begin
|
|
|
|
FPlugin := Value;
|
|
|
|
If Value <> nil then
|
|
|
|
Value.FreeNotification(TPSPlugins(Collection).FCompExec);
|
|
|
|
Changed(False);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TPSPlugins }
|
|
|
|
|
|
|
|
constructor TPSPlugins.Create(CE: TPSScript);
|
|
|
|
begin
|
|
|
|
inherited Create(TPSPluginItem);
|
|
|
|
FCompExec := CE;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TPSPlugins.GetOwner: TPersistent;
|
|
|
|
begin
|
|
|
|
Result := FCompExec;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TPSBreakPointInfo }
|
|
|
|
|
2008-08-01 13:23:09 +02:00
|
|
|
procedure TPSBreakPointInfo.SetFileName(const Value: tbtstring);
|
2006-05-30 16:23:25 +02:00
|
|
|
begin
|
|
|
|
FFileName := Value;
|
|
|
|
FFileNameHash := MakeHash(Value);
|
|
|
|
end;
|
|
|
|
|
2006-08-18 10:34:39 +02:00
|
|
|
{ TPSCustomPlugin }
|
|
|
|
procedure TPSCustumPlugin.CompileImport1(CompExec: TPSScript);
|
|
|
|
begin
|
|
|
|
IF @FOnCompileImport1 <> nil then
|
|
|
|
FOnCompileImport1(CompExec)
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSCustumPlugin.CompileImport2(CompExec: TPSScript);
|
|
|
|
begin
|
|
|
|
IF @FOnCompileImport2 <> nil then
|
|
|
|
FOnCompileImport2(CompExec)
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSCustumPlugin.CompOnUses(CompExec: TPSScript);
|
|
|
|
begin
|
|
|
|
IF @FOnCompOnUses <> nil then
|
|
|
|
FOnCompOnUses(CompExec)
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSCustumPlugin.ExecImport1(CompExec: TPSScript;
|
|
|
|
const ri: TPSRuntimeClassImporter);
|
|
|
|
begin
|
|
|
|
IF @FOnExecImport1 <> nil then
|
|
|
|
FOnExecImport1(CompExec, compExec.Exec, ri)
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSCustumPlugin.ExecImport2(CompExec: TPSScript;
|
|
|
|
const ri: TPSRuntimeClassImporter);
|
|
|
|
begin
|
|
|
|
IF @FOnExecImport2 <> nil then
|
|
|
|
FOnExecImport1(CompExec, compExec.Exec, ri)
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPSCustumPlugin.ExecOnUses(CompExec: TPSScript);
|
|
|
|
begin
|
|
|
|
IF @FOnExecOnUses <> nil then
|
|
|
|
FOnExecOnUses(CompExec)
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2006-05-30 16:23:25 +02:00
|
|
|
end.
|