codetools: as operator in with variables

git-svn-id: trunk@19533 -
This commit is contained in:
mattias 2009-04-20 22:59:04 +00:00
parent 06a31439f8
commit de190884ee
5 changed files with 54 additions and 28 deletions

View File

@ -1592,7 +1592,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); ExprType:=FindExpressionTypeOfVariable(-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

@ -618,10 +618,10 @@ type
// expressions, operands, variables // expressions, operands, variables
function GetCurrentAtomType: TVariableAtomType; function GetCurrentAtomType: TVariableAtomType;
function FindEndOfVariable(StartPos: integer; function FindEndOfVariable(StartPos: integer;
ExceptionIfNoVariableStart: boolean): integer; ExceptionIfNoVariableStart, WithAsOperator: boolean): integer;
function FindStartOfVariable(EndPos: integer): integer; function FindStartOfVariable(EndPos: integer): integer;
function FindExpressionTypeOfVariable(StartPos, EndPos: integer; function FindExpressionTypeOfVariable(StartPos, EndPos: integer;
Params: TFindDeclarationParams): TExpressionType; Params: TFindDeclarationParams; WithAsOperator: boolean): TExpressionType;
function FindEndOfExpression(StartPos: integer): integer; function FindEndOfExpression(StartPos: integer): integer;
function ConvertNodeToExpressionType(Node: TCodeTreeNode; function ConvertNodeToExpressionType(Node: TCodeTreeNode;
Params: TFindDeclarationParams): TExpressionType; Params: TFindDeclarationParams): TExpressionType;
@ -2089,7 +2089,7 @@ begin
EndPos:=CurPos.EndPos; EndPos:=CurPos.EndPos;
end; end;
Include(Params.Flags,fdfFindVariable); Include(Params.Flags,fdfFindVariable);
ExprType:=FindExpressionTypeOfVariable(StartPos,EndPos,Params); ExprType:=FindExpressionTypeOfVariable(StartPos,EndPos,Params,false);
if (ExprType.Desc<>xtContext) then begin if (ExprType.Desc<>xtContext) then begin
Params.SetResult(CleanFindContext); Params.SetResult(CleanFindContext);
end; end;
@ -2916,7 +2916,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); ExprType:=FindExpressionTypeOfVariable(-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
@ -4508,12 +4508,12 @@ begin
{$IFDEF CheckNodeTool}CheckNodeTool(WithVarNode);{$ENDIF} {$IFDEF CheckNodeTool}CheckNodeTool(WithVarNode);{$ENDIF}
Result:=false; Result:=false;
// find the base type of the with variable // find the base type of the with variable
// move cursor to start of with-variable // move cursor to end of with-variable
Params.Save(OldInput); Params.Save(OldInput);
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); WithVarExpr:=FindExpressionTypeOfVariable(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)
@ -5300,12 +5300,14 @@ begin
end; end;
function TFindDeclarationTool.FindEndOfVariable( function TFindDeclarationTool.FindEndOfVariable(
StartPos: integer; ExceptionIfNoVariableStart: boolean): integer; StartPos: integer; ExceptionIfNoVariableStart, WithAsOperator: boolean
): integer;
{ a variable can have the form: { a variable can have the form:
A A
A.B()^.C()[]^^.D A.B()^.C()[]^^.D
(A).B (A).B
inherited A inherited A
A as B
} }
procedure RaiseIdentNotFound; procedure RaiseIdentNotFound;
begin begin
@ -5314,16 +5316,22 @@ function TFindDeclarationTool.FindEndOfVariable(
var var
FirstIdentifier: boolean; FirstIdentifier: boolean;
procedure StartVar;
begin
ReadNextAtom;
if UpAtomIs('INHERITED') then
ReadNextAtom;
FirstIdentifier:=true;
if (CurPos.Flag in AllCommonAtomWords) and AtomIsIdentifier(true) then begin
FirstIdentifier:=false;
ReadNextAtom;
end;
end;
begin begin
MoveCursorToCleanPos(StartPos); MoveCursorToCleanPos(StartPos);
ReadNextAtom; StartVar;
if UpAtomIs('INHERITED') then
ReadNextAtom;
FirstIdentifier:=true;
if (CurPos.Flag in AllCommonAtomWords) and AtomIsIdentifier(true) then begin
FirstIdentifier:=false;
ReadNextAtom;
end;
repeat repeat
case CurPos.Flag of case CurPos.Flag of
cafRoundBracketOpen: cafRoundBracketOpen:
@ -5346,11 +5354,16 @@ begin
RaiseIdentNotFound; RaiseIdentNotFound;
ReadTilBracketClose(true); ReadTilBracketClose(true);
end; end;
else else
if AtomIsChar('^') then begin if AtomIsChar('^') then begin
if FirstIdentifier and ExceptionIfNoVariableStart then if FirstIdentifier and ExceptionIfNoVariableStart then
RaiseIdentNotFound; RaiseIdentNotFound;
end else if UpAtomIs('AS') then begin
if not WithAsOperator then
break;
StartVar;
UndoReadNextAtom;
end else end else
break; break;
end; end;
@ -5429,7 +5442,8 @@ begin
end; end;
function TFindDeclarationTool.FindExpressionTypeOfVariable( function TFindDeclarationTool.FindExpressionTypeOfVariable(
StartPos, EndPos: integer; Params: TFindDeclarationParams): TExpressionType; StartPos, EndPos: integer; Params: TFindDeclarationParams;
WithAsOperator: boolean): TExpressionType;
{ examples { examples
1. A.B 1. A.B
2. A().B 2. A().B
@ -5440,6 +5454,7 @@ function TFindDeclarationTool.FindExpressionTypeOfVariable(
7. (A). 7. (A).
8. (A as B) 8. (A as B)
9. (@A) 9. (@A)
10. A as B
} }
type type
TIsIdentEndOfVar = (iieovYes, iieovNo, iieovUnknown); TIsIdentEndOfVar = (iieovYes, iieovNo, iieovUnknown);
@ -5486,7 +5501,7 @@ var
if StartPos<1 then if StartPos<1 then
StartPos:=FindStartOfVariable(EndPos) StartPos:=FindStartOfVariable(EndPos)
else if EndPos<1 then else if EndPos<1 then
EndPos:=FindEndOfVariable(StartPos,true); EndPos:=FindEndOfVariable(StartPos,true,WithAsOperator);
if (StartPos<1) then if (StartPos<1) then
RaiseInternalError; RaiseInternalError;
if StartPos>SrcLen then exit; if StartPos>SrcLen then exit;
@ -6273,10 +6288,10 @@ begin
or UpAtomIs('INHERITED') then begin or UpAtomIs('INHERITED') then begin
// read variable // read variable
SubStartPos:=CurPos.StartPos; SubStartPos:=CurPos.StartPos;
EndPos:=FindEndOfVariable(SubStartPos,false); EndPos:=FindEndOfVariable(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); Result:=FindExpressionTypeOfVariable(SubStartPos,EndPos,Params,true);
Params.Flags:=OldFlags; Params.Flags:=OldFlags;
MoveCursorToCleanPos(EndPos); MoveCursorToCleanPos(EndPos);
end end

View File

@ -1394,7 +1394,7 @@ begin
Params.Flags:=[fdfExceptionOnNotFound, Params.Flags:=[fdfExceptionOnNotFound,
fdfSearchInParentNodes,fdfSearchInAncestors]; fdfSearchInParentNodes,fdfSearchInAncestors];
ExprType:=FindExpressionTypeOfVariable(ContextExprStartPos,IdentStartPos, ExprType:=FindExpressionTypeOfVariable(ContextExprStartPos,IdentStartPos,
Params); 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;

View File

@ -196,7 +196,7 @@ type
CreateNodes: boolean): boolean; CreateNodes: boolean): boolean;
function ReadTilBlockStatementEnd(ExceptionOnNotFound: boolean): boolean; function ReadTilBlockStatementEnd(ExceptionOnNotFound: boolean): boolean;
function ReadBackTilBlockEnd(StopOnBlockMiddlePart: boolean): boolean; function ReadBackTilBlockEnd(StopOnBlockMiddlePart: boolean): boolean;
function ReadTilVariableEnd(ExceptionOnError: boolean): boolean; function ReadTilVariableEnd(ExceptionOnError, WithAsOperator: boolean): boolean;
function ReadTilStatementEnd(ExceptionOnError, function ReadTilStatementEnd(ExceptionOnError,
CreateNodes: boolean): boolean; CreateNodes: boolean): boolean;
function ReadWithStatement(ExceptionOnError, CreateNodes: boolean): boolean; function ReadWithStatement(ExceptionOnError, CreateNodes: boolean): boolean;
@ -2411,14 +2411,14 @@ begin
end; end;
function TPascalParserTool.ReadTilVariableEnd( function TPascalParserTool.ReadTilVariableEnd(
ExceptionOnError: boolean): boolean; ExceptionOnError, WithAsOperator: boolean): boolean;
{ Examples: { Examples:
A A
A.B^.C[...].D(...).E A.B^.C[...].D(...).E
(...).A (...).A
@B @B
inherited A inherited A
A as B
} }
begin begin
while AtomIsChar('@') do while AtomIsChar('@') do
@ -2441,7 +2441,8 @@ begin
end else end else
break; break;
until false; until false;
if (CurPos.Flag=cafPoint) or UpAtomIs('AS') then if (CurPos.Flag=cafPoint)
or (WithAsOperator and UpAtomIs('AS')) then
ReadNextAtom ReadNextAtom
else else
break; break;
@ -2520,7 +2521,7 @@ begin
CurNode.Desc:=ctnWithVariable; CurNode.Desc:=ctnWithVariable;
end; end;
// read til the end of the variable // read til the end of the variable
if not ReadTilVariableEnd(ExceptionOnError) then begin if not ReadTilVariableEnd(ExceptionOnError,true) then begin
CloseNodes; CloseNodes;
Result:=false; Result:=false;
exit; exit;
@ -2534,7 +2535,7 @@ begin
CreateChildNode; CreateChildNode;
CurNode.Desc:=ctnWithVariable CurNode.Desc:=ctnWithVariable
end; end;
if not ReadTilVariableEnd(ExceptionOnError) then begin if not ReadTilVariableEnd(ExceptionOnError,true) then begin
CloseNodes; CloseNodes;
Result:=false; Result:=false;
exit; exit;

View File

@ -153,6 +153,7 @@ type
CleanPos: integer): boolean; CleanPos: integer): boolean;
function MoveCursorToParameterSpecifier(DefinitionNode: TCodeTreeNode function MoveCursorToParameterSpecifier(DefinitionNode: TCodeTreeNode
): boolean; ): boolean;
function FindEndOfWithVar(WithVarNode: TCodeTreeNode): integer;
// sections // sections
function GetSourceName(DoBuildTree: boolean = true): string; function GetSourceName(DoBuildTree: boolean = true): string;
@ -1664,6 +1665,15 @@ begin
Result:=UpAtomIs('CONST') or UpAtomIs('VAR') or UpAtomIs('OUT'); Result:=UpAtomIs('CONST') or UpAtomIs('VAR') or UpAtomIs('OUT');
end; end;
function TPascalReaderTool.FindEndOfWithVar(WithVarNode: TCodeTreeNode
): integer;
begin
MoveCursorToCleanPos(WithVarNode.StartPos);
if not ReadTilVariableEnd(true,true) then exit(-1);
UndoReadNextAtom;
Result:=CurPos.EndPos;
end;
function TPascalReaderTool.GetSourceName(DoBuildTree: boolean): string; function TPascalReaderTool.GetSourceName(DoBuildTree: boolean): string;
var NamePos: TAtomPosition; var NamePos: TAtomPosition;
begin begin