Jedi Code Format: Shorten code by exit() with parameter instead of setting Result and then exit.

git-svn-id: trunk@64150 -
This commit is contained in:
juha 2020-11-19 22:12:51 +00:00
parent b6078f53b5
commit e994fa439c
4 changed files with 104 additions and 352 deletions

View File

@ -817,19 +817,12 @@ function TBuildTokenList.TryPunctuation(const pcToken: TSourceToken): boolean;
if (chLast = '*') and (ch <> '*') then if (chLast = '*') and (ch <> '*') then
exit; exit;
// "<<" is the start of two nested generics, // "<<" is the start of two nested generics,
// likewise '>>' is not an operator, it is two "end-of-generic" signs in sucession // likewise '>>' is not an operator, it is two "end-of-generic" signs in sucession
if (chLast = '<') and (ch = '<') then if (chLast = '<') and (ch = '<') then
begin exit(True); // <<
Result := True; // <<
exit;
end;
if (chLast = '>') and (ch = '>') then if (chLast = '>') and (ch = '>') then
begin exit(True); // >>
Result := True; // >>
exit;
end;
Result := CharIsPuncChar(ch); Result := CharIsPuncChar(ch);
end; end;
@ -840,7 +833,6 @@ var
lcLast: Char; lcLast: Char;
begin begin
Result := False; Result := False;
if not CharIsPuncChar(Current) then if not CharIsPuncChar(Current) then
exit; exit;
@ -876,7 +868,6 @@ end;
function TBuildTokenList.TrySingleCharToken(const pcToken: TSourceToken): boolean; function TBuildTokenList.TrySingleCharToken(const pcToken: TSourceToken): boolean;
begin begin
Result := False; Result := False;
pcToken.TokenType := TypeOfToken(Current); pcToken.TokenType := TypeOfToken(Current);
if pcToken.TokenType <> ttUnknown then if pcToken.TokenType <> ttUnknown then
begin begin

View File

@ -77,64 +77,31 @@ const
function SemicolonHasReturn(const pt, ptNext: TSourceToken): boolean; function SemicolonHasReturn(const pt, ptNext: TSourceToken): boolean;
begin begin
Result := True; Result := True;
{ point 1 } { point 1 }
if (ptNext.HasParentNode(nProcedureDirectives)) then if ptNext.HasParentNode(nProcedureDirectives) then
begin exit(False);
Result := False; { point 1b }
exit; if ptNext.HasParentNode(nHintDirectives) then
end; exit(False);
{ point 1b }
if (ptNext.HasParentNode(nHintDirectives)) then
begin
Result := False;
exit;
end;
{ point 2. to avoid the return, { point 2. to avoid the return,
the next token must still be in the same property} the next token must still be in the same property}
if ptNext.HasParentNode(nProperty) and (ptNext.TokenType <> ttProperty) then if ptNext.HasParentNode(nProperty) and (ptNext.TokenType <> ttProperty) then
begin exit(False);
Result := False;
exit;
end;
{ point 3 } { point 3 }
if pt.HasParentNode(nRecordConstant) then if pt.HasParentNode(nRecordConstant) then
begin exit(False);
Result := False;
exit;
end;
{ point 4 } { point 4 }
if (pt.HasParentNode(nFormalParams)) then if (pt.HasParentNode(nFormalParams)) then
begin exit(False);
Result := False;
exit;
end;
{ point 4, for a procedure type def } { point 4, for a procedure type def }
if pt.HasParentNode(nProcedureType) then if pt.HasParentNode(nProcedureType) then
begin exit(False);
Result := False;
exit;
end;
{ in a record type def } { in a record type def }
if pt.HasParentNode(nRecordType) then if pt.HasParentNode(nRecordType) then
begin exit(True);
Result := True;
exit;
end;
{ in generic definition} { in generic definition}
if pt.HasParentNode(nGeneric,2) then if pt.HasParentNode(nGeneric,2) then
begin exit(False);
Result := False;
exit;
end;
end; end;
@ -171,7 +138,6 @@ begin
lcParent := lcParent.Parent; lcParent := lcParent.Parent;
if (lcParent = nil) or (lcParent.NodeType <> nBlock) then if (lcParent = nil) or (lcParent.NodeType <> nBlock) then
exit; exit;
@ -192,40 +158,27 @@ begin
exit; exit;
if pt.HasParentNode(nAsm) then if pt.HasParentNode(nAsm) then
begin
exit; exit;
end;
// form dfm comment // form dfm comment
if IsDfmIncludeDirective(pt) then if IsDfmIncludeDirective(pt) then
begin exit(True);
Result := True;
exit;
end;
if (pt.TokenType in WordsBlankLineAfter) then if (pt.TokenType in WordsBlankLineAfter) then
begin exit(True);
Result := True;
exit;
end;
{ 'interface', but not as a typedef, but as the section } { 'interface', but not as a typedef, but as the section }
if (pt.TokenType = ttInterface) and pt.HasParentNode(nInterfaceSection, 1) then if (pt.TokenType = ttInterface) and pt.HasParentNode(nInterfaceSection, 1) then
begin exit(True);
Result := True;
exit;
end;
{ semicolon that ends a proc or is between procs e.g. end of uses clause } { semicolon that ends a proc or is between procs e.g. end of uses clause }
if (pt.TokenType = ttSemiColon) then if (pt.TokenType = ttSemiColon) then
begin begin
if ( not pt.HasParentNode(ProcedureNodes)) and if ( not pt.HasParentNode(ProcedureNodes)) and
(BlockLevel(pt) = 0) and (BlockLevel(pt) = 0) and
( not pt.HasParentNode(nDeclSection)) then ( not pt.HasParentNode(nDeclSection))
begin then
Result := True; exit(True);
exit;
end;
{ semicolon at end of block { semicolon at end of block
e.g. e.g.
@ -237,20 +190,15 @@ begin
} }
if pt.HasParentNode([nVarSection, nConstSection]) and if pt.HasParentNode([nVarSection, nConstSection]) and
(ptNext.TokenType in ProcedureWords) and (ptNext.TokenType in ProcedureWords) and
(not pt.HasParentNode([nClassType,nRecordType])) then // not in class methods (not pt.HasParentNode([nClassType,nRecordType])) // not in class methods
begin then
Result := True; exit(True);
exit;
end;
// at the end of type block with a proc next. but not in a class def // at the end of type block with a proc next. but not in a class def
if pt.HasParentNode(nTypeSection) and (ptNext.TokenType in ProcedureWords) and if pt.HasParentNode(nTypeSection) and (ptNext.TokenType in ProcedureWords)
( not pt.HasParentNode(ObjectBodies + [nRecordType])) then and ( not pt.HasParentNode(ObjectBodies + [nRecordType]))
begin then
Result := True; exit(True);
exit;
end;
lcPrev := pt.PriorToken; lcPrev := pt.PriorToken;
{ 'end' at end of type def or proc { 'end' at end of type def or proc
@ -261,13 +209,8 @@ begin
lcPrev := lcPrev.PriorToken; lcPrev := lcPrev.PriorToken;
if (lcPrev.TokenType = ttEnd) and (pt.TokenType <> ttDot) then if (lcPrev.TokenType = ttEnd) and (pt.TokenType <> ttDot) then
begin
if EndsObjectType(lcPrev) or EndsProcedure(lcPrev) then if EndsObjectType(lcPrev) or EndsProcedure(lcPrev) then
begin exit(True);
Result := True;
exit;
end;
end;
end; end;
end; end;
@ -281,19 +224,14 @@ begin
Result := False; Result := False;
if (pt.TokenType in WordsJustReturnAfter) then if (pt.TokenType in WordsJustReturnAfter) then
begin exit(True);
Result := True;
exit;
end;
{ return after 'type' unless it's the second type in "type foo = type integer;" { return after 'type' unless it's the second type in "type foo = type integer;"
but what about } but what about }
if (pt.TokenType = ttType) and (pt.HasParentNode(nTypeSection, 1)) and if (pt.TokenType = ttType) and (pt.HasParentNode(nTypeSection, 1)) and
( not pt.IsOnRightOf(nTypeDecl, ttEquals)) then ( not pt.IsOnRightOf(nTypeDecl, ttEquals))
begin then
Result := True; exit(True);
exit;
end;
if (pt.TokenType = ttSemiColon) then if (pt.TokenType = ttSemiColon) then
begin begin
@ -311,10 +249,7 @@ begin
needless to say there is no return after the second "const" needless to say there is no return after the second "const"
even though it is in a const section } even though it is in a const section }
if not pt.HasParentNode(nFormalParams) then if not pt.HasParentNode(nFormalParams) then
begin exit(True);
Result := True;
exit;
end;
end; end;
{ return after else unless { return after else unless
@ -322,33 +257,21 @@ begin
- it is an else case of a case statement - it is an else case of a case statement
block styles takes care of these } block styles takes care of these }
if (pt.TokenType = ttElse) and (ptNext.TokenType <> ttIf) and not if (pt.TokenType = ttElse) and (ptNext.TokenType <> ttIf) and not
(pt.HasParentNode(nElseCase, 1)) then (pt.HasParentNode(nElseCase, 1))
begin then
Result := True; exit(True);
exit;
end;
{ case .. of } { case .. of }
if (pt.TokenType = ttOf) and (pt.IsOnRightOf(nCaseStatement, ttCase)) then if (pt.TokenType = ttOf) and (pt.IsOnRightOf(nCaseStatement, ttCase)) then
begin exit(True);
Result := True;
exit;
end;
{ record varaint with of} { record varaint with of}
if (pt.TokenType = ttOf) and pt.HasParentNode(nRecordVariantSection, 1) then if (pt.TokenType = ttOf) and pt.HasParentNode(nRecordVariantSection, 1) then
begin exit(True);
Result := True;
exit;
end;
{ label : } { label : }
if (pt.TokenType = ttColon) and pt.HasParentNode(nStatementLabel, 1) then if (pt.TokenType = ttColon) and pt.HasParentNode(nStatementLabel, 1) then
begin exit(True);
Result := True;
exit;
end;
lcNext := pt.NextSolidToken; lcNext := pt.NextSolidToken;
@ -356,27 +279,17 @@ begin
if (pt.TokenType = ttEnd) and ( not (ptNext.TokenType in [ttSemiColon, ttDot])) and if (pt.TokenType = ttEnd) and ( not (ptNext.TokenType in [ttSemiColon, ttDot])) and
( not (ptNext.TokenType in HintDirectives)) then ( not (ptNext.TokenType in HintDirectives)) then
begin begin
{ not end .. else if the style forbits it } { not end .. else if the style forbits it }
if (lcNext <> nil) and (lcNext.TokenType = ttElse) then if (lcNext <> nil) and (lcNext.TokenType = ttElse) then
begin Result := (FormattingSettings.Returns.EndElseStyle = eAlways)
Result := (FormattingSettings.Returns.EndElseStyle = eAlways);
end
else else
begin
Result := True; Result := True;
end;
exit; exit;
end; end;
{ access specifiying directive (private, public et al) in a class def } { access specifiying directive (private, public et al) in a class def }
if IsClassDirective(pt) then if IsClassDirective(pt) then
begin exit(pt.TokenType <> ttStrict); // all except the strict in "strict private"
// all except the strict in "strict private"
Result := (pt.TokenType <> ttStrict);
exit;
end;
{ "TSomeClass = class(TAncestorClass)" has a return after the close brackets { "TSomeClass = class(TAncestorClass)" has a return after the close brackets
unless it's a "class helper(foo) for bar" unless it's a "class helper(foo) for bar"
@ -386,10 +299,7 @@ begin
begin begin
lcNext := pt.NextSolidToken; lcNext := pt.NextSolidToken;
if (lcNext <> nil) and (lcNext.TokenType <> ttFor) then if (lcNext <> nil) and (lcNext.TokenType <> ttFor) then
begin exit(True);
Result := True;
exit;
end;
end; end;
{ otherwise "TSomeClass = class" has a return after "class" { otherwise "TSomeClass = class" has a return after "class"
@ -400,73 +310,48 @@ begin
- it's not the metaclass syntax 'foo = class of bar; ' } - it's not the metaclass syntax 'foo = class of bar; ' }
if (pt.TokenType = ttClass) and if (pt.TokenType = ttClass) and
pt.HasParentNode([nClassType, nInterfaceType], 1) and not pt.HasParentNode([nClassType, nInterfaceType], 1) and not
(pt.Parent.HasChildNode(nClassHeritage, 1)) and not (ptNext.TokenType in CLASS_FOLLOW) then (pt.Parent.HasChildNode(nClassHeritage, 1)) and not (ptNext.TokenType in CLASS_FOLLOW)
begin then
Result := True; exit(True);
exit;
end;
{ comma in exports clause } { comma in exports clause }
if (pt.TokenType = ttComma) and pt.HasParentNode(nExports) then if (pt.TokenType = ttComma) and pt.HasParentNode(nExports) then
begin exit(True);
Result := True;
exit;
end;
{ comma in uses clause of program or lib - these are 1 per line, { comma in uses clause of program or lib - these are 1 per line,
using the 'in' keyword to specify the file } using the 'in' keyword to specify the file }
if (pt.TokenType = ttComma) and pt.HasParentNode(nUses) and if (pt.TokenType = ttComma) and pt.HasParentNode(nUses) and
pt.HasParentNode(TopOfProgramSections) then pt.HasParentNode(TopOfProgramSections)
begin then
Result := True; exit(True);
exit;
end;
// 'uses' in program, library or package // 'uses' in program, library or package
if (pt.TokenType = ttUses) and pt.HasParentNode(TopOfProgramSections) then if (pt.TokenType = ttUses) and pt.HasParentNode(TopOfProgramSections) then
begin exit(True);
Result := True;
exit;
end;
if (pt.TokenType = ttRecord) and pt.IsOnRightOf(nFieldDeclaration, ttColon) then if (pt.TokenType = ttRecord) and pt.IsOnRightOf(nFieldDeclaration, ttColon) then
begin exit(True);
Result := True;
exit;
end;
{ end of class heritage } { end of class heritage }
if (pt.HasParentNode(nRestrictedType)) and if (pt.HasParentNode(nRestrictedType)) and
( not pt.HasParentNode(nClassVisibility)) and ( not pt.HasParentNode(nClassVisibility)) and
(ptNext.HasParentNode(nClassVisibility)) then (ptNext.HasParentNode(nClassVisibility))
begin then
Result := True; exit(True);
exit;
end;
{ return in record def after the record keyword } { return in record def after the record keyword }
if pt.HasParentNode(nRecordType) and (pt.TokenType = ttRecord) then if pt.HasParentNode(nRecordType) and (pt.TokenType = ttRecord) then
begin exit(True);
Result := True;
exit;
end;
if (pt.TokenType = ttCloseSquareBracket) then if (pt.TokenType = ttCloseSquareBracket) then
begin begin
// end of guid in interface // end of guid in interface
if pt.HasParentNode(nInterfaceTypeGuid, 1) then if pt.HasParentNode(nInterfaceTypeGuid, 1) then
begin exit(True);
Result := True;
exit;
end;
// end of attribute // end of attribute
if pt.HasParentNode(nAttribute) then if pt.HasParentNode(nAttribute) then
begin exit(True);
Result := True;
exit;
end;
end; end;
{ return after compiler directives { return after compiler directives
@ -475,11 +360,9 @@ begin
if (pt.CommentStyle = eCompilerDirective) and (CompilerDirectiveLineBreak(pt, False) = eAlways) then if (pt.CommentStyle = eCompilerDirective) and (CompilerDirectiveLineBreak(pt, False) = eAlways) then
begin begin
lcNext := pt.NextTokenWithExclusions([ttWhiteSpace]); lcNext := pt.NextTokenWithExclusions([ttWhiteSpace]);
if (lcNext <> nil) and (lcNext.TokenType <> ttConditionalCompilationRemoved) then if (lcNext <> nil) and (lcNext.TokenType <> ttConditionalCompilationRemoved)
begin then
Result := True; exit(True);
exit;
end;
end; end;
end; end;
@ -496,28 +379,19 @@ begin
{ option to Break After Uses } { option to Break After Uses }
if pt.HasParentNode(nUses) and (pt.TokenType = ttUses) and if pt.HasParentNode(nUses) and (pt.TokenType = ttUses) and
FormattingSettings.Returns.BreakAfterUses then FormattingSettings.Returns.BreakAfterUses then
begin exit(True);
Result := True;
exit;
end;
if pt.HasParentNode(nUses) and FormattingSettings.Returns.UsesClauseOnePerLine then if pt.HasParentNode(nUses) and FormattingSettings.Returns.UsesClauseOnePerLine then
begin begin
if (pt.TokenType = ttUses) then if (pt.TokenType = ttUses) then
begin exit(True);
Result := True;
exit;
end;
if (pt.TokenType in [ttComma, ttUses]) then if (pt.TokenType in [ttComma, ttUses]) then
begin begin
// add a return, unless there's a comment just after the comma // add a return, unless there's a comment just after the comma
lcNext := pt.NextTokenWithExclusions([ttWhiteSpace]); lcNext := pt.NextTokenWithExclusions([ttWhiteSpace]);
if (lcNext <> nil) and (lcNext.TokenType <> ttComment) then if (lcNext <> nil) and (lcNext.TokenType <> ttComment) then
begin exit(True);
Result := True;
exit;
end;
end; end;
end; end;
@ -525,9 +399,7 @@ begin
exit; exit;
if FormattingSettings.Returns.AddGoodReturns then if FormattingSettings.Returns.AddGoodReturns then
begin
Result := NeedsGoodReturn(pt, ptNext); Result := NeedsGoodReturn(pt, ptNext);
end;
end; end;
function IsAsmLabelEnd(const pcSourceToken: TSourceToken): boolean; function IsAsmLabelEnd(const pcSourceToken: TSourceToken): boolean;
@ -535,14 +407,10 @@ begin
Result := false; Result := false;
if pcSourceToken = nil then if pcSourceToken = nil then
begin
exit; exit;
end;
if (pcSourceToken.TokenType = ttColon) then if (pcSourceToken.TokenType = ttColon) then
begin
Result := pcSourceToken.HasParentNode(nAsmLabel, 1); Result := pcSourceToken.HasParentNode(nAsmLabel, 1);
end;
end; end;
function ReturnsNeededInAsm(const pcSourceToken: TSourceToken): integer; function ReturnsNeededInAsm(const pcSourceToken: TSourceToken): integer;
@ -557,9 +425,7 @@ begin
end; end;
if pcSourceToken.TokenType in [ttAsm, ttSemiColon] then if pcSourceToken.TokenType in [ttAsm, ttSemiColon] then
begin
Result := 1; Result := 1;
end;
end; end;
constructor TReturnAfter.Create; constructor TReturnAfter.Create;
@ -584,24 +450,16 @@ begin
exit; exit;
if lcSourceToken.HasParentNode(nAsm) then if lcSourceToken.HasParentNode(nAsm) then
begin liReturnsNeeded := ReturnsNeededInAsm(lcSourceToken)
liReturnsNeeded := ReturnsNeededInAsm(lcSourceToken);
end
else else
begin begin
// not asm // not asm
if NeedsBlankLine(lcSourceToken, lcNext) then if NeedsBlankLine(lcSourceToken, lcNext) then
begin liReturnsNeeded := 2
liReturnsNeeded := 2;
end
else if NeedsReturn(lcSourceToken, lcNext) then else if NeedsReturn(lcSourceToken, lcNext) then
begin
liReturnsNeeded := 1 liReturnsNeeded := 1
end
else else
begin
liReturnsNeeded := 0; liReturnsNeeded := 0;
end;
end; end;
if liReturnsNeeded < 1 then if liReturnsNeeded < 1 then

View File

@ -72,61 +72,37 @@ begin
exit; exit;
if (pt.TokenType in [ttLessThan,ttGreaterThan]) and pt.HasParentNode(nGeneric,1) then if (pt.TokenType in [ttLessThan,ttGreaterThan]) and pt.HasParentNode(nGeneric,1) then
begin exit(True);
Result := True;
Exit;
end;
if pt.TokenType in NoSpaceAnywhere then if pt.TokenType in NoSpaceAnywhere then
begin exit(True);
Result := True;
exit;
end;
if (FormattingSettings.Spaces.SpaceForOperator = eNever) then if (FormattingSettings.Spaces.SpaceForOperator = eNever) then
begin
if IsSymbolOperator(pt) then if IsSymbolOperator(pt) then
begin exit(True);
Result := True;
exit;
end;
end;
{ no space between method name and open bracket for param list { no space between method name and open bracket for param list
no space between type & bracket for cast no space between type & bracket for cast
no space between fn name & params for procedure call } no space between fn name & params for procedure call }
if pt.HasParentNode([nProcedureDecl, nFunctionDecl, nConstructorDecl, if pt.HasParentNode([nProcedureDecl, nFunctionDecl, nConstructorDecl,
nDestructorDecl, nStatementList]) and nDestructorDecl, nStatementList]) and
(IsIdentifier(pt, idAllowDirectives) or (pt.TokenType in BuiltInTypes)) then (IsIdentifier(pt, idAllowDirectives) or (pt.TokenType in BuiltInTypes))
begin then
if (ptNext.TokenType in OpenBrackets) and (not IsInsideAsm(ptNext)) then if (ptNext.TokenType in OpenBrackets) and (not IsInsideAsm(ptNext)) then
begin exit(True);
Result := True;
exit;
end;
end;
{ the above takes care of procedure headers but not procedure type defs { the above takes care of procedure headers but not procedure type defs
eg type TFred = procedure(i: integer) of object; eg type TFred = procedure(i: integer) of object;
note no space before the open bracket } note no space before the open bracket }
if pt.HasParentNode(nTypeDecl) and (pt.IsOnRightOf(nTypeDecl, ttEquals)) and if pt.HasParentNode(nTypeDecl) and (pt.IsOnRightOf(nTypeDecl, ttEquals)) and
(pt.TokenType in ProcedureWords) then (pt.TokenType in ProcedureWords)
begin then
if (ptNext.TokenType in OpenBrackets) then if (ptNext.TokenType in OpenBrackets) then
begin exit(True);
Result := True;
exit;
end;
end;
{ no space after unary operator in expression } { no space after unary operator in expression }
if pt.HasParentNode(nExpression) and IsUnaryOperator(pt) and if pt.HasParentNode(nExpression) and IsUnaryOperator(pt) and (not StrHasAlpha(pt.SourceCode)) then
( not StrHasAlpha(pt.SourceCode)) then exit(True);
begin
Result := True;
exit;
end;
{ no space before class heritage ? could be one of 3 things { no space before class heritage ? could be one of 3 things
TFoo = class; - no space, but "No space before semicolon" should take care of that TFoo = class; - no space, but "No space before semicolon" should take care of that
@ -137,17 +113,12 @@ begin
also applies to type TFoo = interface(IDispatch) } also applies to type TFoo = interface(IDispatch) }
if (pt.HasParentNode(nRestrictedType)) and (pt.TokenType in ObjectTypeWords) and if (pt.HasParentNode(nRestrictedType)) and (pt.TokenType in ObjectTypeWords) and
( not (FormattingSettings.Spaces.SpaceBeforeClassHeritage)) then ( not (FormattingSettings.Spaces.SpaceBeforeClassHeritage))
begin then
if (ptNext.TokenType in [ttOpenBracket, ttSemiColon]) then if (ptNext.TokenType in [ttOpenBracket, ttSemiColon]) then
begin exit(True);
Result := True;
exit;
end;
end;
end; end;
constructor TNoSpaceAfter.Create; constructor TNoSpaceAfter.Create;
begin begin
inherited; inherited;

View File

@ -83,10 +83,7 @@ begin
if pt.HasParentNode(nGeneric, 2) then if pt.HasParentNode(nGeneric, 2) then
begin begin
if pt.TokenType in [ttComma, ttColon, ttSemiColon] then if pt.TokenType in [ttComma, ttColon, ttSemiColon] then
begin
Result := true; Result := true;
end;
exit; exit;
end; end;
@ -101,62 +98,37 @@ begin
{ semciolon as a record field seperator in a const record declaration { semciolon as a record field seperator in a const record declaration
has no newline (See ReturnAfter.pas), just a single space } has no newline (See ReturnAfter.pas), just a single space }
if (pt.HasParentNode(nRecordConstant)) then if (pt.HasParentNode(nRecordConstant)) then
begin exit(True);
Result := True;
exit;
end;
{ semicolon in param declaration list } { semicolon in param declaration list }
if (pt.HasParentNode(nFormalParams)) then if (pt.HasParentNode(nFormalParams)) then
begin exit(True);
Result := True;
exit;
end;
{ semicolon in param lists in proc type def. as above } { semicolon in param lists in proc type def. as above }
if (pt.HasParentNode(nProcedureType)) then if (pt.HasParentNode(nProcedureType)) then
begin exit(True);
Result := True;
exit;
end;
{ semicolon in procedure directives } { semicolon in procedure directives }
if (pt.HasParentNode(nProcedureDirectives)) then if (pt.HasParentNode(nProcedureDirectives)) then
begin exit(True);
Result := True;
exit;
end;
end;// semicolon end;// semicolon
{ function foo: integer; has single space after the colon { function foo: integer; has single space after the colon
single space after colon - anywhere? } single space after colon - anywhere? }
if pt.TokenType = ttColon then if pt.TokenType = ttColon then
begin
Result := True; Result := True;
end;
if (pt.TokenType in SingleSpaceAfterTokens) then if (pt.TokenType in SingleSpaceAfterTokens) then
begin exit(True);
Result := True;
exit;
end;
if pt.TokenType = ttOpenBracket then if pt.TokenType = ttOpenBracket then
begin
if FormattingSettings.Spaces.SpaceAfterOpenBrackets then if FormattingSettings.Spaces.SpaceAfterOpenBrackets then
begin exit(true);
Result := true;
exit;
end;
end;
{ 'absolute' as a var directive } { 'absolute' as a var directive }
if (pt.TokenType = ttAbsolute) and pt.HasParentNode(nVarAbsolute) then if (pt.TokenType = ttAbsolute) and pt.HasParentNode(nVarAbsolute) then
begin exit(True);
Result := True;
exit;
end;
if (pt.TokenType in SingleSpaceAfterWords) then if (pt.TokenType in SingleSpaceAfterWords) then
begin begin
@ -175,73 +147,45 @@ begin
if FormattingSettings.Spaces.SpaceForOperator = eAlways then if FormattingSettings.Spaces.SpaceForOperator = eAlways then
begin begin
if (pt.TokenType in SingleSpaceOperators) then if (pt.TokenType in SingleSpaceOperators) then
begin exit(True);
Result := True;
exit;
end;
{ + or - but only if it is a binary operator, ie a term to the left of it } { + or - but only if it is a binary operator, ie a term to the left of it }
if (pt.TokenType in PossiblyUnaryOperators) and (pt.HasParentNode(nExpression)) and if (pt.TokenType in PossiblyUnaryOperators) and (pt.HasParentNode(nExpression)) and
( not IsUnaryOperator(pt)) then ( not IsUnaryOperator(pt)) then
begin exit(True);
Result := True;
exit;
end;
end; end;
{ only if it actually is a directive, see TestCases/TestBogusDirectives for details } { only if it actually is a directive, see TestCases/TestBogusDirectives for details }
if (pt.TokenType in AllDirectives) and (pt.HasParentNode(DirectiveNodes)) and if (pt.TokenType in AllDirectives) and (pt.HasParentNode(DirectiveNodes)) and
(ptNext.TokenType <> ttSemiColon) then (ptNext.TokenType <> ttSemiColon)
begin then
Result := True; exit(True);
exit;
end;
if pt.TokenType = ttEquals then if pt.TokenType = ttEquals then
begin exit(True);
Result := True;
exit;
end;
{ 'in' in the uses clause } { 'in' in the uses clause }
if (pt.TokenType = ttIn) and (pt.HasParentNode(nUses)) then if (pt.TokenType = ttIn) and (pt.HasParentNode(nUses)) then
begin exit(True);
Result := True;
exit;
end;
{ const or var as parameter var types } { const or var as parameter var types }
if (pt.TokenType in ParamTypes) and (pt.HasParentNode(nFormalParams)) then if (pt.TokenType in ParamTypes) and (pt.HasParentNode(nFormalParams)) then
begin
// beware of 'procedure foo (bar: array of const);' and the like // beware of 'procedure foo (bar: array of const);' and the like
if not ((pt.TokenType = ttConst) and pt.HasParentNode(nType, 1)) then if not ((pt.TokenType = ttConst) and pt.HasParentNode(nType, 1)) then
begin exit(True);
Result := True;
exit;
end;
end;
if (pt.TokenType in ParamTypes) and pt.HasParentNode(nPropertyParameterList) and if (pt.TokenType in ParamTypes) and pt.HasParentNode(nPropertyParameterList) and
pt.IsOnRightOf(nPropertyParameterList, ttOpenSquareBracket) then pt.IsOnRightOf(nPropertyParameterList, ttOpenSquareBracket)
begin then
Result := True; exit(True);
exit;
end;
{ signle space after read, write etc in property } { signle space after read, write etc in property }
if pt.HasParentNode(nProperty) then if pt.HasParentNode(nProperty) then
begin if (pt.TokenType in [ttProperty, ttRead, ttWrite, ttDefault, ttStored, ttImplements])
if (pt.TokenType in [ttProperty, ttRead, ttWrite, ttDefault, and (ptNext.TokenType <> ttSemiColon)
ttStored, ttImplements]) and then
(ptNext.TokenType <> ttSemiColon) then exit(True);
begin
Result := True;
exit;
end;
end;
{ single space before class heritage ? { single space before class heritage ?
see NoSpaceAfter } see NoSpaceAfter }
@ -249,27 +193,18 @@ begin
(FormattingSettings.Spaces.SpaceBeforeClassHeritage) then (FormattingSettings.Spaces.SpaceBeforeClassHeritage) then
begin begin
if (ptNext.TokenType in [ttOpenBracket, ttSemiColon]) then if (ptNext.TokenType in [ttOpenBracket, ttSemiColon]) then
begin exit(True);
Result := True;
exit;
end;
end; end;
if InStatements(pt) then if InStatements(pt) then
begin begin
// else if // else if
if (pt.TokenType = ttElse) and (ptNext.TokenType = ttIf) then if (pt.TokenType = ttElse) and (ptNext.TokenType = ttIf) then
begin exit(True);
Result := True;
exit;
end;
// end else // end else
if (pt.TokenType = ttEnd) and (ptNext.TokenType = ttElse) then if (pt.TokenType = ttEnd) and (ptNext.TokenType = ttElse) then
begin exit(True);
Result := True;
exit;
end;
{ else followed by something else on the same line, { else followed by something else on the same line,
e.g if block style brings up the following "begin" } e.g if block style brings up the following "begin" }
@ -277,10 +212,7 @@ begin
begin begin
lcSameLineToken := pt.NexttokenWithExclusions([ttWhiteSpace]); lcSameLineToken := pt.NexttokenWithExclusions([ttWhiteSpace]);
if (lcSameLineToken <> nil) and (not (lcSameLineToken.TokenType in [ttReturn, ttSemiColon])) then if (lcSameLineToken <> nil) and (not (lcSameLineToken.TokenType in [ttReturn, ttSemiColon])) then
begin exit(True);
Result := True;
exit;
end;
end; end;
end; end;