codetools: parsing pointer types in terms

git-svn-id: trunk@20973 -
This commit is contained in:
mattias 2009-07-27 11:25:23 +00:00
parent b1158589de
commit 084169277d
4 changed files with 29 additions and 17 deletions

View File

@ -1495,7 +1495,7 @@ const
// find start of proc expression (e.g. Button1.Constrains.DoSomething) // find start of proc expression (e.g. Button1.Constrains.DoSomething)
IsFunction:=false; IsFunction:=false;
FuncType:=''; FuncType:='';
ProcExprStartPos:=FindStartOfTerm(ProcNameAtom.EndPos); ProcExprStartPos:=FindStartOfTerm(ProcNameAtom.EndPos,false);
if ProcExprStartPos<0 then exit; if ProcExprStartPos<0 then exit;
MoveCursorToCleanPos(ProcExprStartPos); MoveCursorToCleanPos(ProcExprStartPos);
ReadPriorAtom; ReadPriorAtom;
@ -1647,7 +1647,7 @@ begin
// find context (e.g. Button1.|) // find context (e.g. Button1.|)
Params.Clear; Params.Clear;
Params.ContextNode:=CursorNode; Params.ContextNode:=CursorNode;
ExprType:=FindExpressionTypeOfVariable(-1,ProcNameAtom.StartPos,Params,false); ExprType:=FindExpressionTypeOfTerm(-1,ProcNameAtom.StartPos,Params,false);
DebugLn(['TCodeCompletionCodeTool.CompleteProcByCall ',ExprTypeToString(ExprType)]); DebugLn(['TCodeCompletionCodeTool.CompleteProcByCall ',ExprTypeToString(ExprType)]);
if ExprType.Desc=xtNone then begin if ExprType.Desc=xtNone then begin

View File

@ -1214,7 +1214,7 @@ type
begin begin
Result:=false; Result:=false;
// find start of variable // find start of variable
VarStartPos:=FindStartOfTerm(CurPos.StartPos); VarStartPos:=FindStartOfTerm(CurPos.StartPos,false);
if (IgnoreIdentifiers<>nil) then begin if (IgnoreIdentifiers<>nil) then begin
if not CleanPosToCaret(VarStartPos,NewCodePos) then exit; if not CleanPosToCaret(VarStartPos,NewCodePos) then exit;
if IgnoreIdentifiers.Find(@NewCodePos)<>nil then exit(true); if IgnoreIdentifiers.Find(@NewCodePos)<>nil then exit(true);

View File

@ -625,8 +625,9 @@ type
function GetCurrentAtomType: TVariableAtomType; function GetCurrentAtomType: TVariableAtomType;
function FindEndOfTerm(StartPos: integer; function FindEndOfTerm(StartPos: integer;
ExceptionIfNoVariableStart, WithAsOperator: boolean): integer; ExceptionIfNoVariableStart, WithAsOperator: boolean): integer;
function FindStartOfTerm(EndPos: integer): integer; function FindStartOfTerm(EndPos: integer; InType: boolean): integer;
function FindExpressionTypeOfVariable(StartPos, EndPos: integer; function NodeTermInType(Node: TCodeTreeNode): boolean;
function FindExpressionTypeOfTerm(StartPos, EndPos: integer;
Params: TFindDeclarationParams; WithAsOperator: boolean): TExpressionType; Params: TFindDeclarationParams; WithAsOperator: boolean): TExpressionType;
function FindEndOfExpression(StartPos: integer): integer; function FindEndOfExpression(StartPos: integer): integer;
function ConvertNodeToExpressionType(Node: TCodeTreeNode; function ConvertNodeToExpressionType(Node: TCodeTreeNode;
@ -2249,7 +2250,7 @@ begin
end; end;
SkipForward:=fdfSkipClassForward in Params.Flags; SkipForward:=fdfSkipClassForward in Params.Flags;
Include(Params.Flags,fdfFindVariable); Include(Params.Flags,fdfFindVariable);
ExprType:=FindExpressionTypeOfVariable(StartPos,EndPos,Params,false); ExprType:=FindExpressionTypeOfTerm(StartPos,EndPos,Params,false);
if (ExprType.Desc<>xtContext) then begin if (ExprType.Desc<>xtContext) then begin
Params.SetResult(CleanFindContext); Params.SetResult(CleanFindContext);
end; end;
@ -3097,7 +3098,7 @@ begin
EndPos:=CurPos.StartPos; EndPos:=CurPos.StartPos;
OldFlags:=Params.Flags; OldFlags:=Params.Flags;
Params.Flags:=Params.Flags-[fdfFindVariable]; Params.Flags:=Params.Flags-[fdfFindVariable];
ExprType:=FindExpressionTypeOfVariable(-1,EndPos,Params,false); ExprType:=FindExpressionTypeOfTerm(-1,EndPos,Params,false);
Params.Flags:=OldFlags; Params.Flags:=OldFlags;
if (ExprType.Desc=xtContext) then if (ExprType.Desc=xtContext) then
Result:=ExprType.Context Result:=ExprType.Context
@ -4900,7 +4901,7 @@ begin
Params.ContextNode:=WithVarNode; Params.ContextNode:=WithVarNode;
Params.Flags:=Params.Flags*fdfGlobals Params.Flags:=Params.Flags*fdfGlobals
+[fdfExceptionOnNotFound,fdfFunctionResult,fdfFindChilds]; +[fdfExceptionOnNotFound,fdfFunctionResult,fdfFindChilds];
WithVarExpr:=FindExpressionTypeOfVariable(WithVarNode.StartPos,-1,Params,true); WithVarExpr:=FindExpressionTypeOfTerm(WithVarNode.StartPos,-1,Params,true);
if (WithVarExpr.Desc<>xtContext) if (WithVarExpr.Desc<>xtContext)
or (WithVarExpr.Context.Node=nil) or (WithVarExpr.Context.Node=nil)
or (WithVarExpr.Context.Node=OldInput.ContextNode) or (WithVarExpr.Context.Node=OldInput.ContextNode)
@ -5853,7 +5854,8 @@ begin
Result:=CurPos.EndPos; Result:=CurPos.EndPos;
end; end;
function TFindDeclarationTool.FindStartOfTerm(EndPos: integer): integer; function TFindDeclarationTool.FindStartOfTerm(EndPos: integer; InType: boolean
): integer;
{ a variable can be combinations of { a variable can be combinations of
1. A.B 1. A.B
2. A().B 2. A().B
@ -5894,6 +5896,10 @@ begin
Result:=NextAtom.StartPos; Result:=NextAtom.StartPos;
exit; exit;
end; end;
if (CurAtomType=vatUp) and InType then begin
Result:=NextAtom.StartPos;
exit;
end;
if (not (CurAtomType in [vatIdentifier,vatPreDefIdentifier,vatPoint,vatUp, if (not (CurAtomType in [vatIdentifier,vatPreDefIdentifier,vatPoint,vatUp,
vatEdgedBracketClose,vatRoundBracketClose])) vatEdgedBracketClose,vatRoundBracketClose]))
or ((CurAtomType in [vatIdentifier,vatPreDefIdentifier,vatNone]) or ((CurAtomType in [vatIdentifier,vatPreDefIdentifier,vatNone])
@ -5918,7 +5924,13 @@ begin
until false; until false;
end; end;
function TFindDeclarationTool.FindExpressionTypeOfVariable( function TFindDeclarationTool.NodeTermInType(Node: TCodeTreeNode): boolean;
begin
if Node=nil then exit(false);
Result:=not (Node.Desc in AllPascalStatements);
end;
function TFindDeclarationTool.FindExpressionTypeOfTerm(
StartPos, EndPos: integer; Params: TFindDeclarationParams; StartPos, EndPos: integer; Params: TFindDeclarationParams;
WithAsOperator: boolean): TExpressionType; WithAsOperator: boolean): TExpressionType;
{ examples { examples
@ -5976,7 +5988,7 @@ var
begin begin
Result:=false; Result:=false;
if StartPos<1 then if StartPos<1 then
StartPos:=FindStartOfTerm(EndPos) StartPos:=FindStartOfTerm(EndPos,NodeTermInType(Params.ContextNode))
else if EndPos<1 then else if EndPos<1 then
EndPos:=FindEndOfTerm(StartPos,true,WithAsOperator); EndPos:=FindEndOfTerm(StartPos,true,WithAsOperator);
if (StartPos<1) then if (StartPos<1) then
@ -6807,7 +6819,7 @@ begin
EndPos:=FindEndOfTerm(SubStartPos,false,true); EndPos:=FindEndOfTerm(SubStartPos,false,true);
OldFlags:=Params.Flags; OldFlags:=Params.Flags;
Params.Flags:=(Params.Flags*fdfGlobals)+[fdfFunctionResult]; Params.Flags:=(Params.Flags*fdfGlobals)+[fdfFunctionResult];
Result:=FindExpressionTypeOfVariable(SubStartPos,EndPos,Params,true); Result:=FindExpressionTypeOfTerm(SubStartPos,EndPos,Params,true);
Params.Flags:=OldFlags; Params.Flags:=OldFlags;
MoveCursorToCleanPos(EndPos); MoveCursorToCleanPos(EndPos);
end end

View File

@ -1516,7 +1516,7 @@ procedure TIdentCompletionTool.FindCollectionContext(
ReadPriorAtom; ReadPriorAtom;
if (CurPos.Flag=cafPoint) if (CurPos.Flag=cafPoint)
or (UpAtomIs('INHERITED')) then begin or (UpAtomIs('INHERITED')) then begin
Result:=FindStartOfTerm(IdentStartPos); Result:=FindStartOfTerm(IdentStartPos,NodeTermInType(ContextNode));
if Result<ContextNode.StartPos then if Result<ContextNode.StartPos then
Result:=ContextNode.StartPos; Result:=ContextNode.StartPos;
end else end else
@ -1568,8 +1568,8 @@ begin
fdfSearchInParentNodes,fdfSearchInAncestors]; fdfSearchInParentNodes,fdfSearchInAncestors];
if IgnoreCurContext then if IgnoreCurContext then
Params.Flags:=Params.Flags+[fdfIgnoreCurContextNode]; Params.Flags:=Params.Flags+[fdfIgnoreCurContextNode];
ExprType:=FindExpressionTypeOfVariable(ContextExprStartPos,IdentStartPos, ExprType:=FindExpressionTypeOfTerm(ContextExprStartPos,IdentStartPos,
Params,false); Params,false);
//DebugLn(['TIdentCompletionTool.FindCollectionContext ',ExprTypeToString(ExprType)]); //DebugLn(['TIdentCompletionTool.FindCollectionContext ',ExprTypeToString(ExprType)]);
if (ExprType.Desc=xtContext) then begin if (ExprType.Desc=xtContext) then begin
GatherContext:=ExprType.Context; GatherContext:=ExprType.Context;
@ -1809,7 +1809,7 @@ begin
end; end;
// context in front of // context in front of
StartPosOfVariable:=FindStartOfTerm(IdentStartPos); StartPosOfVariable:=FindStartOfTerm(IdentStartPos,NodeTermInType(CursorNode));
if StartPosOfVariable>0 then begin if StartPosOfVariable>0 then begin
if StartPosOfVariable=IdentStartPos then begin if StartPosOfVariable=IdentStartPos then begin
// cursor is at start of an operand // cursor is at start of an operand
@ -2230,7 +2230,7 @@ begin
Params:=TFindDeclarationParams.Create; Params:=TFindDeclarationParams.Create;
Params.ContextNode:=CursorNode; Params.ContextNode:=CursorNode;
Params.Flags:=fdfGlobals+fdfDefaultForExpressions; Params.Flags:=fdfGlobals+fdfDefaultForExpressions;
ExprType:=FindExpressionTypeOfVariable(CaseAtom.EndPos,EndPos,Params,true); ExprType:=FindExpressionTypeOfTerm(CaseAtom.EndPos,EndPos,Params,true);
//DebugLn(['TIdentCompletionTool.GetValuesOfCaseVariable Type=',ExprTypeToString(ExprType)]); //DebugLn(['TIdentCompletionTool.GetValuesOfCaseVariable Type=',ExprTypeToString(ExprType)]);
if ExprType.Desc=xtContext then begin if ExprType.Desc=xtContext then begin