if (VM_Count(Parameters) = 0) or (VM_GetName(Parameters, 0) <> 'SELF') then begin
FError.ErrorCode := EParameterError;
FError.ErrorPosition := -1;
exit;
end;
AddSelf;
if IntProcDefParam(Func^.Decl, -1) <> VM_Count(Parameters) - 1 then begin
FError.ErrorPosition := -1; { -1 means that the count is not the same }
FError.ErrorCode := EParameterError;
exit;
end;
end else {$ENDIF}begin
if IntProcDefParam(Func^.Decl, -1) <> VM_Count(Parameters) then begin
FError.ErrorPosition := -1; { -1 means that the count is not the same }
FError.ErrorCode := EParameterError;
exit;
end;
end;
for I := 1 to IntProcDefParam(Func^.Decl, -1) do begin
{$IFNDEF NOCLASSES}
if assigned(Func^.ClassType) then
w := Vm_Get(Parameters, I)
else
{$ENDIF}
w := Vm_Get(Parameters, I - 1);
if Pos('!', IntProcDefName(Func^.Decl, I)) = 1 then begin
if (w^.VType^.atypeid <> CSV_Var) or (not assigned(w^.CV_Var)) then begin
FError.ErrorPosition := I - 1;
FError.ErrorCode := EParameterError;
{$IFNDEF NOCLASSES}RestoreSelf;
{$ENDIF}
exit;
end;
if (PIfVariant(w^.CV_Var)^.VType <> Pointer(IntProcDefParam(Func^.Decl, I))) and not ((PTypeRec(IntProcDefParam(Func^.Decl, I))^.Ext = nil) and (PTypeRec(IntProcDefParam(Func^.Decl, I))^.atypeid = CSV_Array)) and not (PTypeRec(IntProcDefParam(Func^.Decl, I))^.atypeid = CSV_Var) then begin
FError.ErrorPosition := I - 1;
FError.ErrorCode := EParameterError;
{$IFNDEF NOCLASSES}RestoreSelf;
{$ENDIF}
exit;
end;
{$IFNDEF NOCLASSES}
if assigned(Func^.ClassType) then
VM_SetName(Parameters, I, copy(IntProcDefName(Func^.Decl, I), 2, Length(IntProcDefName(Func^.Decl, I))))
else
{$ENDIF}
VM_SetName(Parameters, I - 1, copy(IntProcDefName(Func^.Decl, I), 2, Length(IntProcDefName(Func^.Decl, I))));
end else
if Pos('^', IntProcDefName(Func^.Decl, I)) = 1 then begin
if (w^.VType^.atypeid <> CSV_Var) or (not assigned(w^.CV_Var)) then begin
FError.ErrorPosition := I - 1;
FError.ErrorCode := EParameterError;
{$IFNDEF NOCLASSES}RestoreSelf;
{$ENDIF}
exit;
end;
if (PIfVariant(w^.CV_Var)^.VType <> Pointer(IntProcDefParam(Func^.Decl, I))) and not ((PTypeRec(IntProcDefParam(Func^.Decl, I))^.Ext = nil) and (PTypeRec(IntProcDefParam(Func^.Decl, I))^.atypeid = CSV_Array))
and not (PTypeRec(IntProcDefParam(Func^.Decl, I))^.atypeid = CSV_Var) then begin
FError.ErrorPosition := I - 1;
FError.ErrorCode := EParameterError;
{$IFNDEF NOCLASSES}RestoreSelf;
{$ENDIF}
exit;
end;
{$IFNDEF NOCLASSES}
if assigned(Func^.ClassType) then
VM_SetName(Parameters, I, copy(IntProcDefName(Func^.Decl, I), 2, Length(IntProcDefName(Func^.Decl, I))))
else
{$ENDIF}
VM_SetName(Parameters, I - 1, copy(IntProcDefName(Func^.Decl, I), 2, Length(IntProcDefName(Func^.Decl, I))));
w^.Flags := w^.Flags or 1;
end else begin
if not MakeCompat(w, Pointer(IntProcDefParam(Func^.Decl, I))) then begin
FError.ErrorPosition := I - 1;
FError.ErrorCode := EParameterError;
{$IFNDEF NOCLASSES}RestoreSelf;
{$ENDIF}
exit;
end;
{$IFNDEF NOCLASSES}
if assigned(Func^.ClassType) then
VM_SetName(Parameters, I, IntProcDefName(Func^.Decl, I))
else
{$ENDIF}
VM_SetName(Parameters, I - 1, IntProcDefName(Func^.Decl, I));
end;
end; {for}
ProcStack.Add(Func);
OldVars := CurrVars;
CurrVars := Parameters;
if Func^.Mode = 0 then begin
if IntProcDefParam(Func^.Decl, 0) <> 0 then begin
w := CreateCajVariant(Pointer(IntProcDefParam(Func^.Decl, 0)));
if IntProcDefParam(Func^.Decl, -1) <> VM_Count(Parameters) - 1 then begin
FError.ErrorPosition := -1; { -1 means that the count is not the same }
DestroyCajVariant(slf);
FError.ErrorCode := EParameterError;
exit;
end;
for I := 1 to IntProcDefParam(Func^.Decl, -1) do begin
w := Vm_Get(Parameters, I);
if Pos('!', IntProcDefName(Func^.Decl, I)) = 1 then begin
if (w^.VType^.atypeid <> CSV_Var) or (not assigned(w^.CV_Var)) then begin
FError.ErrorPosition := I - 1;
FError.ErrorCode := EParameterError;
DestroyCajVariant(slf);
exit;
end;
if (PIfVariant(w^.CV_Var)^.VType <> Pointer(IntProcDefParam(Func^.Decl, I))) and not ((PTypeRec(IntProcDefParam(Func^.Decl, I))^.Ext = nil) and (PTypeRec(IntProcDefParam(Func^.Decl, I))^.atypeid = CSV_Array))
and not (PTypeRec(IntProcDefParam(Func^.Decl, I))^.atypeid = CSV_Var) then begin
FError.ErrorPosition := I - 1;
FError.ErrorCode := EParameterError;
DestroyCajVariant(slf);
exit;
end;
VM_SetName(Parameters, I, copy(IntProcDefName(Func^.Decl, I), 2, Length(IntProcDefName(Func^.Decl, I))))
end else if Pos('^', IntProcDefName(Func^.Decl, I)) = 1 then begin
if (w^.VType^.atypeid <> CSV_Var) or (not assigned(w^.CV_Var)) then begin
FError.ErrorPosition := I - 1;
FError.ErrorCode := EParameterError;
DestroyCajVariant(slf);
exit;
end;
if (PIfVariant(w^.CV_Var)^.VType <> Pointer(IntProcDefParam(Func^.Decl, I))) and not ((PTypeRec(IntProcDefParam(Func^.Decl, I))^.Ext = nil) and (PTypeRec(IntProcDefParam(Func^.Decl, I))^.atypeid = CSV_Array))
and not (PTypeRec(IntProcDefParam(Func^.Decl, I))^.atypeid = CSV_Var) then begin
FError.ErrorPosition := I - 1;
FError.ErrorCode := EParameterError;
DestroyCajVariant(slf);
exit;
end;
VM_SetName(Parameters, I, copy(IntProcDefName(Func^.Decl, I), 2, Length(IntProcDefName(Func^.Decl, I))));
w^.Flags := w^.Flags or 1;
end else begin
if not MakeCompat(w, Pointer(IntProcDefParam(Func^.Decl, I))) then begin
FError.ErrorPosition := I - 1;
FError.ErrorCode := EParameterError;
DestroyCajVariant(slf);
exit;
end;
VM_SetName(Parameters, I, IntProcDefName(Func^.Decl, I))
end;
end; {for}
ProcStack.Add(Func);
OldVars := CurrVars;
CurrVars := Parameters;
if Func^.Mode = 0 then begin
I := Parser.CurrTokenPos;
Parser.CurrTokenPos := Func^.offset;
if Parser.CurrTokenId = CSTII_Var then begin
if not ProcessVars(Parameters) then begin
DestroyCajVariant(slf);
PopProcStack;
CurrVars := OldVars;
exit;
end; {if}
end; {if}
WithList := TIfList.Create;
WithList.Add(CreateVarType(slf));
if not RunBegin(WithList, Parameters, False) then begin
function TIfPasScript.ReadParams(WithList: TIfList; ProcDef: string; Vars, Params: PVariableManager): Boolean;
{Call an internal/external Procedure}
var
w: PIfVariant;
I: Longint;
function IRem(s: string): string;
{Remove the !}
begin
Delete(s, 1, 1);
IRem := s;
end; {irem}
begin
ReadParams := False;
if (IntProcDefParam(ProcDef, -1) <> 0) and (Parser.CurrTokenId <> CSTI_OpenRound) then begin
RunError(Self, ERoundOpenExpected);
exit;
end; {if}
if (IntProcDefParam(ProcDef, -1) = 0) and (Parser.CurrTokenId = CSTI_OpenRound) then begin
Parser.Next;
if Parser.CurrTokenId = CSTI_CloseRound then begin
Parser.Next;
end else begin
RunError(Self, ECloseRoundExpected);
exit;
end;
end; {if}
if Parser.CurrTokenId = CSTI_OpenRound then begin
for I := 1 to IntProcDefParam(ProcDef, -1) do begin
Parser.Next;
if Pos('!', IntProcDefName(ProcDef, I)) = 1 then begin
{Expect a variable}
case GetIdentifier(WithList, Vars, 1, w) of
0: begin
exit;
end;
2: begin
DestroyCajVariant(w);
RunError(Self, EVariableExpected);
exit;
end;
end;
if (w^.Flags and $1) <> 0 then begin
RunError(Self, EVariableExpected);
exit;
end; {if}
w := GetVarLink(w);
if (Longint(w^.VType) <> IntProcDefParam(ProcDef, I)) and not ((PTypeRec(IntProcDefParam(ProcDef, I))^.Ext = nil) and (PTypeRec(IntProcDefParam(ProcDef, I))^.atypeid = CSV_Array)) and not (PTypeRec(IntProcDefParam(ProcDef, I))^.atypeid = CSV_Var) then begin
else if Pos('^', IntProcDefName(ProcDef, I)) = 1 then begin
{Expect a constant}
case GetIdentifier(WithList, Vars, 1, w) of
0: begin // error
exit;
end;
2: begin // created variable
w := GetVarLink(w);
if (Longint(w^.VType) <> IntProcDefParam(ProcDef, I)) and not ((PTypeRec(IntProcDefParam(ProcDef, I))^.Ext = nil) and (PTypeRec(IntProcDefParam(ProcDef, I))^.atypeid = CSV_Array))
and not (PTypeRec(IntProcDefParam(ProcDef, I))^.atypeid = CSV_Var) then begin
if (Longint(w^.VType) <> IntProcDefParam(ProcDef, I)) and not ((PTypeRec(IntProcDefParam(ProcDef, I))^.Ext = nil) and (PTypeRec(IntProcDefParam(ProcDef, I))^.atypeid = CSV_Array))
and not (PTypeRec(IntProcDefParam(ProcDef, I))^.atypeid = CSV_Var) then begin
RunError(Self, ETypeMismatch);
exit;
end;
with Vm_Add(Params, CreateCajVariant(TM_Add(Types, '', CSV_Var, nil)), IRem(IntProcDefName(ProcDef, I)))^ do begin
CV_Var := w;
Flags := 1; {readonly}
end;
end;
end;
end {if}
else begin
w := Vm_Add(Params, CreateCajVariant(Pointer(IntProcDefParam(ProcDef, I))), IntProcDefName(ProcDef, I));
if not calc(WithList, Vars, w, CSTI_CloseRound, False) then begin
exit;
end; {if}
end; {else if}
if I = IntProcDefParam(ProcDef, -1) then begin
if Parser.CurrTokenId <> CSTI_CloseRound then begin
function TIfPasScript.RunBegin(WithList: TIfList; Vars: PVariableManager; Skip: Boolean): Boolean;
{ Run the Script, this is the main part of the script engine }
var
C, c2, C3: PIfVariant;
IPos, IStart, ii, IEnd: Longint;
b: Boolean;
{$IFNDEF NOCLASSES}
NewWithList: TIfList;
{$ENDIF}
BeginMode: TBeginMode;
lBreak: Boolean;
begin
if Parser.CurrTokenId = CSTII_repeat then BeginMode := mbRepeat else
if Parser.CurrTokenId = CSTII_try then BeginMode := mbTry else
BeginMode := mbOneLiner;
Inc(FBeginNesting);
if FBeginNesting > FMaxBeginNesting then begin
Dec(FBeginNesting);
RunError(Self, EOutOfMemoryError);
RunBegin := False;
exit;
end;
if Skip then begin
if (Parser.CurrTokenId = CSTII_Begin) or (Parser.CurrTokenId = CSTII_Case) or (Parser.CurrTokenId = CSTII_repeat) or (Parser.CurrTokenId = CSTII_try) or (Parser.CurrTokenId = CSTII_Except)
or (Parser.CurrTokenId = CSTII_Finally) then begin