Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert CStyleCastExpr <ToVoid> to _ #393

Closed
Konstantin8105 opened this issue Dec 3, 2017 · 4 comments
Closed

convert CStyleCastExpr <ToVoid> to _ #393

Konstantin8105 opened this issue Dec 3, 2017 · 4 comments

Comments

@Konstantin8105
Copy link
Contributor

Example in clang AST tree:

|-FunctionDecl 0x26b0288 <line:1778:1, line:1783:1> line:1778:13 used interrupt_handler 'void (int)' static
| |-ParmVarDecl 0x26b0200 <col:31, col:35> col:35 used NotUsed 'int'
| `-CompoundStmt 0x26b0740 <col:43, line:1783:1>
|   |-CStyleCastExpr 0x26b03c8 <line:1779:3, col:17> 'void' <ToVoid>
|   | `-ImplicitCastExpr 0x26b03b0 <col:9, col:17> 'int' <LValueToRValue>
|   |   `-ParenExpr 0x26b0390 <col:9, col:17> 'int' lvalue
|   |     `-DeclRefExpr 0x26b0328 <col:10> 'int' lvalue ParmVar 0x26b0200 'NotUsed' 'int'
|   |   |   |   |-CStyleCastExpr 0x26bc970 <col:20, col:29> 'void' <ToVoid>
|   |   |   |   | `-ParenExpr 0x26bc950 <col:27, col:29> 'int'
|   |   |   |   |   `-IntegerLiteral 0x26bc8f0 <col:28> 'int' 0
|   |-CStyleCastExpr 0x26d01f0 <line:2210:3, col:12> 'void' <ToVoid>
|   | `-ImplicitCastExpr 0x26d01d8 <col:9, col:12> 'char **' <LValueToRValue>
|   |   `-ParenExpr 0x26d01b8 <col:9, col:12> 'char **' lvalue
|   |     `-DeclRefExpr 0x26d0150 <col:10> 'char **' lvalue ParmVar 0x26cfe60 'az' 'char **'
@elliotchance
Copy link
Owner

I'm not sure what this issue is for?

@Konstantin8105
Copy link
Contributor Author

Konstantin8105 commented Dec 7, 2017

In according to shell.c:

|-FunctionDecl 0x24e3650 <line:3009:1, line:3020:1> line:3009:12 used captureOutputCallback 'int (void *, int, char **, char **)' static
| |-ParmVarDecl 0x24e3450 <col:34, col:40> col:40 used pArg 'void *'
| |-ParmVarDecl 0x24e34c0 <col:46, col:50> col:50 used nArg 'int'
| |-ParmVarDecl 0x24e3538 <col:56, col:63> col:63 used azArg 'char **'
| |-ParmVarDecl 0x24e35b0 <col:70, col:77> col:77 used az 'char **'
| `-CompoundStmt 0x24e4360 <col:80, line:3020:1>
|   |-DeclStmt 0x24e3800 <line:3010:3, col:34>
|   | `-VarDecl 0x24e3728 <col:3, col:30> col:14 used p 'ShellText *' cinit
|   |   `-CStyleCastExpr 0x24e37d8 <col:18, col:30> 'ShellText *' <BitCast>
|   |     `-ImplicitCastExpr 0x24e37c0 <col:30> 'void *' <LValueToRValue>
|   |       `-DeclRefExpr 0x24e3788 <col:30> 'void *' lvalue ParmVar 0x24e3450 'pArg' 'void *'
|   |-DeclStmt 0x24e3888 <line:3011:3, col:8>
|   | `-VarDecl 0x24e3828 <col:3, col:7> col:7 used i 'int'
|   |-CStyleCastExpr 0x24e3940 <line:3012:3, col:12> 'void' <ToVoid>
|   | `-ImplicitCastExpr 0x24e3928 <col:9, col:12> 'char **' <LValueToRValue>
|   |   `-ParenExpr 0x24e3908 <col:9, col:12> 'char **' lvalue
|   |     `-DeclRefExpr 0x24e38a0 <col:10> 'char **' lvalue ParmVar 0x24e35b0 'az' 'char **'
|   |-IfStmt 0x24e3a40 <line:3013:3, col:25>
/*
** This is the callback routine from sqlite3_exec() that appends all
** output onto the end of a ShellText object.
*/
static int captureOutputCallback(void *pArg, int nArg, char **azArg, char **az){
  ShellText *p = (ShellText*)pArg;
  int i;
  UNUSED_PARAMETER(az);
  if( azArg==0 ) return 0;
//.....
/*
** Used to prevent warnings about unused parameters
*/
#define UNUSED_PARAMETER(x) (void)(x)

Example of C code for tests:

int main(){
        char **az;
        (void)(az);
        return 0;
}

In AST:

`-FunctionDecl 0x21a44c8 <1.c:1:1, line:5:1> line:1:5 main 'int ()'
  `-CompoundStmt 0x21a4768 <col:11, line:5:1>
    |-DeclStmt 0x21a4650 <line:2:9, col:18>
    | `-VarDecl 0x21a45f0 <col:9, col:16> col:16 used az 'char **'
    |-CStyleCastExpr 0x21a4708 <line:3:9, col:18> 'void' <ToVoid>
    | `-ImplicitCastExpr 0x21a46f0 <col:15, col:18> 'char **' <LValueToRValue>
    |   `-ParenExpr 0x21a46d0 <col:15, col:18> 'char **' lvalue
    |     `-DeclRefExpr 0x21a4668 <col:16> 'char **' lvalue Var 0x21a45f0 'az' 'char **'
    `-ReturnStmt 0x21a4750 <line:4:9, col:16>
      `-IntegerLiteral 0x21a4730 <col:16> 'int' 0

Result of Go code:

package main

func main() {
        __init()
        var az [][]byte
        (az)
        return
}
func __init() {
}
○ → go build 1.go
# command-line-arguments
./1.go:8: az evaluated but not used

@Konstantin8105
Copy link
Contributor Author

Konstantin8105 commented Dec 7, 2017

In according to sqlite3.c:
In C code:

SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int op){
  wsdStatInit;
  assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
  assert( op>=0 && op<ArraySize(statMutex) );
  assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
                                           : sqlite3MallocMutex()) );
  return wsdStat.nowValue[op];
}

In AST tree:

|-FunctionDecl 0x28793d0 prev 0x2803c88 <line:19129:1, line:19136:1> line:19129:22 used sqlite3StatusValue 'sqlite3_int64 (int)' static
| |-ParmVarDecl 0x2879348 <col:41, col:45> col:45 used op 'int'
| `-CompoundStmt 0x2879820 <col:48, line:19136:1>
|   |-NullStmt 0x2879480 <line:19130:14>
|   |-ParenExpr 0x2879538 <line:19131:3, col:14> 'void'
|   | `-CStyleCastExpr 0x2879510 <col:4, col:13> 'void' <ToVoid>
|   |   `-ParenExpr 0x28794f0 <col:11, col:13> 'int'
|   |     `-IntegerLiteral 0x2879490 <col:12> 'int' 0

Go result:

func sqlite3StatusValue(op int) sqlite3_int64 {
        (0)
        (0)
        (0)
        return sqlite3Stat.nowValue[op]
}

@Konstantin8105
Copy link
Contributor Author

In my point of view, in Go interpretation it is like : _ = variable

@Konstantin8105 Konstantin8105 changed the title CStyleCastExpr <ToVoid> convert CStyleCastExpr <ToVoid> to _ Dec 7, 2017
elliotchance pushed a commit that referenced this issue Dec 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants