mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-20 11:59:08 +02:00
codetools: TFindDeclarationTool.FindTermTypeAsString: using alias
git-svn-id: trunk@30759 -
This commit is contained in:
parent
70c510aadc
commit
a1778d544d
@ -682,7 +682,8 @@ type
|
|||||||
function FindSetOfEnumerationType(EnumNode: TCodeTreeNode): TCodeTreeNode;
|
function FindSetOfEnumerationType(EnumNode: TCodeTreeNode): TCodeTreeNode;
|
||||||
function FindPointerOfIdentifier(TypeNode: TCodeTreeNode): TCodeTreeNode;
|
function FindPointerOfIdentifier(TypeNode: TCodeTreeNode): TCodeTreeNode;
|
||||||
function FindExprTypeAsString(const ExprType: TExpressionType;
|
function FindExprTypeAsString(const ExprType: TExpressionType;
|
||||||
TermCleanPos: integer; Params: TFindDeclarationParams): string;
|
TermCleanPos: integer; Params: TFindDeclarationParams;
|
||||||
|
AliasType: PFindContext = nil): string;
|
||||||
protected
|
protected
|
||||||
function CheckSrcIdentifier(Params: TFindDeclarationParams;
|
function CheckSrcIdentifier(Params: TFindDeclarationParams;
|
||||||
const FoundContext: TFindContext): TIdentifierFoundResult;
|
const FoundContext: TFindContext): TIdentifierFoundResult;
|
||||||
@ -698,7 +699,7 @@ type
|
|||||||
var IsForward: boolean): boolean;
|
var IsForward: boolean): boolean;
|
||||||
function FindNonForwardClass(Params: TFindDeclarationParams): boolean;
|
function FindNonForwardClass(Params: TFindDeclarationParams): boolean;
|
||||||
function FindExpressionResultType(Params: TFindDeclarationParams;
|
function FindExpressionResultType(Params: TFindDeclarationParams;
|
||||||
StartPos, EndPos: integer): TExpressionType;
|
StartPos, EndPos: integer; AliasType: PFindContext = nil): TExpressionType;
|
||||||
function FindCodeToolForUsedUnit(UnitNameAtom,
|
function FindCodeToolForUsedUnit(UnitNameAtom,
|
||||||
UnitInFileAtom: TAtomPosition;
|
UnitInFileAtom: TAtomPosition;
|
||||||
ExceptionOnNotFound: boolean): TFindDeclarationTool;
|
ExceptionOnNotFound: boolean): TFindDeclarationTool;
|
||||||
@ -5322,7 +5323,8 @@ end;
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
function TFindDeclarationTool.FindExpressionResultType(
|
function TFindDeclarationTool.FindExpressionResultType(
|
||||||
Params: TFindDeclarationParams; StartPos, EndPos: integer): TExpressionType;
|
Params: TFindDeclarationParams; StartPos, EndPos: integer;
|
||||||
|
AliasType: PFindContext): TExpressionType;
|
||||||
{
|
{
|
||||||
- operators
|
- operators
|
||||||
- mixing ansistring and shortstring gives ansistring
|
- mixing ansistring and shortstring gives ansistring
|
||||||
@ -5377,13 +5379,16 @@ function TFindDeclarationTool.FindExpressionResultType(
|
|||||||
type
|
type
|
||||||
TOperandAndOperator = record
|
TOperandAndOperator = record
|
||||||
Operand: TExpressionType;
|
Operand: TExpressionType;
|
||||||
|
AliasType: TFindContext;
|
||||||
theOperator: TAtomPosition;
|
theOperator: TAtomPosition;
|
||||||
OperatorLvl: integer;
|
OperatorLvl: integer;
|
||||||
end;
|
end;
|
||||||
|
POperandAndOperator = ^TOperandAndOperator;
|
||||||
TExprStack = array[0..4] of TOperandAndOperator;
|
TExprStack = array[0..4] of TOperandAndOperator;
|
||||||
var
|
var
|
||||||
CurExprType: TExpressionType;
|
CurExprType: TExpressionType;
|
||||||
CurAliasType: TFindContext;
|
CurAliasType: PFindContext;
|
||||||
|
AliasTypeStorage: TFindContext;
|
||||||
ExprStack: TExprStack;
|
ExprStack: TExprStack;
|
||||||
StackPtr: integer;
|
StackPtr: integer;
|
||||||
|
|
||||||
@ -5450,13 +5455,20 @@ var
|
|||||||
|
|
||||||
var
|
var
|
||||||
OldFlags: TFindDeclarationFlags;
|
OldFlags: TFindDeclarationFlags;
|
||||||
|
StackEntry: POperandAndOperator;
|
||||||
begin
|
begin
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn(['[TFindDeclarationTool.FindExpressionResultType] Start',
|
DebugLn(['[TFindDeclarationTool.FindExpressionResultType] Start',
|
||||||
' Pos=',StartPos,'-',EndPos,
|
' Pos=',StartPos,'-',EndPos,
|
||||||
'="',dbgstr(Src,StartPos,EndPos-StartPos),'" Context=',Params.ContextNode.DescAsString]);
|
'="',dbgstr(Src,StartPos,EndPos-StartPos),'" Context=',Params.ContextNode.DescAsString,' Alias=',AliasType<>nil]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Result:=CleanExpressionType;
|
Result:=CleanExpressionType;
|
||||||
|
if AliasType<>nil then begin
|
||||||
|
CurAliasType:=@AliasTypeStorage;
|
||||||
|
AliasType^:=CleanFindContext;
|
||||||
|
end else begin
|
||||||
|
CurAliasType:=nil;
|
||||||
|
end;
|
||||||
OldFlags:=Params.Flags;
|
OldFlags:=Params.Flags;
|
||||||
Exclude(Params.Flags,fdfFindVariable);
|
Exclude(Params.Flags,fdfFindVariable);
|
||||||
// read the expression from left to right and calculate the type
|
// read the expression from left to right and calculate the type
|
||||||
@ -5464,7 +5476,7 @@ begin
|
|||||||
MoveCursorToCleanPos(StartPos);
|
MoveCursorToCleanPos(StartPos);
|
||||||
repeat
|
repeat
|
||||||
// read operand
|
// read operand
|
||||||
CurExprType:=ReadOperandTypeAtCursor(Params,EndPos,@CurAliasType);
|
CurExprType:=ReadOperandTypeAtCursor(Params,EndPos,CurAliasType);
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn(['[TFindDeclarationTool.FindExpressionResultType] Operand: ',
|
DebugLn(['[TFindDeclarationTool.FindExpressionResultType] Operand: ',
|
||||||
ExprTypeToString(CurExprType),' Alias=',FindContextToString(CurAliasType)]);
|
ExprTypeToString(CurExprType),' Alias=',FindContextToString(CurAliasType)]);
|
||||||
@ -5473,9 +5485,14 @@ begin
|
|||||||
inc(StackPtr);
|
inc(StackPtr);
|
||||||
if StackPtr>High(ExprStack) then
|
if StackPtr>High(ExprStack) then
|
||||||
RaiseInternalErrorStack;
|
RaiseInternalErrorStack;
|
||||||
ExprStack[StackPtr].Operand:=CurExprType;
|
StackEntry:=@ExprStack[StackPtr];
|
||||||
ExprStack[StackPtr].theOperator.StartPos:=-1;
|
StackEntry^.Operand:=CurExprType;
|
||||||
ExprStack[StackPtr].OperatorLvl:=5;
|
if CurAliasType<>nil then
|
||||||
|
StackEntry^.AliasType:=CurAliasType^
|
||||||
|
else
|
||||||
|
StackEntry^.AliasType:=CleanFindContext;
|
||||||
|
StackEntry^.theOperator.StartPos:=-1;
|
||||||
|
StackEntry^.OperatorLvl:=5;
|
||||||
// read operator
|
// read operator
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
@ -5487,6 +5504,8 @@ begin
|
|||||||
// -> execute complete stack
|
// -> execute complete stack
|
||||||
ExecuteStack(true);
|
ExecuteStack(true);
|
||||||
Result:=ExprStack[StackPtr].Operand;
|
Result:=ExprStack[StackPtr].Operand;
|
||||||
|
if AliasType<>nil then
|
||||||
|
AliasType^:=ExprStack[StackPtr].AliasType;
|
||||||
Params.Flags:=OldFlags;
|
Params.Flags:=OldFlags;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -9376,9 +9395,11 @@ var
|
|||||||
EdgedBracketsStartPos: integer;
|
EdgedBracketsStartPos: integer;
|
||||||
SetNode: TCodeTreeNode;
|
SetNode: TCodeTreeNode;
|
||||||
SetTool: TFindDeclarationTool;
|
SetTool: TFindDeclarationTool;
|
||||||
|
AliasType: TFindContext;
|
||||||
begin
|
begin
|
||||||
{$IFDEF CheckNodeTool}CheckNodeTool(CursorNode);{$ENDIF}
|
{$IFDEF CheckNodeTool}CheckNodeTool(CursorNode);{$ENDIF}
|
||||||
Result:='';
|
Result:='';
|
||||||
|
AliasType:=CleanFindContext;
|
||||||
if IsTermEdgedBracket(TermPos,EdgedBracketsStartPos) then begin
|
if IsTermEdgedBracket(TermPos,EdgedBracketsStartPos) then begin
|
||||||
// check for constant sets: [enum]
|
// check for constant sets: [enum]
|
||||||
MoveCursorToCleanPos(EdgedBracketsStartPos);
|
MoveCursorToCleanPos(EdgedBracketsStartPos);
|
||||||
@ -9416,10 +9437,11 @@ begin
|
|||||||
Params.ContextNode:=CursorNode;
|
Params.ContextNode:=CursorNode;
|
||||||
Params.Flags:=[fdfSearchInParentNodes,fdfSearchInAncestors,
|
Params.Flags:=[fdfSearchInParentNodes,fdfSearchInAncestors,
|
||||||
fdfTopLvlResolving,fdfFunctionResult];
|
fdfTopLvlResolving,fdfFunctionResult];
|
||||||
ExprType:=FindExpressionResultType(Params,TermPos.StartPos,TermPos.EndPos);
|
ExprType:=FindExpressionResultType(Params,TermPos.StartPos,TermPos.EndPos,
|
||||||
|
@AliasType);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,Params);
|
Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,Params,@AliasType);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFindDeclarationTool.FindForInTypeAsString(TermPos: TAtomPosition;
|
function TFindDeclarationTool.FindForInTypeAsString(TermPos: TAtomPosition;
|
||||||
@ -10045,7 +10067,7 @@ end;
|
|||||||
|
|
||||||
function TFindDeclarationTool.FindExprTypeAsString(
|
function TFindDeclarationTool.FindExprTypeAsString(
|
||||||
const ExprType: TExpressionType; TermCleanPos: integer;
|
const ExprType: TExpressionType; TermCleanPos: integer;
|
||||||
Params: TFindDeclarationParams): string;
|
Params: TFindDeclarationParams; AliasType: PFindContext): string;
|
||||||
|
|
||||||
procedure RaiseTermNotSimple;
|
procedure RaiseTermNotSimple;
|
||||||
begin
|
begin
|
||||||
@ -10060,9 +10082,19 @@ var
|
|||||||
ANode: TCodeTreeNode;
|
ANode: TCodeTreeNode;
|
||||||
begin
|
begin
|
||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
DebugLn('TFindDeclarationTool.FindExprTypeAsString ExprTypeToString=',
|
DebugLn('TFindDeclarationTool.FindExprTypeAsString ExprType=',
|
||||||
ExprTypeToString(ExprType));
|
ExprTypeToString(ExprType),' Alias=',FindContextToString(AliasType));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
Result:='';
|
||||||
|
if (AliasType<>nil) and (AliasType^.Node<>nil) then begin
|
||||||
|
case AliasType^.Node.Desc of
|
||||||
|
ctnTypeDefinition:
|
||||||
|
Result:=GetIdentifier(
|
||||||
|
@AliasType^.Tool.Src[AliasType^.Node.StartPos]);
|
||||||
|
end;
|
||||||
|
if Result<>'' then exit;
|
||||||
|
end;
|
||||||
|
|
||||||
case ExprType.Desc of
|
case ExprType.Desc of
|
||||||
xtNone:
|
xtNone:
|
||||||
RaiseTermNotSimple;
|
RaiseTermNotSimple;
|
||||||
@ -10228,8 +10260,8 @@ begin
|
|||||||
xtNil:
|
xtNil:
|
||||||
RaiseTermNotSimple;
|
RaiseTermNotSimple;
|
||||||
else
|
else
|
||||||
DebugLn('TCodeCompletionCodeTool.FindExprTypeAsString ExprTypeToString=',
|
DebugLn('TCodeCompletionCodeTool.FindExprTypeAsString ExprType=',
|
||||||
ExprTypeToString(ExprType));
|
ExprTypeToString(ExprType),' Alias=',FindContextToString(AliasType));
|
||||||
RaiseTermNotSimple;
|
RaiseTermNotSimple;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user