codetools: record case variable is now a ctnVarDefinition, bug #18368

git-svn-id: trunk@30781 -
This commit is contained in:
mattias 2011-05-17 09:53:10 +00:00
parent a3fbf4b67c
commit 84ea3ef4f9
4 changed files with 22 additions and 45 deletions

View File

@ -114,8 +114,8 @@ const
ctnOpenArrayType = 72; ctnOpenArrayType = 72;
ctnOfConstType = 73; ctnOfConstType = 73;
ctnRecordType = 74; ctnRecordType = 74;
ctnRecordCase = 75; ctnRecordCase = 75; // children: ctnVarDefinition plus 0..n ctnRecordVariant
ctnRecordVariant = 76; ctnRecordVariant = 76; // children: 0..n ctnVarDefinition plus may be a ctnRecordCase
ctnProcedureType = 77; ctnProcedureType = 77;
ctnSetType = 78; ctnSetType = 78;
ctnRangeType = 79; ctnRangeType = 79;

View File

@ -609,8 +609,6 @@ type
Params: TFindDeclarationParams): boolean; Params: TFindDeclarationParams): boolean;
function FindIdentifierInUsedUnit(const AnUnitName: string; function FindIdentifierInUsedUnit(const AnUnitName: string;
Params: TFindDeclarationParams): boolean; Params: TFindDeclarationParams): boolean;
function FindIdentifierInRecordCase(RecordCaseNode: TCodeTreeNode;
Params: TFindDeclarationParams): boolean;
function FindIdentifierInTypeOfConstant(VarConstNode: TCodeTreeNode; function FindIdentifierInTypeOfConstant(VarConstNode: TCodeTreeNode;
Params: TFindDeclarationParams): boolean; Params: TFindDeclarationParams): boolean;
protected protected
@ -3210,10 +3208,7 @@ begin
ctnRecordCase: ctnRecordCase:
begin begin
if FindIdentifierInRecordCase(ContextNode,Params) // search in variable and variants
and CheckResult(true,true) then
exit;
// search in variants
MoveContextNodeToChilds; MoveContextNodeToChilds;
end; end;
@ -6051,32 +6046,6 @@ begin
end; end;
end; end;
function TFindDeclarationTool.FindIdentifierInRecordCase(
RecordCaseNode: TCodeTreeNode; Params: TFindDeclarationParams): boolean;
var
IdentPos: LongInt;
begin
Result:=false;
MoveCursorToNodeStart(RecordCaseNode);
ReadNextAtom;// case
ReadNextAtom;// identifier
IdentPos:=CurPos.StartPos;
ReadNextAtom;
if AtomIsChar(':')
and ((fdfCollect in Params.Flags)
or CompareSrcIdentifiers(IdentPos,Params.Identifier))
then begin
// identifier found
{$IFDEF ShowTriedContexts}
DebugLn('[TFindDeclarationTool.FindIdentifierInRecordCase] found="',GetIdentifier(Params.Identifier),'" Src=',GetIdentifier(@Src[IdentPos]));
{$ENDIF}
Params.SetResult(Self,RecordCaseNode,IdentPos);
Result:=true;
end else begin
// proceed the search normally ...
end;
end;
function TFindDeclarationTool.FindIdentifierInTypeOfConstant( function TFindDeclarationTool.FindIdentifierInTypeOfConstant(
VarConstNode: TCodeTreeNode; Params: TFindDeclarationParams): boolean; VarConstNode: TCodeTreeNode; Params: TFindDeclarationParams): boolean;
{ const a: atype = context; { const a: atype = context;

View File

@ -4299,6 +4299,8 @@ begin
case a:(b,c) of case a:(b,c) of
} }
AtomIsIdentifier(true); AtomIsIdentifier(true);
CreateChildNode;
CurNode.Desc:=ctnVarDefinition;
{$IFDEF VerboseRecordCase} {$IFDEF VerboseRecordCase}
debugln(['TPascalParserTool.KeyWordFuncTypeRecordCase case name="',GetAtom,'"']); debugln(['TPascalParserTool.KeyWordFuncTypeRecordCase case name="',GetAtom,'"']);
{$ENDIF} {$ENDIF}
@ -4331,14 +4333,22 @@ begin
end else begin end else begin
// identifier // identifier
AtomIsIdentifier(true); AtomIsIdentifier(true);
CreateChildNode;
CurNode.Desc:=ctnIdentifier;
CurNode.EndPos:=CurPos.EndPos;
ReadNextAtom; ReadNextAtom;
if CurPos.Flag=cafPoint then begin if CurPos.Flag=cafPoint then begin
ReadNextAtom; // unit.type ReadNextAtom; // unit.type
AtomIsIdentifier(true); AtomIsIdentifier(true);
CurNode.EndPos:=CurPos.EndPos;
ReadNextAtom; ReadNextAtom;
end; end;
EndChildNode; // close ctnIdentifier
end; end;
end; end;
// close ctnVarDefinition
CurNode.EndPos:=LastAtoms.GetValueAt(0).EndPos;
EndChildNode;
if not UpAtomIs('OF') then // read 'of' if not UpAtomIs('OF') then // read 'of'
RaiseStringExpectedButAtomFound('"of"'); RaiseStringExpectedButAtomFound('"of"');
// read all variants // read all variants

View File

@ -1830,18 +1830,16 @@ end;
function TPascalReaderTool.ExtractRecordCaseType(RecordCaseNode: TCodeTreeNode function TPascalReaderTool.ExtractRecordCaseType(RecordCaseNode: TCodeTreeNode
): string; ): string;
// case a:b.c of
// case a:(b,c) of
var
VarNode: TCodeTreeNode;
begin begin
MoveCursorToNodeStart(RecordCaseNode); Result:='';
ReadNextAtom;// case VarNode:=RecordCaseNode.FirstChild;
ReadNextAtom;// identifier if VarNode=nil then exit;
ReadNextAtom;// : if VarNode.FirstChild<>nil then
if AtomIsChar(':') then begin Result:=ExtractNode(RecordCaseNode.FirstChild,[]);
ReadNextAtom;
AtomIsIdentifier(true);
Result:=GetAtom;
end else begin
Result:='';
end;
end; end;
function TPascalReaderTool.GetSourceType: TCodeTreeNodeDesc; function TPascalReaderTool.GetSourceType: TCodeTreeNodeDesc;