codetools: code completion: enumeration of arrays

git-svn-id: trunk@22433 -
This commit is contained in:
mattias 2009-11-04 18:56:30 +00:00
parent 2375a8fcaf
commit ef97e3ee6b
2 changed files with 53 additions and 8 deletions

View File

@ -264,6 +264,8 @@ ResourceString
ctsResultTypeOfFunctionGetEnumeratorNotFound = 'result type of function ' ctsResultTypeOfFunctionGetEnumeratorNotFound = 'result type of function '
+'GetEnumerator not found'; +'GetEnumerator not found';
ctsPropertyCurrentNotFound = 'property Current not found'; ctsPropertyCurrentNotFound = 'property Current not found';
ctsEnumerationType = 'enumeration type';
ctsType = 'type';
implementation implementation

View File

@ -661,6 +661,8 @@ type
out ResultExprType: TExpressionType): boolean; out ResultExprType: TExpressionType): boolean;
function FindEnumerationTypeOfSetType(SetTypeNode: TCodeTreeNode; function FindEnumerationTypeOfSetType(SetTypeNode: TCodeTreeNode;
out Context: TFindContext): boolean; out Context: TFindContext): boolean;
function FindElementTypeOfArrayType(ArrayNode: TCodeTreeNode;
out ExprType: TExpressionType): boolean;
function CheckOperatorEnumerator(Params: TFindDeclarationParams; function CheckOperatorEnumerator(Params: TFindDeclarationParams;
const FoundContext: TFindContext): TIdentifierFoundResult; const FoundContext: TFindContext): TIdentifierFoundResult;
function CheckModifierEnumeratorCurrent(Params: TFindDeclarationParams; function CheckModifierEnumeratorCurrent(Params: TFindDeclarationParams;
@ -8902,13 +8904,17 @@ begin
Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,Params); Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,Params);
end; end;
ctnSetType: ctnSetType:
begin if TermExprType.Context.Tool.FindEnumerationTypeOfSetType(
if TermExprType.Context.Tool.FindEnumerationTypeOfSetType( TermExprType.Context.Node,ExprType.Context)
TermExprType.Context.Node,ExprType.Context) then begin
then begin ExprType.Desc:=xtContext;
ExprType.Desc:=xtContext; Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,Params);
Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,Params); end;
end; ctnRangedArrayType,ctnOpenArrayType:
if TermExprType.Context.Tool.FindElementTypeOfArrayType(
TermExprType.Context.Node,ExprType)
then begin
Result:=FindExprTypeAsString(ExprType,TermPos.StartPos,Params);
end; end;
else else
RaiseTermHasNoIterator; RaiseTermHasNoIterator;
@ -9169,7 +9175,9 @@ begin
if (SetTypeNode=nil) or (SetTypeNode.Desc<>ctnSetType) then exit; if (SetTypeNode=nil) or (SetTypeNode.Desc<>ctnSetType) then exit;
MoveCursorToNodeStart(SetTypeNode); MoveCursorToNodeStart(SetTypeNode);
ReadNextAtom; // set ReadNextAtom; // set
if not UpAtomIs('SET') then exit;
ReadNextAtom; // of ReadNextAtom; // of
if not UpAtomIs('OF') then exit;
ReadNextAtom; ReadNextAtom;
if not IsIdentStartChar[Src[CurPos.StartPos]] then if not IsIdentStartChar[Src[CurPos.StartPos]] then
// set of () // set of ()
@ -9187,7 +9195,7 @@ begin
or (Params.NewNode.FirstChild.Desc<>ctnEnumerationType) then begin or (Params.NewNode.FirstChild.Desc<>ctnEnumerationType) then begin
MoveCursorToCleanPos(p); MoveCursorToCleanPos(p);
ReadNextAtom; ReadNextAtom;
RaiseStringExpectedButAtomFound('enumeration type'); RaiseStringExpectedButAtomFound(ctsEnumerationType);
end; end;
Context.Tool:=Params.NewCodeTool; Context.Tool:=Params.NewCodeTool;
Context.Node:=Params.NewNode; Context.Node:=Params.NewNode;
@ -9197,6 +9205,41 @@ begin
end; end;
end; end;
function TFindDeclarationTool.FindElementTypeOfArrayType(
ArrayNode: TCodeTreeNode; out ExprType: TExpressionType): boolean;
var
Params: TFindDeclarationParams;
p: LongInt;
begin
Result:=false;
ExprType:=CleanExpressionType;
if (ArrayNode=nil) then exit;
if (ArrayNode.Desc<>ctnOpenArrayType) and (ArrayNode.Desc<>ctnRangedArrayType)
then exit;
MoveCursorToNodeStart(ArrayNode);
ReadNextAtom; // array
if not UpAtomIs('ARRAY') then exit;
ReadNextAtom; // of
if CurPos.Flag=cafEdgedBracketOpen then begin
ReadTilBracketClose(true);
ReadNextAtom;
end;
if not UpAtomIs('OF') then exit;
ReadNextAtom;
if not AtomIsIdentifier(false) then exit;
Params:=TFindDeclarationParams.Create;
try
Params.Flags:=fdfDefaultForExpressions;
Params.ContextNode:=ArrayNode;
p:=CurPos.StartPos;
Params.SetIdentifier(Self,@Src[p],nil);
ExprType:=FindExpressionResultType(Params,p,-1);
Result:=true;
finally
Params.Free;
end;
end;
function TFindDeclarationTool.CheckOperatorEnumerator( function TFindDeclarationTool.CheckOperatorEnumerator(
Params: TFindDeclarationParams; const FoundContext: TFindContext Params: TFindDeclarationParams; const FoundContext: TFindContext
): TIdentifierFoundResult; ): TIdentifierFoundResult;