base_symbol.pas
来自「Delphi脚本控件」· PAS 代码 · 共 2,415 行 · 第 1/4 页
PAS
2,415 行
MemberRec := GetMemberRec(ID, maAny);
if MemberRec = nil then
Exit;
D := MemberRec.Definition;
if D <> nil then
result := D.UserData;
end;
KindHostVar:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DV := TPaxVariableDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DV := TPaxVariableDefinition(DefList.GetRecordByIndex(- I));
end;
result := DV.UserData;
end;
KindHostConst:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DC := TPaxConstantDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DC := TPaxConstantDefinition(DefList.GetRecordByIndex(- I));
end;
result := DC.UserData;
end;
KindHostObject:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DOB := TPaxObjectDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DOB := TPaxObjectDefinition(DefList.GetRecordByIndex(- I));
end;
result := DOB.UserData;
end;
KindHostInterfaceVar:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DI := TPaxInterfaceVarDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DI := TPaxInterfaceVarDefinition(DefList.GetRecordByIndex(- I));
end;
result := DI.UserData;
end
else
if ID < 0 then
begin
D := DefinitionList[-ID];
result := D.UserData;
end;
end;
end;
function TPAXSymbolTable.GetAddressEx(ID: Integer): Pointer;
var
DV: TPaxVariableDefinition;
DC: TPaxConstantDefinition;
DOB: TPaxObjectDefinition;
DI: TPaxInterfaceVarDefinition;
I: Integer;
DefList: TPaxDefinitionList;
begin
case Kind[ID] of
KindHostVar:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DV := TPaxVariableDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DV := TPaxVariableDefinition(DefList.GetRecordByIndex(- I));
end;
result := DV.GetAddress;
end;
KindHostConst:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DC := TPaxConstantDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DC := TPaxConstantDefinition(DefList.GetRecordByIndex(- I));
end;
result := DC.GetAddress;
end;
KindHostObject:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DOB := TPaxObjectDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DOB := TPaxObjectDefinition(DefList.GetRecordByIndex(- I));
end;
result := @ DOB.DefValue;
end;
KindHostInterfaceVar:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DI := TPaxInterfaceVarDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DI := TPaxInterfaceVarDefinition(DefList.GetRecordByIndex(- I));
end;
result := @ DI.DefValue;
end
else
result := GetAddr(ID);
end;
end;
function TPAXSymbolTable.GetValue(ID: Integer): Variant;
var
Base: Variant;
SO: TPAXScriptObject;
DV: TPaxVariableDefinition;
DC: TPaxConstantDefinition;
DOB: TPaxObjectDefinition;
DI: TPaxInterfaceVarDefinition;
I: Integer;
DefList: TPaxDefinitionList;
begin
case Kind[ID] of
KindRef:
begin
Base := GetVariant(ID);
if VarIsNull(Base) or VarIsEmpty(Base) then
begin
TPaxBaseScripter(Scripter).Dump();
raise TPAXScriptFailure.Create(errIncompatibleTypes);
end;
SO := VariantToScriptObject(Base);
result := SO.GetProperty(NameIndex[ID], 0);
end;
KindHostVar:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DV := TPaxVariableDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DV := TPaxVariableDefinition(DefList.GetRecordByIndex(- I));
end;
result := DV.GetValue(Scripter);
end;
KindHostConst:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DC := TPaxConstantDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DC := TPaxConstantDefinition(DefList.GetRecordByIndex(- I));
end;
result := DC.Value;
end;
KindHostObject:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DOB := TPaxObjectDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DOB := TPaxObjectDefinition(DefList.GetRecordByIndex(- I));
end;
result := DOB.Value;
end;
KindHostInterfaceVar:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DI := TPaxInterfaceVarDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DI := TPaxInterfaceVarDefinition(DefList.GetRecordByIndex(- I));
end;
result := DI.Value;
end
else
result := GetVariant(ID);
end;
end;
procedure TPAXSymbolTable.PutValue(ID: Integer; const Val: Variant);
var
Base: Variant;
SO: TPAXScriptObject;
DV: TPaxVariableDefinition;
DOB: TPaxObjectDefinition;
I: Integer;
DefList: TPaxDefinitionList;
begin
case GetKind(ID) of
KindRef:
begin
Base := GetVariant(ID);
if VarIsNull(Base) or VarIsEmpty(Base) then
raise TPAXScriptFailure.Create(errIncompatibleTypes);
SO := VariantToScriptObject(Base);
SO.PutProperty(NameIndex[ID], Val, 0);
end;
KindHostVar:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DV := TPaxVariableDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DV := TPaxVariableDefinition(DefList.GetRecordByIndex(- I));
end;
DV.SetValue(Scripter, Val);
end;
KindHostConst:
begin
raise TPAXScriptFailure.Create(Format(errCannotWriteReadOnlyProperty, [GetName(ID)]));
end;
KindHostObject:
begin
I := GetVariant(ID);
if I > 0 then
begin
DefList := DefinitionList;
DOB := TPaxObjectDefinition(DefList[I]);
end
else
begin
DefList := TPaxBaseScripter(Scripter).LocalDefinitions;
DOB := TPaxObjectDefinition(DefList.GetRecordByIndex(- I));
end;
DOB.Value := Val;
end;
KindHostInterfaceVar:
begin
end
else
PutVariant(ID, Val);
end;
end;
procedure TPAXSymbolTable.Dump(const FileName: String);
const
V = '|';
var
T: Text;
procedure WriteLine(I: Integer);
function StrAddr: String;
begin
if A[I].Address = nil then
result := 'nil'
else
result := IntToStr(Integer(A[I].Address)-Integer(Mem));
end;
function StrLocal: String;
begin
if A[I].Local > 0 then
result := 'L'
else
result := ' ';
end;
begin
writeln( T, '' );
if I > Card then
begin
write(T, I:6);
Exit;
end;
try
with A[I] do
begin
write(T, I:5, V,
Norm(GetName(I), 12), V,
Norm(GetStrKind(I), 3), V,
StrLocal, V,
Norm(GetStrType(I), 9), ':', PType:4, V,
Misc:4, V,
Count:4, V,
Rank:2, V,
Next:5, V,
Level:5, V,
Module:2, V,
Position:5, V,
Norm(StrAddr, 8), V,
Owner:5, V,
GetStrVal(I));
end;
except
I := 0;
end;
end;
procedure Header;
begin
writeln(T,'____N', V,
' Name', V,
'Knd', V,
'L', V,
' Type', V,
'Misc', V,
' Cnt', V,
'Rn', V,
' Next', V,
'Level', V,
'Md', V,
' Pos', V,
' Addr', V,
'Owner', V,
'Value' );
end;
var
I: Integer;
begin
AssignFile(T, FileName);
Rewrite(T);
try
Header;
for I:=0 to Card do
begin
WriteLine(I);
end;
writeln(T, '');
writeln(T, '');
Header;
writeln(T, '');
writeln(T, '');
write(T, 'CreateCard ', CreateCard);
writeln(T, '');
write(T, 'MemBoundVar ', MemBoundVar);
writeln(T, '');
writeln(T, '');
writeln(T, '');
for I:=0 to NameList.Count - 1 do
begin
writeln(T, I:5, ' ', NameList[I]);
end;
finally
CloseFile(T);
end;
end;
function _GetName(NameIndex: Integer; Scripter: Pointer): String;
begin
result := TPaxBaseScripter(Scripter).NameList[NameIndex];
end;
procedure TPAXSymbolTable.SetupSubs(StartRecNo: Integer);
var
ClassRec: TPAXClassRec;
ClassList: TPAXClassList;
I: Integer;
V: Variant;
D: TPAXMethodDefinition;
J, N: Integer;
SO: TPAXScriptObject;
begin
ClassList := TPAXBaseScripter(Scripter).ClassList;
if ClassList.DelegateClassRec = nil then
raise TPAXScriptFailure.Create(Format(errClassIsNotImported, ['Delegate']));
for I:=StartRecNo to Card do
if Kind[I] = KindSUB then
begin
V := GetVariant(I);
if not IsObject(V) then
begin
D := nil;
N := V;
if N = 0 then
begin
ClassRec := ClassList.FindClass(Level[I]);
if ClassRec <> nil then
for J:=0 to ClassRec.MemberList.Count - 1 do
if ClassRec.MemberList[J].Kind = KindSUB then
if StrEql(Name[I], _GetName(ClassRec.MemberList.NameID[J], Scripter)) then
begin
D := TPaxMethodDefinition.Create(nil, Name[GetDllProcID(I)], nil,
Count[I], nil, true);
if D.LoadFromDll(Scripter, I) then
ClassRec.MemberList[J].Definition := D;
end;
end;
SO := TPAXScriptObject.Create(ClassList.DelegateClassRec);
SO.Instance := TPAXDelegate.Create(Scripter, I, N, D);
SO.PClass := TPAXDelegate;
SO.PutProperty(CreateNameIndex('Name', Scripter), Name[I], 0);
PutVariant(I, ScriptObjectToVariant(SO));
end;
end;
end;
function TPAXSymbolTable.TypeCast(TypeID: Integer; const Value: Variant): Variant;
var
C: TPaxClassRec;
SO: TPaxScriptObject;
S: String;
I: IUnknown;
begin
if (TypeID > 0) and (TypeID <= PaxTypes.Count) then
case TypeID of
typeINTEGER, typeWORD, typeSHORTINT, typeSMALLINT: result := ToInteger(Value);
typeBOOLEAN: result := ToBoolean(Value);
typeSTRING: result := ToString(Value);
typeDOUBLE, typeCARDINAL, typeINT64: result := ToNumber(Value);
end
else
begin
result := Value;
if IsObject(result) then
begin
S := GetName(TypeID);
C := TPaxBaseScripter(Scripter).ClassList.FindClassByName(S);
if C <> nil then
begin
SO := VariantToScriptObject(result);
SO.ClassRec := C;
if SO.Intf <> nil then if C.fClassDef <> nil then
begin
SO.Intf.QueryInterface(C.fClassDef.guid, I);
SO.Intf := I;
end;
end;
end;
end;
end;
function TPAXSymbolTable.IsVirtual(SubId: Integer): Boolean;
var
L: Integer;
C: TPaxClassRec;
M: TPaxMemberRec;
D: TPaxDefinition;
begin
result := false;
if SubId > 0 then
begin
if A[SubId].IsVirtual then
begin
result := true;
Exit;
end;
L := Level[SubId];
C := TPaxBaseScripter(Scripter).ClassList.FindClass(L);
if C <> nil then
begin
M := C.MemberList.GetMemberRecByID(SubId);
if M <> nil then
result := modVIRTUAL in M.ml;
end;
end
else
begin
D := DefinitionList[-SubId];
result := modVIRTUAL in D.ml;
end;
end;
function TPAXSymbolTable.NameList: TPaxNameList;
begin
result := TPaxBaseScripter(Scripter).NameList;
end;
procedure TPAXSymbolTable.InitGlobalVars;
var
I, T: Integer;
V: Variant;
begin
for I:=1 to Card do
if Kind[I] = KindVAR then
// if not IsLocal(I) then
if Pos('$', Name[I]) = 0 then
begin
V := GetVariant(I);
if VarType(V) = varEmpty then
begin
T := PType[I];
if T = typeINTEGER then
PutVariant(I, 0)
else if T = typeDOUBLE then
PutVariant(I, 0.0)
else if T = typeSTRING then
PutVariant(I, '')
else if T = typeBOOLEAN then
PutVariant(I, false);
end;
end;
end;
function TPAXSymbolTable.GetJSIndex(I: Integer): Boolean;
begin
if (I >= 1) and (I <= Card) then
result := A[I].JSIndex
else
result := false;
end;
procedure TPAXSymbolTable.SetJSIndex(I: Integer; Value: Boolean);
begin
if (I >= 1) and (I <= Card) then
A[I].JSIndex := Value;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?