From 75d3718f7dacab544abaefbdc5e3fc98a73bf264 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 6 Apr 2009 02:19:13 +0000 Subject: [PATCH] jcf: update to r803 revision of main repository: - support for c-style fpc operators git-svn-id: trunk@19236 - --- components/jcf2/Parse/BuildParseTree.pas | 10 ++-- components/jcf2/Parse/BuildTokenList.pas | 25 +++++++-- components/jcf2/Parse/ParseTreeNode.pas | 3 +- components/jcf2/Parse/Tokens.pas | 16 +++++- components/jcf2/Parse/UI/fShowParseTree.lfm | 44 ++++++++-------- components/jcf2/Parse/UI/fShowParseTree.lrs | 43 ++++++++------- components/jcf2/Process/Align/AlignAssign.pas | 6 +-- components/jcf2/Process/Indent/Indenter.pas | 52 +++++++++++++++++-- .../Obfuscate/RemoveUnneededWhiteSpace.pas | 2 +- .../jcf2/Process/Returns/LongLineBreaker.pas | 2 +- .../jcf2/Process/Returns/NoReturnBefore.pas | 2 +- .../jcf2/Process/Returns/ReturnAfter.pas | 3 +- .../jcf2/Process/Spacing/SingleSpaceAfter.pas | 3 +- .../Process/Spacing/SingleSpaceBefore.pas | 2 +- components/jcf2/Settings/SetIndent.pas | 12 +++++ components/jcf2/Settings/SetSpaces.pas | 1 - .../jcf2/Ui/Settings/frClarifyIndent.dfm | 22 ++++++-- .../jcf2/Ui/Settings/frClarifyIndent.pas | 7 +++ components/jcf2/Utils/JcfStringUtils.pas | 5 +- components/jcf2/readme.txt | 2 +- 20 files changed, 186 insertions(+), 76 deletions(-) diff --git a/components/jcf2/Parse/BuildParseTree.pas b/components/jcf2/Parse/BuildParseTree.pas index 9e60c3eebd..57033db077 100644 --- a/components/jcf2/Parse/BuildParseTree.pas +++ b/components/jcf2/Parse/BuildParseTree.pas @@ -2306,7 +2306,7 @@ procedure TBuildParseTree.RecogniseOperatorSymbol; const OperatorTokens: TTokenTypeSet = [ttPlus, ttMinus, ttTimes, ttFloatDiv, ttExponent, ttEquals, ttGreaterThan, ttLessThan, ttGreaterThanOrEqual, ttLessThanOrEqual, - ttAssign]; + ttAssign, ttPlusAssign, ttMinusAssign, ttTimesAssign, ttFloatDivAssign]; begin Recognise(OperatorTokens); end; @@ -2971,11 +2971,11 @@ begin RecogniseBracketedStatement; RecogniseDesignatorTail; - if fcTokenList.FirstSolidTokenType = ttAssign then + if fcTokenList.FirstSolidTokenType in AssignmentDirectives then begin PushNode(nAssignment); - Recognise(ttAssign); + Recognise(fcTokenList.FirstSolidTokenType); RecogniseExpr(True); PopNode; @@ -3044,11 +3044,11 @@ begin RecogniseDesignatorTail; - if TokenList.FirstSolidTokenType = ttAssign then + if TokenList.FirstSolidTokenType in AssignmentDirectives then begin PushNode(nAssignment); - Recognise(ttAssign); + Recognise(TokenList.FirstSolidTokenType); RecogniseExpr(True); PopNode; diff --git a/components/jcf2/Parse/BuildTokenList.pas b/components/jcf2/Parse/BuildTokenList.pas index ac9cf1ede6..b9c50df53f 100644 --- a/components/jcf2/Parse/BuildTokenList.pas +++ b/components/jcf2/Parse/BuildTokenList.pas @@ -474,17 +474,34 @@ begin end; function TBuildTokenList.TryAssign(const pcToken: TSourceToken): boolean; +var + TwoChars: WideString; begin Result := False; - if Current <> ':' then + if not (CharInSet(Current, [':', '+', '-', '*', '/'])) then exit; - if CurrentChars(2) <> ':=' then + TwoChars := CurrentChars(2); + + if TwoChars = ':=' then + pcToken.TokenType := ttAssign + else + if TwoChars = '+=' then + pcToken.TokenType := ttPlusAssign + else + if TwoChars = '-=' then + pcToken.TokenType := ttMinusAssign + else + if TwoChars = '*=' then + pcToken.TokenType := ttTimesAssign + else + if TwoChars = '/=' then + pcToken.TokenType := ttFloatDivAssign + else exit; - pcToken.TokenType := ttAssign; - pcToken.SourceCode := CurrentChars(2); + pcToken.SourceCode := TwoChars; Consume(2); Result := True; diff --git a/components/jcf2/Parse/ParseTreeNode.pas b/components/jcf2/Parse/ParseTreeNode.pas index f67c14f326..ce76f64c97 100644 --- a/components/jcf2/Parse/ParseTreeNode.pas +++ b/components/jcf2/Parse/ParseTreeNode.pas @@ -543,8 +543,7 @@ begin end; -function TParseTreeNode.IsOnRightOf(const peRootNodeTypes, peNodes: - TParseTreeNodeTypeSet): boolean; +function TParseTreeNode.IsOnRightOf(const peRootNodeTypes, peNodes: TParseTreeNodeTypeSet): boolean; var lbSearchDone: boolean; diff --git a/components/jcf2/Parse/Tokens.pas b/components/jcf2/Parse/Tokens.pas index 8f0625ea6a..cc6c36d96b 100644 --- a/components/jcf2/Parse/Tokens.pas +++ b/components/jcf2/Parse/Tokens.pas @@ -272,7 +272,13 @@ type ttGreaterThanOrEqual, ttLessThanOrEqual, ttNotEqual, - ttBackSlash { legal in char literals } + ttBackSlash, { legal in char literals } + + // FreePascal c-style operators + ttPlusAssign, // += + ttMinusAssign, // -= + ttTimesAssign, // *= + ttFloatDivAssign // /= ); TTokenTypeSet = set of TTokenType; @@ -416,6 +422,8 @@ const AsmOffsets: TTokenTypeSet = [ttVmtOffset, ttDmtOffset]; + AssignmentDirectives: TTokenTypeSet = [ttAssign, ttPlusAssign, ttMinusAssign, ttTimesAssign, ttFloatDivAssign]; + { interpret a string as a token } procedure TypeOfToken(const psWord: string; out peWordType: TWordType; out peToken: TTokenType); overload; @@ -751,6 +759,12 @@ begin AddKeyword('<', wtOperator, ttLessThan); AddKeyword('\', wtOperator, ttBackSlash); + // FreePascal c-style operators + AddKeyword('+=', wtNotAWord, ttPlusAssign); + AddKeyword('-=', wtNotAWord, ttMinusAssign); + AddKeyword('*=', wtNotAWord, ttTimesAssign); + AddKeyword('/=', wtNotAWord, ttFloatDivAssign); + {Now that we know how many keywords were added, we can set the actual size of the array } SetLength(mrKeywordTextMap, miKeyWordCount); diff --git a/components/jcf2/Parse/UI/fShowParseTree.lfm b/components/jcf2/Parse/UI/fShowParseTree.lfm index 4f0be192ca..ce32d3a152 100644 --- a/components/jcf2/Parse/UI/fShowParseTree.lfm +++ b/components/jcf2/Parse/UI/fShowParseTree.lfm @@ -19,8 +19,8 @@ object frmShowParseTree: TfrmShowParseTree LCLVersion = '0.9.27' object StatusBar1: TStatusBar Left = 0 - Height = 21 - Top = 534 + Height = 23 + Top = 532 Width = 581 Panels = <> end @@ -40,7 +40,7 @@ object frmShowParseTree: TfrmShowParseTree Left = 11 Height = 18 Top = 31 - Width = 108 + Width = 115 Caption = 'Tree has ? nodes' ParentColor = False end @@ -48,15 +48,15 @@ object frmShowParseTree: TfrmShowParseTree Left = 11 Height = 18 Top = 55 - Width = 161 + Width = 167 Caption = 'Tree has max depth of ??' ParentColor = False end object cbShowWhiteSpace: TCheckBox Left = 11 - Height = 22 + Height = 23 Top = 5 - Width = 133 + Width = 141 Caption = 'Show whitespace' OnClick = cbShowWhiteSpaceClick TabOrder = 0 @@ -65,7 +65,7 @@ object frmShowParseTree: TfrmShowParseTree object pnlBottom: TPanel Left = 0 Height = 50 - Top = 484 + Top = 482 Width = 581 Align = alBottom BevelOuter = bvNone @@ -107,22 +107,22 @@ object frmShowParseTree: TfrmShowParseTree end object pcPages: TPageControl Left = 0 - Height = 399 + Height = 397 Top = 85 Width = 581 - ActivePage = tsTree + ActivePage = tsTokens Align = alClient - TabIndex = 1 + TabIndex = 0 TabOrder = 3 object tsTokens: TTabSheet Caption = 'Tokens' - ClientHeight = 372 - ClientWidth = 579 + ClientHeight = 367 + ClientWidth = 573 object lvTokens: TListView Left = 0 - Height = 372 + Height = 367 Top = 0 - Width = 579 + Width = 573 Align = alClient Columns = < item @@ -138,7 +138,7 @@ object frmShowParseTree: TfrmShowParseTree item AutoSize = False Caption = 'Text' - Width = 313 + Width = 271 end> ReadOnly = True RowSelect = True @@ -152,24 +152,24 @@ object frmShowParseTree: TfrmShowParseTree end object tsTree: TTabSheet Caption = 'Tree' - ClientHeight = 372 - ClientWidth = 579 + ClientHeight = 371 + ClientWidth = 573 ImageIndex = 1 object tvParseTree: TTreeView Left = 0 - Height = 372 + Height = 371 Top = 0 - Width = 579 + Width = 573 Align = alClient - DefaultItemHeight = 19 + Ctl3D = False + DefaultItemHeight = 15 HideSelection = False Indent = 22 - ReadOnly = True RightClickSelect = True TabOrder = 0 OnChange = tvParseTreeChange OnDblClick = tvParseTreeDblClick - Options = [tvoAutoItemHeight, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips] + Options = [tvoAutoItemHeight, tvoKeepCollapsedNodes, tvoRightClickSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips] end end end diff --git a/components/jcf2/Parse/UI/fShowParseTree.lrs b/components/jcf2/Parse/UI/fShowParseTree.lrs index 432bfc4c04..3b924a590d 100644 --- a/components/jcf2/Parse/UI/fShowParseTree.lrs +++ b/components/jcf2/Parse/UI/fShowParseTree.lrs @@ -8,18 +8,18 @@ LazarusResources.Add('TfrmShowParseTree','FORMDATA',[ +'SET'#11'Font.Height'#2#241#9'Font.Name'#6#8'Segoe UI'#10'KeyPreview'#9#8'On' +'Create'#7#10'FormCreate'#7'OnKeyUp'#7#9'FormKeyUp'#6'OnShow'#7#8'FormShow'#8 +'Position'#7#17'poOwnerFormCenter'#10'LCLVersion'#6#6'0.9.27'#0#10'TStatusBa' - +'r'#10'StatusBar1'#4'Left'#2#0#6'Height'#2#21#3'Top'#3#22#2#5'Width'#3'E'#2#6 + +'r'#10'StatusBar1'#4'Left'#2#0#6'Height'#2#23#3'Top'#3#20#2#5'Width'#3'E'#2#6 +'Panels'#14#0#0#0#6'TPanel'#6'pnlTop'#4'Left'#2#0#6'Height'#2'U'#3'Top'#2#0#5 +'Width'#3'E'#2#5'Align'#7#5'alTop'#10'BevelOuter'#7#6'bvNone'#12'ClientHeigh' +'t'#2'U'#11'ClientWidth'#3'E'#2#21'Constraints.MinHeight'#2'C'#20'Constraint' +'s.MinWidth'#2'C'#8'TabOrder'#2#1#0#6'TLabel'#12'lblTreeCount'#4'Left'#2#11#6 - +'Height'#2#18#3'Top'#2#31#5'Width'#2'l'#7'Caption'#6#16'Tree has ? nodes'#11 + +'Height'#2#18#3'Top'#2#31#5'Width'#2's'#7'Caption'#6#16'Tree has ? nodes'#11 +'ParentColor'#8#0#0#6'TLabel'#12'lblTreeDepth'#4'Left'#2#11#6'Height'#2#18#3 - +'Top'#2'7'#5'Width'#3#161#0#7'Caption'#6#24'Tree has max depth of ??'#11'Par' + +'Top'#2'7'#5'Width'#3#167#0#7'Caption'#6#24'Tree has max depth of ??'#11'Par' +'entColor'#8#0#0#9'TCheckBox'#16'cbShowWhiteSpace'#4'Left'#2#11#6'Height'#2 - +#22#3'Top'#2#5#5'Width'#3#133#0#7'Caption'#6#15'Show whitespace'#7'OnClick'#7 + +#23#3'Top'#2#5#5'Width'#3#141#0#7'Caption'#6#15'Show whitespace'#7'OnClick'#7 +#21'cbShowWhiteSpaceClick'#8'TabOrder'#2#0#0#0#0#6'TPanel'#9'pnlBottom'#4'Le' - +'ft'#2#0#6'Height'#2'2'#3'Top'#3#228#1#5'Width'#3'E'#2#5'Align'#7#8'alBottom' + +'ft'#2#0#6'Height'#2'2'#3'Top'#3#226#1#5'Width'#3'E'#2#5'Align'#7#8'alBottom' +#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#2'2'#11'ClientWidth'#3'E'#2#8'T' +'abOrder'#2#2#0#6'TLabel'#10'lblCurrent'#4'Left'#2#11#6'Height'#2#20#3'Top'#2 +#2#5'Width'#2'3'#7'Caption'#6#8'Current:'#11'ParentColor'#8#0#0#6'TLabel'#8 @@ -29,22 +29,21 @@ LazarusResources.Add('TfrmShowParseTree','FORMDATA',[ +':'#11'ParentColor'#8#0#0#6'TLabel'#22'lblImmediateChildCount'#4'Left'#3#15#1 +#6'Height'#2#20#3'Top'#2#2#5'Width'#3#152#0#7'Caption'#6#22'Immediate child ' +'count:'#11'ParentColor'#8#0#0#0#12'TPageControl'#7'pcPages'#4'Left'#2#0#6'H' - +'eight'#3#143#1#3'Top'#2'U'#5'Width'#3'E'#2#10'ActivePage'#7#6'tsTree'#5'Ali' - +'gn'#7#8'alClient'#8'TabIndex'#2#1#8'TabOrder'#2#3#0#9'TTabSheet'#8'tsTokens' - +#7'Caption'#6#6'Tokens'#12'ClientHeight'#3't'#1#11'ClientWidth'#3'C'#2#0#9'T' - +'ListView'#8'lvTokens'#4'Left'#2#0#6'Height'#3't'#1#3'Top'#2#0#5'Width'#3'C' - +#2#5'Align'#7#8'alClient'#7'Columns'#14#1#8'AutoSize'#8#7'Caption'#6#5'Index' - +#5'Width'#2'?'#0#1#8'AutoSize'#8#7'Caption'#6#4'Type'#5'Width'#3#185#0#0#1#8 - +'AutoSize'#8#7'Caption'#6#4'Text'#5'Width'#3'9'#1#0#0#8'ReadOnly'#9#9'RowSel' - +'ect'#9#10'SortColumn'#2#0#8'SortType'#7#6'stNone'#8'TabOrder'#2#0#9'ViewSty' - +'le'#7#8'vsReport'#10'OnDblClick'#7#16'lvTokensDblClick'#12'OnSelectItem'#7 - +#18'lvTokensSelectItem'#0#0#0#9'TTabSheet'#6'tsTree'#7'Caption'#6#4'Tree'#12 - +'ClientHeight'#3't'#1#11'ClientWidth'#3'C'#2#10'ImageIndex'#2#1#0#9'TTreeVie' - +'w'#11'tvParseTree'#4'Left'#2#0#6'Height'#3't'#1#3'Top'#2#0#5'Width'#3'C'#2#5 - +'Align'#7#8'alClient'#17'DefaultItemHeight'#2#19#13'HideSelection'#8#6'Inden' - +'t'#2#22#8'ReadOnly'#9#16'RightClickSelect'#9#8'TabOrder'#2#0#8'OnChange'#7 + +'eight'#3#141#1#3'Top'#2'U'#5'Width'#3'E'#2#10'ActivePage'#7#8'tsTokens'#5'A' + +'lign'#7#8'alClient'#8'TabIndex'#2#0#8'TabOrder'#2#3#0#9'TTabSheet'#8'tsToke' + +'ns'#7'Caption'#6#6'Tokens'#12'ClientHeight'#3'o'#1#11'ClientWidth'#3'='#2#0 + +#9'TListView'#8'lvTokens'#4'Left'#2#0#6'Height'#3'o'#1#3'Top'#2#0#5'Width'#3 + +'='#2#5'Align'#7#8'alClient'#7'Columns'#14#1#8'AutoSize'#8#7'Caption'#6#5'In' + +'dex'#5'Width'#2'?'#0#1#8'AutoSize'#8#7'Caption'#6#4'Type'#5'Width'#3#185#0#0 + +#1#8'AutoSize'#8#7'Caption'#6#4'Text'#5'Width'#3#15#1#0#0#8'ReadOnly'#9#9'Ro' + +'wSelect'#9#10'SortColumn'#2#0#8'SortType'#7#6'stNone'#8'TabOrder'#2#0#9'Vie' + +'wStyle'#7#8'vsReport'#10'OnDblClick'#7#16'lvTokensDblClick'#12'OnSelectItem' + +#7#18'lvTokensSelectItem'#0#0#0#9'TTabSheet'#6'tsTree'#7'Caption'#6#4'Tree' + +#12'ClientHeight'#3's'#1#11'ClientWidth'#3'='#2#10'ImageIndex'#2#1#0#9'TTree' + +'View'#11'tvParseTree'#4'Left'#2#0#6'Height'#3's'#1#3'Top'#2#0#5'Width'#3'=' + +#2#5'Align'#7#8'alClient'#5'Ctl3D'#8#17'DefaultItemHeight'#2#15#13'HideSelec' + +'tion'#8#6'Indent'#2#22#16'RightClickSelect'#9#8'TabOrder'#2#0#8'OnChange'#7 +#17'tvParseTreeChange'#10'OnDblClick'#7#19'tvParseTreeDblClick'#7'Options'#11 - +#17'tvoAutoItemHeight'#21'tvoKeepCollapsedNodes'#11'tvoReadOnly'#19'tvoRight' - +'ClickSelect'#14'tvoShowButtons'#12'tvoShowLines'#11'tvoShowRoot'#11'tvoTool' - +'Tips'#0#0#0#0#0#0 + +#17'tvoAutoItemHeight'#21'tvoKeepCollapsedNodes'#19'tvoRightClickSelect'#14 + +'tvoShowButtons'#12'tvoShowLines'#11'tvoShowRoot'#11'tvoToolTips'#0#0#0#0#0#0 ]); diff --git a/components/jcf2/Process/Align/AlignAssign.pas b/components/jcf2/Process/Align/AlignAssign.pas index 1106265009..bbf8baf404 100644 --- a/components/jcf2/Process/Align/AlignAssign.pas +++ b/components/jcf2/Process/Align/AlignAssign.pas @@ -120,13 +120,13 @@ end; function TAlignAssign.TokenIsAligned(const pt: TSourceToken): boolean; begin { keep the indent - don't align statement of differing indent levels } - if (fiStartBlockLevel < 0) and (pt.TokenType = ttAssign) then + if (fiStartBlockLevel < 0) and (pt.TokenType in AssignmentDirectives) then fiStartBlockLevel := BlockLevel(pt); - if (fiStartCaseLevel < 0) and (pt.TokenType = ttAssign) then + if (fiStartCaseLevel < 0) and (pt.TokenType in AssignmentDirectives) then fiStartCaseLevel := CaseLevel(pt); - Result := (pt.TokenType = ttAssign) and + Result := (pt.TokenType in AssignmentDirectives) and (fiStartBlockLevel = BlockLevel(pt)) and (fiStartCaseLevel = CaseLevel(pt)); end; diff --git a/components/jcf2/Process/Indent/Indenter.pas b/components/jcf2/Process/Indent/Indenter.pas index dce9d787b9..72bea149f9 100644 --- a/components/jcf2/Process/Indent/Indenter.pas +++ b/components/jcf2/Process/Indent/Indenter.pas @@ -195,7 +195,7 @@ begin if not pt.HasParentNode(nAssignment) then exit; - if not pt.IsOnRightOf(nAssignment, ttAssign) then + if not pt.IsOnRightOf([nAssignment], AssignmentDirectives) then exit; Result := True; @@ -220,7 +220,7 @@ begin end; -{ this is needed for delphi.net nested types +{ this is needed for nested types indent the inner class more than the outer } function CountClassNesting(const pt: TParseTreeNode): integer; begin @@ -235,6 +235,19 @@ begin Result := Result + CountClassNesting(pt.Parent); end; +function CountTypeNesting(const pt: TParseTreeNode): integer; +begin + Result := 0; + + if pt = nil then + exit; + + if pt.NodeType = nTypeSection then + Result := 1; + + Result := Result + CountTypeNesting(pt.Parent); +end; + function IsRunOnProcDecl(const pt: TSourceToken): boolean; begin Result := pt.HasParentNode(ProcedureHeadings) and @@ -298,6 +311,8 @@ var lbHasIndentedDecl: boolean; lcParent, lcChild: TParseTreeNode; liClassNestingCount: integer; + liTypeNestingCount: integer; + liVarConstIndent: integer; begin Result := 0; lbHasIndentedRunOnLine := False; @@ -309,14 +324,24 @@ begin { object types } if pt.HasParentNode(ObjectTypes) then begin - liClassNestingCount := CountClassNesting(pt); + { indentation sections inside the class } + if FormatSettings.Indent.IndentVarAndConstInClass then + begin + liVarConstIndent := 2; + end + else + begin + liVarConstIndent := 1; + end; if pt.TokenType in ClassVisibility + [ttStrict] then liIndentCount := 1 else if (pt.TokenType = ttConst) and pt.HasParentNode(nConstSection, 1) then - liIndentCount := 1 + liIndentCount := liVarConstIndent else if (pt.TokenType = ttVar) and pt.HasParentNode(nVarSection, 1) then - liIndentCount := 1 + liIndentCount := liVarConstIndent + else if (pt.TokenType = ttClass) and pt.HasParentNode(nClassVars, 1) then + liIndentCount := 2 else if pt.TokenType = ttEnd then begin @@ -339,7 +364,24 @@ begin lbHasIndentedDecl := True; + liClassNestingCount := CountClassNesting(pt); liIndentCount := liIndentCount + (liClassNestingCount - 1); + + if FormatSettings.Indent.IndentNestedTypes then + begin + liTypeNestingCount := CountTypeNesting(pt); + if (liTypeNestingCount > 1) then + begin + if pt.TokenType = ttType then + begin + liIndentCount := liIndentCount + (liTypeNestingCount - 2); + end + else + begin + liIndentCount := liIndentCount + (liTypeNestingCount - 1); + end; + end; + end; end { indent vars, consts etc, e.g. diff --git a/components/jcf2/Process/Obfuscate/RemoveUnneededWhiteSpace.pas b/components/jcf2/Process/Obfuscate/RemoveUnneededWhiteSpace.pas index c150d86be6..1b312e0bf9 100644 --- a/components/jcf2/Process/Obfuscate/RemoveUnneededWhiteSpace.pas +++ b/components/jcf2/Process/Obfuscate/RemoveUnneededWhiteSpace.pas @@ -75,7 +75,7 @@ end; const MiscUnspacedTokens: TTokenTypeSet = [ ttQuotedLiteralString, ttSemiColon, ttColon, ttComma, - ttDot, ttDoubleDot, ttAssign, ttReturn]; + ttDot, ttDoubleDot, ttAssign, ttReturn, ttPlusAssign, ttMinusAssign, ttTimesAssign, ttFloatDivAssign]; DoNotConcat = [ttGreaterThan, ttLessThan, ttEquals]; diff --git a/components/jcf2/Process/Returns/LongLineBreaker.pas b/components/jcf2/Process/Returns/LongLineBreaker.pas index b3549a958c..8aef0d4ec0 100644 --- a/components/jcf2/Process/Returns/LongLineBreaker.pas +++ b/components/jcf2/Process/Returns/LongLineBreaker.pas @@ -378,7 +378,7 @@ begin end; end; { It is good to break after := not before } - ttAssign: + ttAssign, ttPlusAssign, ttMinusAssign, ttTimesAssign, ttFloatDivAssign: begin piScoreBefore := BAD2; piScoreAfter := GOOD3; diff --git a/components/jcf2/Process/Returns/NoReturnBefore.pas b/components/jcf2/Process/Returns/NoReturnBefore.pas index e1d7f4ecfa..53a9d29b23 100644 --- a/components/jcf2/Process/Returns/NoReturnBefore.pas +++ b/components/jcf2/Process/Returns/NoReturnBefore.pas @@ -56,7 +56,7 @@ uses SourceToken, TokenUtils, Tokens, ParseTreeNodeType, function HasNoReturnBefore(const pt: TSourceToken): boolean; const - NoReturnTokens: TTokenTypeSet = [ttAssign, ttColon, ttSemiColon]; + NoReturnTokens: TTokenTypeSet = [ttAssign, ttColon, ttSemiColon, ttPlusAssign, ttMinusAssign, ttTimesAssign, ttFloatDivAssign]; ProcNoReturnWords: TTokenTypeSet = [ttThen, ttDo]; var lcPrev: TParseTreeNode; diff --git a/components/jcf2/Process/Returns/ReturnAfter.pas b/components/jcf2/Process/Returns/ReturnAfter.pas index 010c5765ac..e995c913da 100644 --- a/components/jcf2/Process/Returns/ReturnAfter.pas +++ b/components/jcf2/Process/Returns/ReturnAfter.pas @@ -270,7 +270,8 @@ begin 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 } if (pt.TokenType = ttType) and (pt.HasParentNode(nTypeSection, 1)) and ( not pt.IsOnRightOf(nTypeDecl, ttEquals)) then begin diff --git a/components/jcf2/Process/Spacing/SingleSpaceAfter.pas b/components/jcf2/Process/Spacing/SingleSpaceAfter.pas index 5e9587e612..a65004b7ef 100644 --- a/components/jcf2/Process/Spacing/SingleSpaceAfter.pas +++ b/components/jcf2/Process/Spacing/SingleSpaceAfter.pas @@ -55,7 +55,8 @@ uses FormatFlags, TokenUtils, SettingsTypes; const - SingleSpaceAfterTokens: TTokenTypeSet = [ttColon, ttAssign, ttComma]; + SingleSpaceAfterTokens: TTokenTypeSet = [ttColon, ttAssign, ttComma, + ttPlusAssign, ttMinusAssign, ttTimesAssign, ttFloatDivAssign]; SingleSpaceAfterWords: TTokenTypeSet = [ ttProcedure, ttFunction, diff --git a/components/jcf2/Process/Spacing/SingleSpaceBefore.pas b/components/jcf2/Process/Spacing/SingleSpaceBefore.pas index 326dd90045..7421e2fa77 100644 --- a/components/jcf2/Process/Spacing/SingleSpaceBefore.pas +++ b/components/jcf2/Process/Spacing/SingleSpaceBefore.pas @@ -140,7 +140,7 @@ begin if pt.HasParentNode(nAsm) then exit; - if (pt.TokenType = ttAssign) then + if (pt.TokenType in AssignmentDirectives) then begin Result := True; exit; diff --git a/components/jcf2/Settings/SetIndent.pas b/components/jcf2/Settings/SetIndent.pas index eccdaa0e7c..fc682e4ef4 100644 --- a/components/jcf2/Settings/SetIndent.pas +++ b/components/jcf2/Settings/SetIndent.pas @@ -51,6 +51,8 @@ type fbKeepCommentsWithCodeElsewhere: boolean; fbIndentElse: Boolean; fbIndentCaseElse: Boolean; + fbIndentNestedTypes: Boolean; + fbIndentVarAndConstInClass: Boolean; protected public @@ -85,6 +87,8 @@ type property IndentElse: boolean read fbIndentElse write fbIndentElse; property IndentCaseElse: boolean read fbIndentCaseElse write fbIndentCaseElse; + property IndentNestedTypes: Boolean read fbIndentNestedTypes write fbIndentNestedTypes; + property IndentVarAndConstInClass: Boolean read fbIndentVarAndConstInClass write fbIndentVarAndConstInClass; end; implementation @@ -108,6 +112,8 @@ const REG_INDENT_ELSE = 'IndentElse'; REG_INDENT_CASE_ELSE = 'IndentCaseElse'; + REG_INDENT_VAR_AND_CONST_IN_CLASS = 'IndentVarAndConstInClass'; + REG_INDENT_NESTED_TYPES = 'IndentNestedTypes'; constructor TSetIndent.Create; begin @@ -141,6 +147,9 @@ begin fbIndentElse := pcStream.Read(REG_INDENT_ELSE, False); fbIndentCaseElse := pcStream.Read(REG_INDENT_CASE_ELSE, True); + + fbIndentNestedTypes := pcStream.Read(REG_INDENT_NESTED_TYPES, False); + fbIndentVarAndConstInClass := pcStream.Read(REG_INDENT_VAR_AND_CONST_IN_CLASS, False); end; procedure TSetIndent.WriteToStream(const pcOut: TSettingsOutput); @@ -165,6 +174,9 @@ begin pcOut.Write(REG_INDENT_ELSE, fbIndentElse); pcOut.Write(REG_INDENT_CASE_ELSE, fbIndentCaseElse); + + pcOut.Write(REG_INDENT_NESTED_TYPES, fbIndentNestedTypes); + pcOut.Write(REG_INDENT_VAR_AND_CONST_IN_CLASS, fbIndentVarAndConstInClass); end; function TSetIndent.SpacesForIndentLevel(const piLevel: integer): integer; diff --git a/components/jcf2/Settings/SetSpaces.pas b/components/jcf2/Settings/SetSpaces.pas index 7a529ec42d..88a76d7a0a 100644 --- a/components/jcf2/Settings/SetSpaces.pas +++ b/components/jcf2/Settings/SetSpaces.pas @@ -117,7 +117,6 @@ type property SpaceBeforeOpenSquareBracketsInExpression: boolean read fbSpaceBeforeOpenSquareBracketsInExpression write fbSpaceBeforeOpenSquareBracketsInExpression; - property SpaceAfterOpenBrackets: boolean read fbSpaceAfterOpenBrackets write fbSpaceAfterOpenBrackets; property SpaceBeforeCloseBrackets: boolean read fbSpaceBeforeCloseBrackets write fbSpaceBeforeCloseBrackets; property MoveSpaceToBeforeColon: boolean read fbMoveSpaceToBeforeColon write fbMoveSpaceToBeforeColon; diff --git a/components/jcf2/Ui/Settings/frClarifyIndent.dfm b/components/jcf2/Ui/Settings/frClarifyIndent.dfm index f867ed8fa5..f548b5e784 100644 --- a/components/jcf2/Ui/Settings/frClarifyIndent.dfm +++ b/components/jcf2/Ui/Settings/frClarifyIndent.dfm @@ -1,12 +1,12 @@ inherited fClarifyIndent: TfClarifyIndent Width = 430 - Height = 307 + Height = 342 Font.Charset = ANSI_CHARSET Font.Height = -15 Font.Name = 'Segoe UI' ParentFont = False ExplicitWidth = 430 - ExplicitHeight = 307 + ExplicitHeight = 342 object Label2: TLabel Left = 4 Top = 6 @@ -32,7 +32,7 @@ inherited fClarifyIndent: TfClarifyIndent Left = 4 Top = 32 Width = 417 - Height = 257 + Height = 310 Caption = 'Options' TabOrder = 1 object cbIndentBeginEnd: TCheckBox @@ -143,5 +143,21 @@ inherited fClarifyIndent: TfClarifyIndent Caption = 'Indent for procedure body' TabOrder = 11 end + object cbIndentNestedTypes: TCheckBox + Left = 12 + Top = 250 + Width = 366 + Height = 18 + Caption = 'Indent nested types' + TabOrder = 12 + end + object cbIndentVarAndConstInClass: TCheckBox + Left = 12 + Top = 272 + Width = 366 + Height = 18 + Caption = 'Indent var and const in class' + TabOrder = 13 + end end end diff --git a/components/jcf2/Ui/Settings/frClarifyIndent.pas b/components/jcf2/Ui/Settings/frClarifyIndent.pas index b1a5846218..c3dc525416 100644 --- a/components/jcf2/Ui/Settings/frClarifyIndent.pas +++ b/components/jcf2/Ui/Settings/frClarifyIndent.pas @@ -55,6 +55,8 @@ type cbIndentCaseElse: TCheckBox; cbIndentLibraryProcs: TCheckBox; cbIndentProcedureBody: TCheckBox; + cbIndentNestedTypes: TCheckBox; + cbIndentVarAndConstInClass: TCheckBox; procedure cbIndentBeginEndClick(Sender: TObject); procedure cbHasFirstLevelIndentClick(Sender: TObject); private @@ -105,6 +107,9 @@ begin cbIndentIfElse.Checked := IndentElse; cbIndentCaseElse.Checked := IndentCaseElse; cbIndentProcedureBody.Checked := IndentProcedureBody; + + cbIndentNestedTypes.Checked := IndentNestedTypes; + cbIndentVarAndConstInClass.Checked := IndentVarAndConstInClass; end; cbIndentBeginEndClick(nil); @@ -133,6 +138,8 @@ begin IndentCaseElse := cbIndentCaseElse.Checked; IndentProcedureBody := cbIndentProcedureBody.Checked; + IndentNestedTypes := cbIndentNestedTypes.Checked; + IndentVarAndConstInClass := cbIndentVarAndConstInClass.Checked; end; end; diff --git a/components/jcf2/Utils/JcfStringUtils.pas b/components/jcf2/Utils/JcfStringUtils.pas index 9da2712079..16e78f1cbc 100644 --- a/components/jcf2/Utils/JcfStringUtils.pas +++ b/components/jcf2/Utils/JcfStringUtils.pas @@ -92,6 +92,9 @@ const NativeSingleQuote = Char(''''); +{$IFNDEF DELPHI12} +function CharInSet(const C: Char; const testSet: TSysCharSet): Boolean; +{$ENDIF} function CharIsControl(const C: Char): Boolean; function CharIsAlpha(const C: Char): Boolean; function CharIsAlphaNum(const C: Char): Boolean; @@ -167,7 +170,7 @@ uses {$IFNDEF DELPHI12} // define CharInSet for Delphi 2007 or earlier -function CharInSet(const C: Char; const testSet: TSysCharSet): boolean; +function CharInSet(const C: Char; const testSet: TSysCharSet): Boolean; begin Result := C in testSet; end; diff --git a/components/jcf2/readme.txt b/components/jcf2/readme.txt index f442d36ce6..5c62069cf8 100644 --- a/components/jcf2/readme.txt +++ b/components/jcf2/readme.txt @@ -1,3 +1,3 @@ -This directory contains a copy (sometimes modified) of r792 jcf2 svn tree: https://jedicodeformat.svn.sourceforge.net/svnroot/jedicodeformat/trunk/CodeFormat/Jcf2 +This directory contains a copy (sometimes modified) of r803 jcf2 svn tree: https://jedicodeformat.svn.sourceforge.net/svnroot/jedicodeformat/trunk/CodeFormat/Jcf2 Only command line utility works currently. \ No newline at end of file