2929
3030import com .oracle .truffle .api .instrumentation .SourceFilter ;
3131import com .oracle .truffle .api .instrumentation .SourceSectionFilter ;
32+ import com .oracle .truffle .api .instrumentation .Tag ;
3233import com .oracle .truffle .api .instrumentation .SourceSectionFilter .IndexRange ;
3334import com .oracle .truffle .api .instrumentation .TruffleInstrument ;
3435import com .oracle .truffle .api .source .Source ;
@@ -51,12 +52,12 @@ abstract class BreakpointLocation {
5152 */
5253 static final BreakpointLocation ANY = new BreakpointSourceLocation ();
5354
54- static BreakpointLocation create (Object key , SourceElement [] sourceElements , SourceSection sourceSection ) {
55- return new BreakpointSourceLocation (key , sourceElements , sourceSection );
55+ static BreakpointLocation create (Object key , SourceElement [] sourceElements , SourceSection sourceSection , Class <? extends Tag > tag ) {
56+ return new BreakpointSourceLocation (key , sourceElements , sourceSection , tag );
5657 }
5758
58- static BreakpointLocation create (Object key , SourceElement [] sourceElements , int line , int column ) {
59- return new BreakpointSourceLocation (key , sourceElements , line , column );
59+ static BreakpointLocation create (Object key , SourceElement [] sourceElements , int line , int column , Class <? extends Tag > tag ) {
60+ return new BreakpointSourceLocation (key , sourceElements , line , column , tag );
6061 }
6162
6263 static BreakpointLocation create (SourceElement [] sourceElements , SuspensionFilter filter ) {
@@ -69,11 +70,14 @@ static BreakpointLocation create(SourceElement[] sourceElements, SuspensionFilte
6970
7071 abstract SourceSectionFilter createLocationFilter (Source source , SuspendAnchor suspendAnchor );
7172
72- private static void setTags (SourceSectionFilter .Builder f , SourceElement [] sourceElements ) {
73- Class <?>[] elementTags = new Class <?>[sourceElements .length ];
74- for (int i = 0 ; i < elementTags .length ; i ++) {
73+ private static void setTags (SourceSectionFilter .Builder f , SourceElement [] sourceElements , Class <? extends Tag > tag ) {
74+ Class <?>[] elementTags = new Class <?>[sourceElements .length + (( tag == null ) ? 0 : 1 ) ];
75+ for (int i = 0 ; i < sourceElements .length ; i ++) {
7576 elementTags [i ] = sourceElements [i ].getTag ();
7677 }
78+ if (tag != null ) {
79+ elementTags [elementTags .length - 1 ] = tag ;
80+ }
7781 f .tagIs (elementTags );
7882 }
7983
@@ -85,25 +89,28 @@ private static final class BreakpointSourceLocation extends BreakpointLocation {
8589 private int line ;
8690 private int column ;
8791
92+ private final Class <? extends Tag > tag ;
93+
8894 /**
8995 * @param key non-null source identifier
9096 * @param line 1-based line number, -1 for unspecified
9197 */
92- BreakpointSourceLocation (Object key , SourceElement [] sourceElements , SourceSection sourceSection ) {
98+ BreakpointSourceLocation (Object key , SourceElement [] sourceElements , SourceSection sourceSection , Class <? extends Tag > tag ) {
9399 assert key instanceof Source || key instanceof URI ;
94100 this .key = key ;
95101 this .sourceElements = sourceElements ;
96102 this .sourceSection = sourceSection ;
97103 this .line = -1 ;
98104 this .column = -1 ;
105+ this .tag = tag ;
99106 }
100107
101108 /**
102109 * @param key non-null source identifier
103110 * @param line 1-based line number
104111 * @param column 1-based column number, -1 for unspecified
105112 */
106- BreakpointSourceLocation (Object key , SourceElement [] sourceElements , int line , int column ) {
113+ BreakpointSourceLocation (Object key , SourceElement [] sourceElements , int line , int column , Class <? extends Tag > tag ) {
107114 assert key instanceof Source || key instanceof URI ;
108115 assert line > 0 ;
109116 assert column > 0 || column == -1 ;
@@ -112,6 +119,7 @@ private static final class BreakpointSourceLocation extends BreakpointLocation {
112119 this .line = line ;
113120 this .column = column ;
114121 this .sourceSection = null ;
122+ this .tag = tag ;
115123 }
116124
117125 private BreakpointSourceLocation () {
@@ -120,6 +128,7 @@ private BreakpointSourceLocation() {
120128 this .line = -1 ;
121129 this .column = -1 ;
122130 this .sourceSection = null ;
131+ this .tag = null ;
123132 }
124133
125134 @ Override
@@ -159,7 +168,7 @@ SourceSection adjustLocation(Source source, TruffleInstrument.Env env, SuspendAn
159168 return null ;
160169 }
161170 boolean hasColumn = column > 0 ;
162- SourceSection location = SuspendableLocationFinder .findNearest (source , sourceElements , line , column , suspendAnchor , env );
171+ SourceSection location = SuspendableLocationFinder .findNearest (source , sourceElements , line , column , tag , suspendAnchor , env );
163172 if (location != null ) {
164173 switch (suspendAnchor ) {
165174 case BEFORE :
@@ -213,7 +222,7 @@ SourceSectionFilter createLocationFilter(Source source, SuspendAnchor suspendAnc
213222 if (sourceSection != null ) {
214223 f .sourceSectionEquals (sourceSection );
215224 }
216- setTags (f , sourceElements );
225+ setTags (f , sourceElements , tag );
217226 return f .build ();
218227 }
219228
@@ -267,7 +276,7 @@ SourceSectionFilter createLocationFilter(Source source, SuspendAnchor suspendAnc
267276 }
268277 SourceFilter sourceFilter = sourceFilterBuilder .build ();
269278 f .sourceFilter (sourceFilter );
270- setTags (f , sourceElements );
279+ setTags (f , sourceElements , null );
271280 return f .build ();
272281 }
273282
0 commit comments