mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-04 19:10:18 +02:00
fcl-passrc: implemented TPasAliasType.Expr for string stype
git-svn-id: trunk@36213 -
This commit is contained in:
parent
e11821f558
commit
bd9978f9cf
@ -481,6 +481,7 @@ type
|
|||||||
const Arg: Pointer); override;
|
const Arg: Pointer); override;
|
||||||
public
|
public
|
||||||
DestType: TPasType;
|
DestType: TPasType;
|
||||||
|
Expr: TPasExpr;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TPasTypeAliasType }
|
{ TPasTypeAliasType }
|
||||||
@ -2227,8 +2228,8 @@ end;
|
|||||||
|
|
||||||
destructor TPasAliasType.Destroy;
|
destructor TPasAliasType.Destroy;
|
||||||
begin
|
begin
|
||||||
if Assigned(DestType) then
|
ReleaseAndNil(TPasElement(DestType));
|
||||||
DestType.Release;
|
ReleaseAndNil(TPasElement(Expr));
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -337,6 +337,8 @@ type
|
|||||||
Function CurTokenIsIdentifier(Const S : String) : Boolean;
|
Function CurTokenIsIdentifier(Const S : String) : Boolean;
|
||||||
// Expression parsing
|
// Expression parsing
|
||||||
function isEndOfExp(AllowEqual : Boolean = False; CheckHints : Boolean = True): Boolean;
|
function isEndOfExp(AllowEqual : Boolean = False; CheckHints : Boolean = True): Boolean;
|
||||||
|
function ExprToText(Expr: TPasExpr): String;
|
||||||
|
function ArrayExprToText(Expr: TPasExprArray): String;
|
||||||
// Type declarations
|
// Type declarations
|
||||||
function ParseComplexType(Parent : TPasElement = Nil): TPasType;
|
function ParseComplexType(Parent : TPasElement = Nil): TPasType;
|
||||||
function ParseTypeDecl(Parent: TPasElement): TPasType;
|
function ParseTypeDecl(Parent: TPasElement): TPasType;
|
||||||
@ -1123,8 +1125,10 @@ function TPasParser.ParseStringType(Parent: TPasElement;
|
|||||||
const NamePos: TPasSourcePos; const TypeName: String): TPasAliasType;
|
const NamePos: TPasSourcePos; const TypeName: String): TPasAliasType;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
S : String;
|
LengthAsText : String;
|
||||||
ok: Boolean;
|
ok: Boolean;
|
||||||
|
Params: TParamsExpr;
|
||||||
|
LengthExpr: TPasExpr;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result := TPasAliasType(CreateElement(TPasAliasType, TypeName, Parent, NamePos));
|
Result := TPasAliasType(CreateElement(TPasAliasType, TypeName, Parent, NamePos));
|
||||||
@ -1132,21 +1136,25 @@ begin
|
|||||||
try
|
try
|
||||||
If (Result.Name='') then
|
If (Result.Name='') then
|
||||||
Result.Name:='string';
|
Result.Name:='string';
|
||||||
|
Result.Expr:=TPrimitiveExpr(CreateElement(TPrimitiveExpr,Result.Name,Result));
|
||||||
NextToken;
|
NextToken;
|
||||||
|
LengthAsText:='';
|
||||||
if CurToken=tkSquaredBraceOpen then
|
if CurToken=tkSquaredBraceOpen then
|
||||||
begin
|
begin
|
||||||
S:='';
|
Params:=TParamsExpr(CreateElement(TParamsExpr,'',Result));
|
||||||
|
Params.Value:=Result.Expr;
|
||||||
|
Result.Expr:=Params;
|
||||||
|
LengthAsText:='';
|
||||||
NextToken;
|
NextToken;
|
||||||
While Not (Curtoken in [tkSquaredBraceClose,tkEOF]) do
|
LengthExpr:=DoParseExpression(Result,nil,false);
|
||||||
begin
|
Params.AddParam(LengthExpr);
|
||||||
S:=S+CurTokenString;
|
CheckToken(tkSquaredBraceClose);
|
||||||
NextToken;
|
LengthAsText:=ExprToText(LengthExpr);
|
||||||
end;
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
UngetToken;
|
UngetToken;
|
||||||
Result.DestType:=TPasStringType(CreateElement(TPasStringType,'string',Parent));
|
Result.DestType:=TPasStringType(CreateElement(TPasStringType,'string',Parent));
|
||||||
TPasStringType(Result.DestType).LengthExpr:=S;
|
TPasStringType(Result.DestType).LengthExpr:=LengthAsText;
|
||||||
ok:=true;
|
ok:=true;
|
||||||
finally
|
finally
|
||||||
if not ok then
|
if not ok then
|
||||||
@ -1588,6 +1596,60 @@ begin
|
|||||||
Result:=(Curtoken=tkEqual);
|
Result:=(Curtoken=tkEqual);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPasParser.ExprToText(Expr: TPasExpr): String;
|
||||||
|
var
|
||||||
|
C: TClass;
|
||||||
|
begin
|
||||||
|
C:=Expr.ClassType;
|
||||||
|
if C=TPrimitiveExpr then
|
||||||
|
Result:=TPrimitiveExpr(Expr).Value
|
||||||
|
else if C=TSelfExpr then
|
||||||
|
Result:='self'
|
||||||
|
else if C=TBoolConstExpr then
|
||||||
|
Result:=BoolToStr(TBoolConstExpr(Expr).Value,'true','false')
|
||||||
|
else if C=TNilExpr then
|
||||||
|
Result:='nil'
|
||||||
|
else if C=TInheritedExpr then
|
||||||
|
Result:='inherited'
|
||||||
|
else if C=TUnaryExpr then
|
||||||
|
Result:=OpcodeStrings[TUnaryExpr(Expr).OpCode]+ExprToText(TUnaryExpr(Expr).Operand)
|
||||||
|
else if C=TBinaryExpr then
|
||||||
|
begin
|
||||||
|
Result:=ExprToText(TBinaryExpr(Expr).left);
|
||||||
|
if OpcodeStrings[TBinaryExpr(Expr).OpCode]<>'' then
|
||||||
|
Result:=Result+OpcodeStrings[TBinaryExpr(Expr).OpCode]
|
||||||
|
else
|
||||||
|
Result:=Result+' ';
|
||||||
|
Result:=Result+ExprToText(TBinaryExpr(Expr).right)
|
||||||
|
end
|
||||||
|
else if C=TParamsExpr then
|
||||||
|
begin
|
||||||
|
case TParamsExpr(Expr).Kind of
|
||||||
|
pekArrayParams: Result:=ExprToText(TParamsExpr(Expr).Value)
|
||||||
|
+'['+ArrayExprToText(TParamsExpr(Expr).Params)+']';
|
||||||
|
pekFuncParams: Result:=ExprToText(TParamsExpr(Expr).Value)
|
||||||
|
+'('+ArrayExprToText(TParamsExpr(Expr).Params)+')';
|
||||||
|
pekSet: Result:='['+ArrayExprToText(TParamsExpr(Expr).Params)+']';
|
||||||
|
else ParseExc(nErrUnknownOperatorType,SErrUnknownOperatorType,[ExprKindNames[TParamsExpr(Expr).Kind]]);
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ParseExc(nErrUnknownOperatorType,SErrUnknownOperatorType,['TPasParser.ExprToText: '+Expr.ClassName]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TPasParser.ArrayExprToText(Expr: TPasExprArray): String;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Result:='';
|
||||||
|
for i:=0 to length(Expr)-1 do
|
||||||
|
begin
|
||||||
|
if i>0 then
|
||||||
|
Result:=Result+',';
|
||||||
|
Result:=Result+ExprToText(Expr[i]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TPasParser.ParseParams(AParent: TPasElement; paramskind: TPasExprKind;
|
function TPasParser.ParseParams(AParent: TPasElement; paramskind: TPasExprKind;
|
||||||
AllowFormatting: Boolean = False): TParamsExpr;
|
AllowFormatting: Boolean = False): TParamsExpr;
|
||||||
var
|
var
|
||||||
|
@ -1951,7 +1951,7 @@ Var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
If isEOF then
|
If isEOF then
|
||||||
exit;
|
exit('');
|
||||||
LPos:=FPos+1;
|
LPos:=FPos+1;
|
||||||
Repeat
|
Repeat
|
||||||
Inc(FPos);
|
Inc(FPos);
|
||||||
@ -3356,7 +3356,7 @@ begin
|
|||||||
['letter',Param]);
|
['letter',Param]);
|
||||||
Value:=CondDirectiveBool[IfOpt(Param[1])];
|
Value:=CondDirectiveBool[IfOpt(Param[1])];
|
||||||
exit(true);
|
exit(true);
|
||||||
end ;
|
end;
|
||||||
// last check user hook
|
// last check user hook
|
||||||
if Assigned(OnEvalFunction) then
|
if Assigned(OnEvalFunction) then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user