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

View File

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

View File

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

View File

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