mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-29 09:00:30 +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;
|
||||
public
|
||||
DestType: TPasType;
|
||||
Expr: TPasExpr;
|
||||
end;
|
||||
|
||||
{ TPasTypeAliasType }
|
||||
@ -2227,8 +2228,8 @@ end;
|
||||
|
||||
destructor TPasAliasType.Destroy;
|
||||
begin
|
||||
if Assigned(DestType) then
|
||||
DestType.Release;
|
||||
ReleaseAndNil(TPasElement(DestType));
|
||||
ReleaseAndNil(TPasElement(Expr));
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
@ -337,6 +337,8 @@ type
|
||||
Function CurTokenIsIdentifier(Const S : String) : Boolean;
|
||||
// Expression parsing
|
||||
function isEndOfExp(AllowEqual : Boolean = False; CheckHints : Boolean = True): Boolean;
|
||||
function ExprToText(Expr: TPasExpr): String;
|
||||
function ArrayExprToText(Expr: TPasExprArray): String;
|
||||
// Type declarations
|
||||
function ParseComplexType(Parent : TPasElement = Nil): TPasType;
|
||||
function ParseTypeDecl(Parent: TPasElement): TPasType;
|
||||
@ -1123,8 +1125,10 @@ function TPasParser.ParseStringType(Parent: TPasElement;
|
||||
const NamePos: TPasSourcePos; const TypeName: String): TPasAliasType;
|
||||
|
||||
Var
|
||||
S : String;
|
||||
LengthAsText : String;
|
||||
ok: Boolean;
|
||||
Params: TParamsExpr;
|
||||
LengthExpr: TPasExpr;
|
||||
|
||||
begin
|
||||
Result := TPasAliasType(CreateElement(TPasAliasType, TypeName, Parent, NamePos));
|
||||
@ -1132,21 +1136,25 @@ begin
|
||||
try
|
||||
If (Result.Name='') then
|
||||
Result.Name:='string';
|
||||
Result.Expr:=TPrimitiveExpr(CreateElement(TPrimitiveExpr,Result.Name,Result));
|
||||
NextToken;
|
||||
LengthAsText:='';
|
||||
if CurToken=tkSquaredBraceOpen then
|
||||
begin
|
||||
S:='';
|
||||
Params:=TParamsExpr(CreateElement(TParamsExpr,'',Result));
|
||||
Params.Value:=Result.Expr;
|
||||
Result.Expr:=Params;
|
||||
LengthAsText:='';
|
||||
NextToken;
|
||||
While Not (Curtoken in [tkSquaredBraceClose,tkEOF]) do
|
||||
begin
|
||||
S:=S+CurTokenString;
|
||||
NextToken;
|
||||
end;
|
||||
LengthExpr:=DoParseExpression(Result,nil,false);
|
||||
Params.AddParam(LengthExpr);
|
||||
CheckToken(tkSquaredBraceClose);
|
||||
LengthAsText:=ExprToText(LengthExpr);
|
||||
end
|
||||
else
|
||||
UngetToken;
|
||||
Result.DestType:=TPasStringType(CreateElement(TPasStringType,'string',Parent));
|
||||
TPasStringType(Result.DestType).LengthExpr:=S;
|
||||
TPasStringType(Result.DestType).LengthExpr:=LengthAsText;
|
||||
ok:=true;
|
||||
finally
|
||||
if not ok then
|
||||
@ -1588,6 +1596,60 @@ begin
|
||||
Result:=(Curtoken=tkEqual);
|
||||
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;
|
||||
AllowFormatting: Boolean = False): TParamsExpr;
|
||||
var
|
||||
|
@ -1951,7 +1951,7 @@ Var
|
||||
|
||||
begin
|
||||
If isEOF then
|
||||
exit;
|
||||
exit('');
|
||||
LPos:=FPos+1;
|
||||
Repeat
|
||||
Inc(FPos);
|
||||
@ -3356,7 +3356,7 @@ begin
|
||||
['letter',Param]);
|
||||
Value:=CondDirectiveBool[IfOpt(Param[1])];
|
||||
exit(true);
|
||||
end ;
|
||||
end;
|
||||
// last check user hook
|
||||
if Assigned(OnEvalFunction) then
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user