IDE: codeexplorer: implemented figure empty begin blocks

git-svn-id: trunk@19522 -
This commit is contained in:
mattias 2009-04-20 13:18:23 +00:00
parent 5207898fdc
commit 76f345e29e
5 changed files with 49 additions and 15 deletions

View File

@ -3739,6 +3739,7 @@ begin
end; end;
function CodeIsOnlySpace(const ACode: string; FromPos, ToPos: integer): boolean; function CodeIsOnlySpace(const ACode: string; FromPos, ToPos: integer): boolean;
// from FromPos to including ToPos
var var
SrcLen: integer; SrcLen: integer;
CodePos: integer; CodePos: integer;

View File

@ -695,12 +695,14 @@ begin
RaiseException( RaiseException(
'TPascalParserTool.BuildSubTreeForBeginBlock: BeginNode.Desc=' 'TPascalParserTool.BuildSubTreeForBeginBlock: BeginNode.Desc='
+BeginNode.DescAsString); +BeginNode.DescAsString);
if (BeginNode.FirstChild<>nil) if (BeginNode.SubDesc and ctnsNeedJITParsing)=0 then
or ((BeginNode.SubDesc and ctnsNeedJITParsing)=0) then
// block already parsed // block already parsed
exit; exit;
// avoid endless loop // avoid endless loop
BeginNode.SubDesc:=BeginNode.SubDesc and (not ctnsNeedJITParsing); BeginNode.SubDesc:=BeginNode.SubDesc and (not ctnsNeedJITParsing);
if (BeginNode.FirstChild<>nil) then
// block already parsed
exit;
OldPhase:=CurrentPhase; OldPhase:=CurrentPhase;
CurrentPhase:=CodeToolPhaseParse; CurrentPhase:=CodeToolPhaseParse;
@ -716,13 +718,14 @@ begin
MaxPos:=SrcLen; MaxPos:=SrcLen;
repeat repeat
ReadNextAtom; ReadNextAtom;
if UpAtomIs('WITH') then if BlockStatementStartKeyWordFuncList.DoItUppercase(UpperSrc,CurPos.StartPos,
ReadWithStatement(true,true); CurPos.EndPos-CurPos.StartPos) then
if UpAtomIs('ON') then begin
if not ReadTilBlockEnd(false,true) then RaiseEndOfSourceExpected;
end else if UpAtomIs('WITH') then
ReadWithStatement(true,true)
else if UpAtomIs('ON') then
ReadOnStatement(true,true); ReadOnStatement(true,true);
if UpAtomIs('CASE') then begin
// ToDo
end;
until (CurPos.StartPos>=MaxPos); until (CurPos.StartPos>=MaxPos);
CurrentPhase:=OldPhase; CurrentPhase:=OldPhase;
except except
@ -2129,6 +2132,7 @@ function TPascalParserTool.ReadTilBlockEnd(
var BlockType: TEndBlockType; var BlockType: TEndBlockType;
TryType: TTryType; TryType: TTryType;
BlockStartPos: integer; BlockStartPos: integer;
Desc: TCodeTreeNodeDesc;
procedure SaveRaiseExceptionWithBlockStartHint(const AMessage: string); procedure SaveRaiseExceptionWithBlockStartHint(const AMessage: string);
var CaretXY: TCodeXYPosition; var CaretXY: TCodeXYPosition;
@ -2173,9 +2177,11 @@ var BlockType: TEndBlockType;
begin begin
Result:=true; Result:=true;
TryType:=ttNone; TryType:=ttNone;
if CurPos.Flag=cafBEGIN then Desc:=ctnNone;
BlockType:=ebtBegin if CurPos.Flag=cafBEGIN then begin
else if UpAtomIs('REPEAT') then BlockType:=ebtBegin;
Desc:=ctnBeginBlock;
end else if UpAtomIs('REPEAT') then
BlockType:=ebtRepeat BlockType:=ebtRepeat
else if UpAtomIs('TRY') then else if UpAtomIs('TRY') then
BlockType:=ebtTry BlockType:=ebtTry
@ -2187,6 +2193,13 @@ begin
BlockType:=ebtRecord BlockType:=ebtRecord
else else
RaiseUnknownBlockType; RaiseUnknownBlockType;
if (Desc<>ctnNone) then begin
if CreateNodes then begin
CreateChildNode;
CurNode.Desc:=Desc;
end else
Desc:=ctnNone;
end;
BlockStartPos:=CurPos.StartPos; BlockStartPos:=CurPos.StartPos;
repeat repeat
ReadNextAtom; ReadNextAtom;
@ -2202,6 +2215,10 @@ begin
RaiseStrExpectedWithBlockStartHint('"until"'); RaiseStrExpectedWithBlockStartHint('"until"');
if (BlockType=ebtTry) and (TryType=ttNone) then if (BlockType=ebtTry) and (TryType=ttNone) then
RaiseStrExpectedWithBlockStartHint('"finally"'); RaiseStrExpectedWithBlockStartHint('"finally"');
if Desc<>ctnNone then begin
CurNode.EndPos:=CurPos.EndPos;
EndChildNode;
end;
ReadNextAtom; ReadNextAtom;
if (CurPos.Flag=cafPoint) and (BlockType<>ebtBegin) then begin if (CurPos.Flag=cafPoint) and (BlockType<>ebtBegin) then begin
RaiseCharExpectedButAtomFound(';'); RaiseCharExpectedButAtomFound(';');
@ -2218,9 +2235,13 @@ begin
if (BlockType<>ebtRecord) or (not UpAtomIs('CASE')) then if (BlockType<>ebtRecord) or (not UpAtomIs('CASE')) then
ReadTilBlockEnd(false,CreateNodes); ReadTilBlockEnd(false,CreateNodes);
end else if UpAtomIs('UNTIL') then begin end else if UpAtomIs('UNTIL') then begin
if BlockType=ebtRepeat then if BlockType<>ebtRepeat then
break;
RaiseStrExpectedWithBlockStartHint('"end"'); RaiseStrExpectedWithBlockStartHint('"end"');
if Desc<>ctnNone then begin
CurNode.EndPos:=CurPos.EndPos;
EndChildNode;
end;
break;
end else if UpAtomIs('FINALLY') then begin end else if UpAtomIs('FINALLY') then begin
if (BlockType=ebtTry) and (TryType=ttNone) then begin if (BlockType=ebtTry) and (TryType=ttNone) then begin
if StopOnBlockMiddlePart then break; if StopOnBlockMiddlePart then break;

View File

@ -72,6 +72,7 @@ type
cefcEmptyProcs, // procs without code (can contain comments) cefcEmptyProcs, // procs without code (can contain comments)
cefcNestedProcs, // procs with a lot of nested sub procs cefcNestedProcs, // procs with a lot of nested sub procs
cefcUnnamedConsts, // numbers, strings in statements cefcUnnamedConsts, // numbers, strings in statements
cefcEmptyBlocks, // empty begin..end block (not even a comment)
cefcPublishedPropWithoutDefault, // published properties without default specifier cefcPublishedPropWithoutDefault, // published properties without default specifier
cefcUnsortedClassVisibility, // public,private,protected,published keywords are not sorted cefcUnsortedClassVisibility, // public,private,protected,published keywords are not sorted
cefcEmptyClassSections, // empty public,private,protected,published section cefcEmptyClassSections, // empty public,private,protected,published section
@ -206,6 +207,7 @@ const
'EmptyProcs', 'EmptyProcs',
'NestedProcs', 'NestedProcs',
'UnnamedConsts', 'UnnamedConsts',
'EmptyBlocks',
'PublishedPropWithoutDefault', 'PublishedPropWithoutDefault',
'UnsortedClassVisibility', 'UnsortedClassVisibility',
'EmptyClassSections', 'EmptyClassSections',
@ -277,6 +279,7 @@ begin
cefcEmptyProcs: Result:=lisCEEmptyProcedures; cefcEmptyProcs: Result:=lisCEEmptyProcedures;
cefcNestedProcs: Result:=lisCEManyNestedProcedures; cefcNestedProcs: Result:=lisCEManyNestedProcedures;
cefcUnnamedConsts: Result:=lisCEUnnamedConstants; cefcUnnamedConsts: Result:=lisCEUnnamedConstants;
cefcEmptyBlocks: Result:=lisCEEmptyBlocks;
cefcPublishedPropWithoutDefault: Result:=lisCEPublishedPropertyWithoutDefault; cefcPublishedPropWithoutDefault: Result:=lisCEPublishedPropertyWithoutDefault;
cefcUnsortedClassVisibility: Result:=lisCEUnsortedVisibility; cefcUnsortedClassVisibility: Result:=lisCEUnsortedVisibility;
cefcEmptyClassSections: Result:=lisCEEmptyClassSections; cefcEmptyClassSections: Result:=lisCEEmptyClassSections;

View File

@ -857,6 +857,8 @@ begin
case CodeNode.Desc of case CodeNode.Desc of
ctnBeginBlock: ctnBeginBlock:
begin begin
if (CodeNode.SubDesc and ctnsNeedJITParsing)<>0 then
Tool.BuildSubTreeForBeginBlock(CodeNode);
if (cefcLongProcs in Figures) if (cefcLongProcs in Figures)
and (CodeNode.Parent.Desc=ctnProcedure) then begin and (CodeNode.Parent.Desc=ctnProcedure) then begin
LineCnt:=LineEndCount(Tool.Src,CodeNode.StartPos,CodeNode.EndPos,i); LineCnt:=LineEndCount(Tool.Src,CodeNode.StartPos,CodeNode.EndPos,i);
@ -881,6 +883,12 @@ begin
and (not CodeNode.HasParentOfType(ctnBeginBlock)) then begin and (not CodeNode.HasParentOfType(ctnBeginBlock)) then begin
FindFigureConstants(Tool,CodeNode,CodeNode.StartPos,CodeNode.EndPos); FindFigureConstants(Tool,CodeNode,CodeNode.StartPos,CodeNode.EndPos);
end; end;
if (cefcEmptyBlocks in Figures)
and CodeIsOnlySpace(Tool.Src,CodeNode.StartPos+length('begin'),
CodeNode.EndPos-length('end')-1)
then begin
AddCodeNode(cefcEmptyBlocks,CodeNode);
end;
end; end;
ctnProcedure: ctnProcedure:

View File

@ -4165,6 +4165,7 @@ resourcestring
lisCEFigureCharConst = 'Search for unnamed char constants'; lisCEFigureCharConst = 'Search for unnamed char constants';
lisCEIgnoreFigureConstants = 'Ignore next unnamed constants'; lisCEIgnoreFigureConstants = 'Ignore next unnamed constants';
lisCEIgnoreFigConstInFuncs = 'Ignore constants in next functions'; lisCEIgnoreFigConstInFuncs = 'Ignore constants in next functions';
lisCEEmptyBlocks = 'Empty blocks';
implementation implementation