mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-01 20:39:25 +01:00
codetools: as operator in with variables
git-svn-id: trunk@19533 -
This commit is contained in:
parent
06a31439f8
commit
de190884ee
@ -1592,7 +1592,7 @@ begin
|
||||
// find context (e.g. Button1.|)
|
||||
Params.Clear;
|
||||
Params.ContextNode:=CursorNode;
|
||||
ExprType:=FindExpressionTypeOfVariable(-1,ProcNameAtom.StartPos,Params);
|
||||
ExprType:=FindExpressionTypeOfVariable(-1,ProcNameAtom.StartPos,Params,false);
|
||||
DebugLn(['TCodeCompletionCodeTool.CompleteProcByCall ',ExprTypeToString(ExprType)]);
|
||||
|
||||
if ExprType.Desc=xtNone then begin
|
||||
|
||||
@ -618,10 +618,10 @@ type
|
||||
// expressions, operands, variables
|
||||
function GetCurrentAtomType: TVariableAtomType;
|
||||
function FindEndOfVariable(StartPos: integer;
|
||||
ExceptionIfNoVariableStart: boolean): integer;
|
||||
ExceptionIfNoVariableStart, WithAsOperator: boolean): integer;
|
||||
function FindStartOfVariable(EndPos: integer): integer;
|
||||
function FindExpressionTypeOfVariable(StartPos, EndPos: integer;
|
||||
Params: TFindDeclarationParams): TExpressionType;
|
||||
Params: TFindDeclarationParams; WithAsOperator: boolean): TExpressionType;
|
||||
function FindEndOfExpression(StartPos: integer): integer;
|
||||
function ConvertNodeToExpressionType(Node: TCodeTreeNode;
|
||||
Params: TFindDeclarationParams): TExpressionType;
|
||||
@ -2089,7 +2089,7 @@ begin
|
||||
EndPos:=CurPos.EndPos;
|
||||
end;
|
||||
Include(Params.Flags,fdfFindVariable);
|
||||
ExprType:=FindExpressionTypeOfVariable(StartPos,EndPos,Params);
|
||||
ExprType:=FindExpressionTypeOfVariable(StartPos,EndPos,Params,false);
|
||||
if (ExprType.Desc<>xtContext) then begin
|
||||
Params.SetResult(CleanFindContext);
|
||||
end;
|
||||
@ -2916,7 +2916,7 @@ begin
|
||||
EndPos:=CurPos.StartPos;
|
||||
OldFlags:=Params.Flags;
|
||||
Params.Flags:=Params.Flags-[fdfFindVariable];
|
||||
ExprType:=FindExpressionTypeOfVariable(-1,EndPos,Params);
|
||||
ExprType:=FindExpressionTypeOfVariable(-1,EndPos,Params,false);
|
||||
Params.Flags:=OldFlags;
|
||||
if (ExprType.Desc=xtContext) then
|
||||
Result:=ExprType.Context
|
||||
@ -4508,12 +4508,12 @@ begin
|
||||
{$IFDEF CheckNodeTool}CheckNodeTool(WithVarNode);{$ENDIF}
|
||||
Result:=false;
|
||||
// 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.ContextNode:=WithVarNode;
|
||||
Params.Flags:=Params.Flags*fdfGlobals
|
||||
+[fdfExceptionOnNotFound,fdfFunctionResult,fdfFindChilds];
|
||||
WithVarExpr:=FindExpressionTypeOfVariable(WithVarNode.StartPos,-1,Params);
|
||||
WithVarExpr:=FindExpressionTypeOfVariable(WithVarNode.StartPos,-1,Params,true);
|
||||
if (WithVarExpr.Desc<>xtContext)
|
||||
or (WithVarExpr.Context.Node=nil)
|
||||
or (WithVarExpr.Context.Node=OldInput.ContextNode)
|
||||
@ -5300,12 +5300,14 @@ begin
|
||||
end;
|
||||
|
||||
function TFindDeclarationTool.FindEndOfVariable(
|
||||
StartPos: integer; ExceptionIfNoVariableStart: boolean): integer;
|
||||
StartPos: integer; ExceptionIfNoVariableStart, WithAsOperator: boolean
|
||||
): integer;
|
||||
{ a variable can have the form:
|
||||
A
|
||||
A.B()^.C()[]^^.D
|
||||
(A).B
|
||||
inherited A
|
||||
A as B
|
||||
}
|
||||
procedure RaiseIdentNotFound;
|
||||
begin
|
||||
@ -5314,16 +5316,22 @@ function TFindDeclarationTool.FindEndOfVariable(
|
||||
|
||||
var
|
||||
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
|
||||
MoveCursorToCleanPos(StartPos);
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('INHERITED') then
|
||||
ReadNextAtom;
|
||||
FirstIdentifier:=true;
|
||||
if (CurPos.Flag in AllCommonAtomWords) and AtomIsIdentifier(true) then begin
|
||||
FirstIdentifier:=false;
|
||||
ReadNextAtom;
|
||||
end;
|
||||
StartVar;
|
||||
repeat
|
||||
case CurPos.Flag of
|
||||
cafRoundBracketOpen:
|
||||
@ -5346,11 +5354,16 @@ begin
|
||||
RaiseIdentNotFound;
|
||||
ReadTilBracketClose(true);
|
||||
end;
|
||||
|
||||
|
||||
else
|
||||
if AtomIsChar('^') then begin
|
||||
if FirstIdentifier and ExceptionIfNoVariableStart then
|
||||
RaiseIdentNotFound;
|
||||
end else if UpAtomIs('AS') then begin
|
||||
if not WithAsOperator then
|
||||
break;
|
||||
StartVar;
|
||||
UndoReadNextAtom;
|
||||
end else
|
||||
break;
|
||||
end;
|
||||
@ -5429,7 +5442,8 @@ begin
|
||||
end;
|
||||
|
||||
function TFindDeclarationTool.FindExpressionTypeOfVariable(
|
||||
StartPos, EndPos: integer; Params: TFindDeclarationParams): TExpressionType;
|
||||
StartPos, EndPos: integer; Params: TFindDeclarationParams;
|
||||
WithAsOperator: boolean): TExpressionType;
|
||||
{ examples
|
||||
1. A.B
|
||||
2. A().B
|
||||
@ -5440,6 +5454,7 @@ function TFindDeclarationTool.FindExpressionTypeOfVariable(
|
||||
7. (A).
|
||||
8. (A as B)
|
||||
9. (@A)
|
||||
10. A as B
|
||||
}
|
||||
type
|
||||
TIsIdentEndOfVar = (iieovYes, iieovNo, iieovUnknown);
|
||||
@ -5486,7 +5501,7 @@ var
|
||||
if StartPos<1 then
|
||||
StartPos:=FindStartOfVariable(EndPos)
|
||||
else if EndPos<1 then
|
||||
EndPos:=FindEndOfVariable(StartPos,true);
|
||||
EndPos:=FindEndOfVariable(StartPos,true,WithAsOperator);
|
||||
if (StartPos<1) then
|
||||
RaiseInternalError;
|
||||
if StartPos>SrcLen then exit;
|
||||
@ -6273,10 +6288,10 @@ begin
|
||||
or UpAtomIs('INHERITED') then begin
|
||||
// read variable
|
||||
SubStartPos:=CurPos.StartPos;
|
||||
EndPos:=FindEndOfVariable(SubStartPos,false);
|
||||
EndPos:=FindEndOfVariable(SubStartPos,false,true);
|
||||
OldFlags:=Params.Flags;
|
||||
Params.Flags:=(Params.Flags*fdfGlobals)+[fdfFunctionResult];
|
||||
Result:=FindExpressionTypeOfVariable(SubStartPos,EndPos,Params);
|
||||
Result:=FindExpressionTypeOfVariable(SubStartPos,EndPos,Params,true);
|
||||
Params.Flags:=OldFlags;
|
||||
MoveCursorToCleanPos(EndPos);
|
||||
end
|
||||
|
||||
@ -1394,7 +1394,7 @@ begin
|
||||
Params.Flags:=[fdfExceptionOnNotFound,
|
||||
fdfSearchInParentNodes,fdfSearchInAncestors];
|
||||
ExprType:=FindExpressionTypeOfVariable(ContextExprStartPos,IdentStartPos,
|
||||
Params);
|
||||
Params,false);
|
||||
//DebugLn(['TIdentCompletionTool.FindCollectionContext ',ExprTypeToString(ExprType)]);
|
||||
if (ExprType.Desc=xtContext) then begin
|
||||
GatherContext:=ExprType.Context;
|
||||
|
||||
@ -196,7 +196,7 @@ type
|
||||
CreateNodes: boolean): boolean;
|
||||
function ReadTilBlockStatementEnd(ExceptionOnNotFound: boolean): boolean;
|
||||
function ReadBackTilBlockEnd(StopOnBlockMiddlePart: boolean): boolean;
|
||||
function ReadTilVariableEnd(ExceptionOnError: boolean): boolean;
|
||||
function ReadTilVariableEnd(ExceptionOnError, WithAsOperator: boolean): boolean;
|
||||
function ReadTilStatementEnd(ExceptionOnError,
|
||||
CreateNodes: boolean): boolean;
|
||||
function ReadWithStatement(ExceptionOnError, CreateNodes: boolean): boolean;
|
||||
@ -2411,14 +2411,14 @@ begin
|
||||
end;
|
||||
|
||||
function TPascalParserTool.ReadTilVariableEnd(
|
||||
ExceptionOnError: boolean): boolean;
|
||||
ExceptionOnError, WithAsOperator: boolean): boolean;
|
||||
{ Examples:
|
||||
A
|
||||
A.B^.C[...].D(...).E
|
||||
(...).A
|
||||
@B
|
||||
inherited A
|
||||
|
||||
A as B
|
||||
}
|
||||
begin
|
||||
while AtomIsChar('@') do
|
||||
@ -2441,7 +2441,8 @@ begin
|
||||
end else
|
||||
break;
|
||||
until false;
|
||||
if (CurPos.Flag=cafPoint) or UpAtomIs('AS') then
|
||||
if (CurPos.Flag=cafPoint)
|
||||
or (WithAsOperator and UpAtomIs('AS')) then
|
||||
ReadNextAtom
|
||||
else
|
||||
break;
|
||||
@ -2520,7 +2521,7 @@ begin
|
||||
CurNode.Desc:=ctnWithVariable;
|
||||
end;
|
||||
// read til the end of the variable
|
||||
if not ReadTilVariableEnd(ExceptionOnError) then begin
|
||||
if not ReadTilVariableEnd(ExceptionOnError,true) then begin
|
||||
CloseNodes;
|
||||
Result:=false;
|
||||
exit;
|
||||
@ -2534,7 +2535,7 @@ begin
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnWithVariable
|
||||
end;
|
||||
if not ReadTilVariableEnd(ExceptionOnError) then begin
|
||||
if not ReadTilVariableEnd(ExceptionOnError,true) then begin
|
||||
CloseNodes;
|
||||
Result:=false;
|
||||
exit;
|
||||
|
||||
@ -153,6 +153,7 @@ type
|
||||
CleanPos: integer): boolean;
|
||||
function MoveCursorToParameterSpecifier(DefinitionNode: TCodeTreeNode
|
||||
): boolean;
|
||||
function FindEndOfWithVar(WithVarNode: TCodeTreeNode): integer;
|
||||
|
||||
// sections
|
||||
function GetSourceName(DoBuildTree: boolean = true): string;
|
||||
@ -1664,6 +1665,15 @@ begin
|
||||
Result:=UpAtomIs('CONST') or UpAtomIs('VAR') or UpAtomIs('OUT');
|
||||
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;
|
||||
var NamePos: TAtomPosition;
|
||||
begin
|
||||
|
||||
Loading…
Reference in New Issue
Block a user