mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 07:59:28 +02:00
codetools: resolve sub identifier in type definition: search forward too
git-svn-id: trunk@34720 -
This commit is contained in:
parent
c91d3e41bf
commit
1c8d8b843e
@ -1983,7 +1983,7 @@ begin
|
||||
// for example PMapID = ^TMapID
|
||||
NewType:=TypeTool.ExtractCode(TypeNode.FirstChild.StartPos,
|
||||
TypeNode.FirstChild.EndPos,[]);
|
||||
debugln(['TCodeCompletionCodeTool.CompleteLocalVariableByParameter pointer to ',NewType]);
|
||||
//debugln(['TCodeCompletionCodeTool.CompleteLocalVariableByParameter pointer to ',NewType]);
|
||||
Params.Clear;
|
||||
Params.ContextNode:=TypeNode;
|
||||
Params.Flags:=fdfDefaultForExpressions;
|
||||
@ -1991,7 +1991,7 @@ begin
|
||||
ExprType:=TypeTool.FindExpressionResultType(Params,
|
||||
TypeNode.FirstChild.StartPos,TypeNode.FirstChild.EndPos,
|
||||
@AliasType);
|
||||
debugln(['TCodeCompletionCodeTool.CompleteLocalVariableByParameter parameter is pointer to type: AliasType=',FindContextToString(AliasType)]);
|
||||
//debugln(['TCodeCompletionCodeTool.CompleteLocalVariableByParameter parameter is pointer to type: AliasType=',FindContextToString(AliasType)]);
|
||||
end;
|
||||
end else begin
|
||||
|
||||
@ -2008,7 +2008,7 @@ begin
|
||||
//debugln(['TCodeCompletionCodeTool.CompleteLocalVariableByParameter MissingUnitName=',MissingUnitName]);
|
||||
end;
|
||||
|
||||
DebugLn('TCodeCompletionCodeTool.CompleteLocalVariableAsParameter NewType=',NewType);
|
||||
//DebugLn('TCodeCompletionCodeTool.CompleteLocalVariableAsParameter NewType=',NewType);
|
||||
if NewType='' then
|
||||
RaiseException('CompleteLocalVariableAsParameter Internal error: NewType=""');
|
||||
end;
|
||||
|
@ -6698,6 +6698,7 @@ var
|
||||
OldInput: TFindDeclarationInput;
|
||||
StartFlags: TFindDeclarationFlags;
|
||||
IsIdentEndOfVar: TIsIdentEndOfVar;
|
||||
FlagCanBeForwardDefined, FlagCanBeForwardDefinedValid: boolean;
|
||||
ExprType: TExpressionType;
|
||||
|
||||
procedure RaiseIdentExpected;
|
||||
@ -6767,6 +6768,7 @@ var
|
||||
NextAtomType:=vatSpace;
|
||||
MoveCursorToCleanPos(CurAtom.StartPos);
|
||||
IsIdentEndOfVar:=iieovUnknown;
|
||||
FlagCanBeForwardDefinedValid:=false;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
@ -6821,6 +6823,26 @@ var
|
||||
Result:=(IsIdentEndOfVar=iieovYes);
|
||||
end;
|
||||
|
||||
function CanBeForwardDefined: boolean;
|
||||
var
|
||||
Node: TCodeTreeNode;
|
||||
begin
|
||||
if not FlagCanBeForwardDefinedValid then begin
|
||||
FlagCanBeForwardDefinedValid:=true;
|
||||
FlagCanBeForwardDefined:=false;
|
||||
Node:=StartNode;
|
||||
while Node<>nil do begin
|
||||
if Node.Desc in [ctnTypeDefinition,ctnGenericType] then begin
|
||||
FlagCanBeForwardDefined:=true;
|
||||
break;
|
||||
end else if not (Node.Desc in AllPascalTypes) then
|
||||
break;
|
||||
Node:=Node.Parent;
|
||||
end;
|
||||
end;
|
||||
Result:=FlagCanBeForwardDefined;
|
||||
end;
|
||||
|
||||
procedure ResolveBaseTypeOfIdentifier;
|
||||
{ normally not the identifier is searched, but its type
|
||||
but there is one exception:
|
||||
@ -6902,6 +6924,7 @@ var
|
||||
IsStart: Boolean;
|
||||
Context: TFindContext;
|
||||
IsEnd: Boolean;
|
||||
SearchForwardToo: Boolean;
|
||||
begin
|
||||
// for example 'AnObject[3]'
|
||||
|
||||
@ -6975,9 +6998,16 @@ var
|
||||
else
|
||||
Context:=ExprType.Context;
|
||||
Params.ContextNode:=Context.Node;
|
||||
SearchForwardToo:=false;
|
||||
if Context.Node=StartNode then begin
|
||||
// there is no special context -> search in parent contexts too
|
||||
Params.Flags:=Params.Flags+[fdfSearchInParentNodes,fdfIgnoreCurContextNode];
|
||||
// check if searching forward too
|
||||
if CanBeForwardDefined then begin
|
||||
SearchForwardToo:=true;
|
||||
Params.Flags:=Params.Flags-[fdfExceptionOnNotFound]
|
||||
+[fdfIgnoreCurContextNode,fdfSearchForward];
|
||||
end;
|
||||
end else begin
|
||||
// only search in special context
|
||||
Params.Flags:=Params.Flags+[fdfIgnoreUsedUnits];
|
||||
@ -6988,13 +7018,33 @@ var
|
||||
then
|
||||
Include(Params.Flags,fdfIgnoreOverloadedProcs);
|
||||
|
||||
// search ...
|
||||
Params.SetIdentifier(Self,@Src[CurAtom.StartPos],@CheckSrcIdentifier);
|
||||
|
||||
// search ...
|
||||
{$IFDEF ShowExprEval}
|
||||
DebugLn([' FindExpressionTypeOfTerm ResolveIdentifier SubIdent="',GetIdentifier(Params.Identifier),'" ContextNode="',Params.ContextNode.DescAsString,'" "',dbgstr(Context.Tool.Src,Params.ContextNode.StartPos,15),'" ',dbgs(Params.Flags)]);
|
||||
DebugLn([' FindExpressionTypeOfTerm ResolveIdentifier backward SubIdent="',GetIdentifier(Params.Identifier),'" ContextNode="',Params.ContextNode.DescAsString,'" "',dbgstr(Context.Tool.Src,Params.ContextNode.StartPos,15),'" ',dbgs(Params.Flags)]);
|
||||
{$ENDIF}
|
||||
ExprType.Desc:=xtNone;
|
||||
// first search backwards
|
||||
if Context.Tool.FindIdentifierInContext(Params) then begin
|
||||
ExprType.Desc:=xtContext;
|
||||
end else if SearchForwardToo then begin
|
||||
// then search forwards
|
||||
Params.Load(OldInput,false);
|
||||
Params.SetIdentifier(Self,@Src[CurAtom.StartPos],@CheckSrcIdentifier);
|
||||
Params.Flags:=[fdfSearchInParentNodes,fdfExceptionOnNotFound,
|
||||
fdfIgnoreCurContextNode,fdfSearchForward]
|
||||
+(fdfGlobals*Params.Flags);
|
||||
Params.ContextNode:=Context.Node;
|
||||
{$IFDEF ShowExprEval}
|
||||
DebugLn([' FindExpressionTypeOfTerm ResolveIdentifier forward SubIdent="',GetIdentifier(Params.Identifier),'" ContextNode="',Params.ContextNode.DescAsString,'" "',dbgstr(Context.Tool.Src,Params.ContextNode.StartPos,15),'" ',dbgs(Params.Flags)]);
|
||||
{$ENDIF}
|
||||
if FindIdentifierInContext(Params) then begin
|
||||
ExprType.Desc:=xtContext;
|
||||
end;
|
||||
end;
|
||||
if ExprType.Desc=xtContext then begin
|
||||
// identifier found
|
||||
if Params.NewCodeTool.NodeIsConstructor(Params.NewNode) then begin
|
||||
// identifier is a constructor
|
||||
if (Context.Node.Desc in AllClassObjects) then begin
|
||||
|
Loading…
Reference in New Issue
Block a user