File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < stdio.h>
2+
3+ void log (const char *file, int line, const char *func) {
4+ printf (" %s %d %s\n " , file, line, func);
5+ }
6+
7+ int main () {
8+ printf (" %s %d %s\n " , __FILE__, __LINE__, __FUNCTION__);
9+ log (__FILE__, __LINE__, __FUNCTION__);
10+ return 0 ;
11+ }
Original file line number Diff line number Diff line change 1+ extern crate libcc2rs;
2+ use libcc2rs:: * ;
3+ use std:: cell:: RefCell ;
4+ use std:: collections:: BTreeMap ;
5+ use std:: io:: prelude:: * ;
6+ use std:: io:: { Read , Seek , Write } ;
7+ use std:: os:: fd:: AsFd ;
8+ use std:: rc:: { Rc , Weak } ;
9+
10+ // macros.rs
11+ pub fn log_0 ( file : Ptr < u8 > , line : i32 , func : Ptr < u8 > ) {
12+ let file: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( file) ) ;
13+ let line: Value < i32 > = Rc :: new ( RefCell :: new ( line) ) ;
14+ let func: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( func) ) ;
15+ println ! (
16+ "{} {} {}" ,
17+ ( * file. borrow( ) ) ,
18+ ( * line. borrow( ) ) ,
19+ ( * func. borrow( ) )
20+ ) ;
21+ }
22+ pub fn main ( ) {
23+ std:: process:: exit ( main_0 ( ) ) ;
24+ }
25+ fn main_0 ( ) -> i32 {
26+ println ! (
27+ "{} {} {}" ,
28+ Ptr :: from_string_literal( "/app/cpp2rust/tests/unit/macros.cpp" ) ,
29+ 8 ,
30+ Ptr :: from_string_literal( "main" )
31+ ) ;
32+ ( {
33+ let _file: Ptr < u8 > = Ptr :: from_string_literal ( "/app/cpp2rust/tests/unit/macros.cpp" ) ;
34+ let _line: i32 = 9 ;
35+ let _func: Ptr < u8 > = Ptr :: from_string_literal ( "main" ) ;
36+ log_0 ( _file, _line, _func)
37+ } ) ;
38+ return 0 ;
39+ }
Original file line number Diff line number Diff line change 1+ extern crate libc;
2+ use libc:: * ;
3+ extern crate libcc2rs;
4+ use libcc2rs:: * ;
5+ use std:: collections:: BTreeMap ;
6+ use std:: io:: { Read , Seek , Write } ;
7+ use std:: os:: fd:: { AsFd , FromRawFd , IntoRawFd } ;
8+ use std:: rc:: Rc ;
9+
10+ // macros.rs
11+ pub unsafe fn log_0 ( mut file : * const u8 , mut line : i32 , mut func : * const u8 ) {
12+ printf ( b"%s %d %s\n \0 " . as_ptr ( ) as * const i8 , file, line, func) ;
13+ }
14+ pub fn main ( ) {
15+ unsafe {
16+ std:: process:: exit ( main_0 ( ) as i32 ) ;
17+ }
18+ }
19+ unsafe fn main_0 ( ) -> i32 {
20+ printf (
21+ b"%s %d %s\n \0 " . as_ptr ( ) as * const i8 ,
22+ b"/app/cpp2rust/tests/unit/macros.cpp\0 " . as_ptr ( ) ,
23+ 8 ,
24+ b"main\0 " . as_ptr ( ) ,
25+ ) ;
26+ ( unsafe {
27+ let _file: * const u8 = b"/app/cpp2rust/tests/unit/macros.cpp\0 " . as_ptr ( ) ;
28+ let _line: i32 = 9 ;
29+ let _func: * const u8 = b"main\0 " . as_ptr ( ) ;
30+ log_0 ( _file, _line, _func)
31+ } ) ;
32+ return 0 ;
33+ }
You can’t perform that action at this time.
0 commit comments