IDE: codecontext hints: added ranged array type

git-svn-id: trunk@25533 -
This commit is contained in:
mattias 2010-05-20 10:13:19 +00:00
parent 2450332df9
commit 7029a5ebf8
2 changed files with 71 additions and 2 deletions

View File

@ -58,6 +58,8 @@ type
Attr: TProcHeadAttributes): string;
function ExtractCode(StartPos, EndPos: integer;
Attr: TProcHeadAttributes): string;
function ExtractBrackets(BracketStartPos: integer;
Attr: TProcHeadAttributes): string;
function ExtractIdentCharsFromStringConstant(
StartPos, MinPos, MaxPos, MaxLen: integer): string;
function ReadStringConstantValue(StartPos: integer): string;
@ -164,6 +166,10 @@ type
function FindEndOfWithVar(WithVarNode: TCodeTreeNode): integer;
function NodeIsIdentifierInInterface(Node: TCodeTreeNode): boolean;
// arrays
function ExtractArrayRange(ArrayNode: TCodeTreeNode;
Attr: TProcHeadAttributes): string;
// sections
function GetSourceName(DoBuildTree: boolean = true): string;
function GetSourceType: TCodeTreeNodeDesc;
@ -993,6 +999,49 @@ begin
Result:=GetExtraction(phpInUpperCase in Attr);
end;
function TPascalReaderTool.ExtractBrackets(BracketStartPos: integer;
Attr: TProcHeadAttributes): string;
function ExtractTilBracketClose(ExtractBrackets: boolean): boolean;
var
CloseBracket: TCommonAtomFlag;
First: Boolean;
begin
Result:=true;
case CurPos.Flag of
cafRoundBracketOpen: CloseBracket:=cafRoundBracketClose;
cafEdgedBracketOpen: CloseBracket:=cafEdgedBracketClose;
else exit;
end;
First:=true;
repeat
if First then
ExtractNextAtom(ExtractBrackets,Attr)
else
ExtractNextAtom(true,Attr);
if CurPos.StartPos>SrcLen then exit;
if CurPos.Flag=CloseBracket then exit(true);
if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then begin
if not ExtractTilBracketClose(true) then exit;
end;
until false;
end;
begin
Result:='';
ExtractProcHeadPos:=phepNone;
if (BracketStartPos<1) or (BracketStartPos>SrcLen) then exit;
InitExtraction;
// reparse the clean source
MoveCursorToCleanPos(BracketStartPos);
ReadNextAtom;
if not ExtractTilBracketClose(not (phpWithoutBrackets in Attr)) then exit;
if not (phpWithoutBrackets in Attr) then
ExtractNextAtom(true,Attr);
// copy memorystream to Result string
Result:=GetExtraction(phpInUpperCase in Attr);
end;
function TPascalReaderTool.ExtractPropName(PropNode: TCodeTreeNode;
InUpperCase: boolean): string;
begin
@ -1815,6 +1864,17 @@ begin
Result:=false;
end;
function TPascalReaderTool.ExtractArrayRange(ArrayNode: TCodeTreeNode;
Attr: TProcHeadAttributes): string;
begin
Result:='';
if (ArrayNode=nil) or (ArrayNode.Desc<>ctnRangedArrayType) then exit;
MoveCursorToNodeStart(ArrayNode);
if not ReadNextUpAtomIs('ARRAY') then exit;
if not ReadNextAtomIsChar('[') then exit;
Result:=ExtractBrackets(CurPos.StartPos,Attr);
end;
function TPascalReaderTool.GetSourceName(DoBuildTree: boolean): string;
var NamePos: TAtomPosition;
begin

View File

@ -297,6 +297,8 @@ procedure TCodeContextFrm.CreateHints(const CodeContexts: TCodeContextInfo);
var
Expr: TExpressionType;
Params: TFindDeclarationParams;
ExprTool: TFindDeclarationTool;
ExprNode: TCodeTreeNode;
begin
Result:=false;
Params:=TFindDeclarationParams.Create;
@ -304,10 +306,12 @@ procedure TCodeContextFrm.CreateHints(const CodeContexts: TCodeContextInfo);
try
Expr:=Tool.ConvertNodeToExpressionType(Node,Params);
if (Expr.Desc=xtContext) and (Expr.Context.Node<>nil) then begin
case Expr.Context.Node.Desc of
ExprTool:=Expr.Context.Tool;
ExprNode:=Expr.Context.Node;
case ExprNode.Desc of
ctnProcedureType:
begin
s:=s+Expr.Context.Tool.ExtractProcHead(Expr.Context.Node,
s:=s+ExprTool.ExtractProcHead(ExprNode,
[phpWithVarModifiers,phpWithParameterNames,phpWithDefaultValues,
phpWithResultType]);
Result:=true;
@ -317,6 +321,11 @@ procedure TCodeContextFrm.CreateHints(const CodeContexts: TCodeContextInfo);
s:=s+'[Index: PtrUInt]';
Result:=true;
end;
ctnRangedArrayType:
begin
s:=s+ExprTool.ExtractArrayRange(ExprNode,[]);
Result:=true;
end;
end;
end else if Expr.Desc in (xtAllStringTypes+xtAllWideStringTypes-[xtShortString])
then begin