#FEATURE
authorClaus Gittinger <cg@exept.de>
Sun, 20 Sep 2015 11:49:13 +0200
changeset 15851 16cba5e7ac67
parent 15849 9e9179e9f829
child 15852 005d6c483bfa
#FEATURE class: Tools::TagList changed: #additionalCTagsInFile: also extract switchesand goto labels.
Tools__TagList.st
--- a/Tools__TagList.st	Wed Sep 16 19:00:15 2015 +0200
+++ b/Tools__TagList.st	Sun Sep 20 11:49:13 2015 +0200
@@ -2716,9 +2716,11 @@
 additionalCTagsInFile:aFilePath
     "additional tags, which are not found by the standard ctags utility:
         case foo:   - case label tags
+        switch:     - case label tags
+        label:      - label tags (if there is a corresponding goto)
     "
 
-    |targets line lineNr s caseLabel l|
+    |targets line lineNr s caseLabel l gotoTargets possibleLabels|
 
     self hideLabels ifTrue:[^ #()].
     showOnly notNil ifTrue:[^ #()].
@@ -2726,16 +2728,20 @@
     Tag autoload.
 
     targets := OrderedCollection new.
+    gotoTargets := Set new.
+    possibleLabels := OrderedCollection new.
+
     s := aFilePath asFilename readStream.
     s notNil ifTrue:[
+        lineNr := 0.
         s := LineNumberReadStream readingFrom:s.
         [s atEnd] whileFalse:[
+            lineNr := lineNr + 1.
             line := s nextLine withoutSeparators.
             ((line startsWith:'case ') and:[line includes:$:]) ifTrue:[
                 l := line readStream. 
                 l skip:5.
                 caseLabel := l upTo:$:.
-                lineNr := s lineNumber - 1.
                 targets add:(Tag::TCaseLabel
                                 label:'case ' allItalic , caseLabel",' <case>' allItalic"
                                 pattern:nil
@@ -2743,17 +2749,57 @@
                                 lineNumber:lineNr).
             ] ifFalse:[
                 (line startsWith:'default:') ifTrue:[
-                    lineNr := s lineNumber - 1.
                     targets add:(Tag::TCaseLabel
-                                    label:'case ' allItalic, 'default'",' <case>' allItalic"
+                                    label:'case ' allItalic, 'default'
                                     pattern:nil
                                     type:nil
                                     lineNumber:lineNr).
-                ].
+                ] ifFalse:[
+                    ((line startsWith:'switch') and:[line includes:$(]) ifTrue:[
+                        l := line readStream. 
+                        l skip:6.
+                        l skipSeparators.
+                        l peek == $( ifTrue:[
+                            l next.
+                            caseLabel := '(',(l upTo:$) )withoutSeparators,')'.
+                            targets add:(Tag::TCaseLabel
+                                        label:'switch ' allItalic , caseLabel
+                                        pattern:nil
+                                        type:nil
+                                        lineNumber:lineNr).
+                        ]
+                    ] ifFalse:[
+                        (line startsWith:'goto ') ifTrue:[
+                            |targetLabel|
+                            l := line readStream. 
+                            l skip:5.
+                            l skipSeparators.
+                            targetLabel := (l upTo:$; ) withoutSeparators.
+                            gotoTargets add:targetLabel.
+                        ] ifFalse:[
+                            (line includes:$:) ifTrue:[
+                                |label|
+                                label := (line upTo:$:) withoutSeparators.
+                                ((label first isLetter or:[label first = $_])
+                                and:[ label conform:[:ch | ch isLetterOrDigit or:[ch = $_]]]) ifTrue:[
+                                    possibleLabels 
+                                        add:(Tag::TCaseLabel
+                                            label:'label ' allItalic , label
+                                            pattern:label
+                                            type:nil
+                                            lineNumber:lineNr)
+                                ].
+                            ].
+                        ].
+                    ]
+                ]
             ].
         ].
         s close
     ].
+    possibleLabels 
+        select:[:lbl | gotoTargets includes:lbl pattern]
+        thenDo:[:lbl | targets add:lbl].
     ^ targets
 !