@@ -20,15 +20,15 @@ use cexpr::literal::CChar;
20
20
// main testing routine
21
21
fn test_definition ( ident : Vec < u8 > , tokens : & [ Token ] , idents : & mut HashMap < Vec < u8 > , EvalResult > ) -> bool {
22
22
use cexpr:: expr:: EvalResult :: * ;
23
-
23
+
24
24
let display_name=String :: from_utf8_lossy ( & ident) . into_owned ( ) ;
25
25
26
26
let test={
27
27
// Split name such as Str_test_string into (Str,test_string)
28
28
let pos=ident. iter ( ) . position ( |c|* c==b'_' ) . expect ( & format ! ( "Invalid definition in testcase: {}" , display_name) ) ;
29
29
let expected=& ident[ ..pos] ;
30
30
let value=& ident[ ( pos+1 ) ..] ;
31
-
31
+
32
32
if expected==b"Str" {
33
33
Some ( Str ( value. to_owned ( ) ) )
34
34
} else if expected==b"Int" {
@@ -74,14 +74,16 @@ unsafe fn clang_str_to_vec(s: CXString) -> Vec<u8> {
74
74
vec
75
75
}
76
76
77
+ #[ allow( non_upper_case_globals) ]
77
78
unsafe fn token_clang_to_cexpr ( tu : CXTranslationUnit , orig : & CXToken ) -> Token {
78
79
Token {
79
80
kind : match clang_getTokenKind ( * orig) {
80
- CXTokenKind :: Comment => cexpr:: token:: Kind :: Comment ,
81
- CXTokenKind :: Identifier => cexpr:: token:: Kind :: Identifier ,
82
- CXTokenKind :: Keyword => cexpr:: token:: Kind :: Keyword ,
83
- CXTokenKind :: Literal => cexpr:: token:: Kind :: Literal ,
84
- CXTokenKind :: Punctuation => cexpr:: token:: Kind :: Punctuation ,
81
+ CXToken_Comment => cexpr:: token:: Kind :: Comment ,
82
+ CXToken_Identifier => cexpr:: token:: Kind :: Identifier ,
83
+ CXToken_Keyword => cexpr:: token:: Kind :: Keyword ,
84
+ CXToken_Literal => cexpr:: token:: Kind :: Literal ,
85
+ CXToken_Punctuation => cexpr:: token:: Kind :: Punctuation ,
86
+ _ => panic ! ( "invalid token kind: {:?}" , * orig) ,
85
87
} ,
86
88
raw : clang_str_to_vec ( clang_getTokenSpelling ( tu, * orig) ) . into_boxed_slice ( )
87
89
}
@@ -104,7 +106,7 @@ unsafe fn location_in_scope(r: CXSourceRange) -> bool {
104
106
let mut file=CXFile ( ptr:: null_mut ( ) ) ;
105
107
clang_getSpellingLocation ( start, & mut file, ptr:: null_mut ( ) , ptr:: null_mut ( ) , ptr:: null_mut ( ) ) ;
106
108
clang_Location_isFromMainFile ( start) !=0
107
- && clang_Location_isInSystemHeader ( start) ==0
109
+ && clang_Location_isInSystemHeader ( start) ==0
108
110
&& file. 0 !=ptr:: null_mut ( )
109
111
}
110
112
@@ -123,21 +125,21 @@ fn test_file(file: &str) -> bool {
123
125
ptr:: null_mut( ) , 0 ,
124
126
CXTranslationUnit_DetailedPreprocessingRecord ,
125
127
& mut tu
126
- ) ==CXErrorCode :: Success , "Failure reading test case {}" , file) ;
128
+ ) ==CXError_Success , "Failure reading test case {}" , file) ;
127
129
tu
128
130
} ;
129
131
visit_children ( clang_getTranslationUnitCursor ( tu) , |cur, _parent| {
130
- if cur. kind ==CXCursorKind :: MacroDefinition {
132
+ if cur. kind ==CXCursor_MacroDefinition {
131
133
let mut range=clang_getCursorExtent ( cur) ;
132
- if !location_in_scope ( range) { return CXChildVisitResult :: Continue }
134
+ if !location_in_scope ( range) { return CXChildVisit_Continue }
133
135
range. end_int_data -=1 ; // clang bug for macros only
134
136
let mut token_ptr=ptr:: null_mut ( ) ;
135
137
let mut num=0 ;
136
138
clang_tokenize ( tu, range, & mut token_ptr, & mut num) ;
137
139
if token_ptr!=ptr:: null_mut ( ) {
138
140
let tokens=slice:: from_raw_parts ( token_ptr, num as usize ) ;
139
141
let tokens: Vec < _ > =tokens. iter ( ) . filter_map ( |t|
140
- if clang_getTokenKind ( * t) !=CXTokenKind :: Comment {
142
+ if clang_getTokenKind ( * t) !=CXToken_Comment {
141
143
Some ( token_clang_to_cexpr ( tu, t) )
142
144
} else {
143
145
None
@@ -147,7 +149,7 @@ fn test_file(file: &str) -> bool {
147
149
all_succeeded&=test_definition ( clang_str_to_vec ( clang_getCursorSpelling ( cur) ) , & tokens, & mut idents) ;
148
150
}
149
151
}
150
- CXChildVisitResult :: Continue
152
+ CXChildVisit_Continue
151
153
} ) ;
152
154
clang_disposeTranslationUnit ( tu) ;
153
155
} ;
0 commit comments