2
2
3
3
import cpp
4
4
5
- private string relativePath ( File file ) { result = file .getRelativePath ( ) .replaceAll ( "\\" , "/" ) }
6
-
7
- cached
8
- private predicate tokenLocation ( string path , int sl , int sc , int ec , int el , Copy copy , int index ) {
9
- path = copy .sourceFile ( ) .getAbsolutePath ( ) and
10
- tokens ( copy , index , sl , sc , ec , el )
11
- }
12
-
13
- /** A token block used for detection of duplicate and similar code. */
14
- class Copy extends @duplication_or_similarity {
15
- /** Gets the index of the last token in this block. */
16
- private int lastToken ( ) { result = max ( int i | tokens ( this , i , _, _, _, _) | i ) }
5
+ private newtype TDuplicationOrSimilarity = MKDuplicationOrSimilarity ( )
17
6
7
+ /**
8
+ * DEPRECATED: This class is no longer used.
9
+ *
10
+ * A token block used for detection of duplicate and similar code.
11
+ */
12
+ class Copy extends TDuplicationOrSimilarity {
18
13
/** Gets the index of the token in this block starting at the location `loc`, if any. */
19
- int tokenStartingAt ( Location loc ) {
20
- exists ( string filepath , int startline , int startcol |
21
- loc .hasLocationInfo ( filepath , startline , startcol , _, _) and
22
- tokenLocation ( filepath , startline , startcol , _, _, this , result )
23
- )
24
- }
14
+ int tokenStartingAt ( Location loc ) { none ( ) }
25
15
26
16
/** Gets the index of the token in this block ending at the location `loc`, if any. */
27
- int tokenEndingAt ( Location loc ) {
28
- exists ( string filepath , int endline , int endcol |
29
- loc .hasLocationInfo ( filepath , _, _, endline , endcol ) and
30
- tokenLocation ( filepath , _, _, endline , endcol , this , result )
31
- )
32
- }
17
+ int tokenEndingAt ( Location loc ) { none ( ) }
33
18
34
19
/** Gets the line on which the first token in this block starts. */
35
- int sourceStartLine ( ) { tokens ( this , 0 , result , _ , _ , _ ) }
20
+ int sourceStartLine ( ) { none ( ) }
36
21
37
22
/** Gets the column on which the first token in this block starts. */
38
- int sourceStartColumn ( ) { tokens ( this , 0 , _ , result , _ , _ ) }
23
+ int sourceStartColumn ( ) { none ( ) }
39
24
40
25
/** Gets the line on which the last token in this block ends. */
41
- int sourceEndLine ( ) { tokens ( this , this . lastToken ( ) , _ , _ , result , _ ) }
26
+ int sourceEndLine ( ) { none ( ) }
42
27
43
28
/** Gets the column on which the last token in this block ends. */
44
- int sourceEndColumn ( ) { tokens ( this , this . lastToken ( ) , _ , _ , _ , result ) }
29
+ int sourceEndColumn ( ) { none ( ) }
45
30
46
31
/** Gets the number of lines containing at least (part of) one token in this block. */
47
32
int sourceLines ( ) { result = this .sourceEndLine ( ) + 1 - this .sourceStartLine ( ) }
48
33
49
34
/** Gets an opaque identifier for the equivalence class of this block. */
50
- int getEquivalenceClass ( ) { duplicateCode ( this , _ , result ) or similarCode ( this , _ , result ) }
35
+ int getEquivalenceClass ( ) { none ( ) }
51
36
52
37
/** Gets the source file in which this block appears. */
53
- File sourceFile ( ) {
54
- exists ( string name | duplicateCode ( this , name , _) or similarCode ( this , name , _) |
55
- name .replaceAll ( "\\" , "/" ) = relativePath ( result )
56
- )
57
- }
38
+ File sourceFile ( ) { none ( ) }
58
39
59
40
/**
60
41
* Holds if this element is at the specified location.
@@ -77,15 +58,23 @@ class Copy extends @duplication_or_similarity {
77
58
string toString ( ) { none ( ) }
78
59
}
79
60
80
- /** A block of duplicated code. */
81
- class DuplicateBlock extends Copy , @duplication {
61
+ /**
62
+ * DEPRECATED: This class is no longer used.
63
+ *
64
+ * A block of duplicated code.
65
+ */
66
+ class DuplicateBlock extends Copy {
82
67
override string toString ( ) {
83
68
result = "Duplicate code: " + this .sourceLines ( ) + " duplicated lines."
84
69
}
85
70
}
86
71
87
- /** A block of similar code. */
88
- class SimilarBlock extends Copy , @similarity {
72
+ /**
73
+ * DEPRECATED: This class is no longer used.
74
+ *
75
+ * A block of similar code.
76
+ */
77
+ class SimilarBlock extends Copy {
89
78
override string toString ( ) {
90
79
result = "Similar code: " + this .sourceLines ( ) + " almost duplicated lines."
91
80
}
0 commit comments