From f05de01d89453348d597ed9d8c5814692d196b43 Mon Sep 17 00:00:00 2001 From: cedretaber Date: Sat, 8 Oct 2022 01:25:25 +0900 Subject: [PATCH 1/6] Add union type. --- sample/types/union.c | 49 + sample/types/union.c.yojson | 3583 +++++++++++++++++++++++++++++++++++ src/lib/ast.ml | 37 +- src/lib/ast.mli | 9 + src/lib/ast2cabs.ml | 5 + src/lib/yojson2ast.ml | 43 +- 6 files changed, 3708 insertions(+), 18 deletions(-) create mode 100644 sample/types/union.c create mode 100644 sample/types/union.c.yojson diff --git a/sample/types/union.c b/sample/types/union.c new file mode 100644 index 0000000..53c134f --- /dev/null +++ b/sample/types/union.c @@ -0,0 +1,49 @@ + +union U1 { + int x; + long y; +}; + +typedef union { + int x; + long y; +} U2; + +union U3; + +union U4 { + unsigned int x : 8; + unsigned int y : 12; +}; + +int main(void) +{ + union U1 u11, u12; + u11.x = 42; + u12.y = 99; + union U1 u13 = { 1 }; + + U2 u21, u22; + u21.x = 42; + u22.y = 99; + U2 u23 = { .y = 1 }; + + union U4 u4; + u4.x = 0; + u4.y = 1; + + union U5 { + int x; + float y; + }; + union U5 u51, u52, u53 = { 1 }; + u51.x = 42; + u52.y = 3.14; + + union { + int n; + float r; + } u6; + u6.n = 7; + u6.r = 1.41; +} diff --git a/sample/types/union.c.yojson b/sample/types/union.c.yojson new file mode 100644 index 0000000..60bf373 --- /dev/null +++ b/sample/types/union.c.yojson @@ -0,0 +1,3583 @@ +<"TranslationUnitDecl" : ( + { + "pointer" : 1, + "source_range" : ( + { + }, + { + } + ) + }, + [ + <"TypedefDecl" : ( + { + "pointer" : 2, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__int128_t", + "qual_name" : [ + "__int128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 3, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__uint128_t", + "qual_name" : [ + "__uint128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 4, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__NSConstantString", + "qual_name" : [ + "__NSConstantString" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 5, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_ms_va_list", + "qual_name" : [ + "__builtin_ms_va_list" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 6, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_va_list", + "qual_name" : [ + "__builtin_va_list" + ] + }, + 0, + { + } + )>, + <"RecordDecl" : ( + { + "pointer" : 7, + "parent_pointer" : 1, + "source_range" : ( + { + "file" : "sample/types/union.c", + "line" : 2, + "column" : 1 + }, + { + "line" : 5, + "column" : 1 + } + ) + }, + { + "name" : "U1", + "qual_name" : [ + "U1" + ] + }, + 8, + [ + <"FieldDecl" : ( + { + "pointer" : 9, + "parent_pointer" : 7, + "source_range" : ( + { + "line" : 3, + "column" : 5 + }, + { + "column" : 9 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "x", + "qual_name" : [ + "x", + "U1" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"FieldDecl" : ( + { + "pointer" : 11, + "parent_pointer" : 7, + "source_range" : ( + { + "line" : 4, + "column" : 5 + }, + { + "column" : 10 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "y", + "qual_name" : [ + "y", + "U1" + ] + }, + { + "type_ptr" : 12 + }, + { + } + )> + ], + { + }, + <"TTK_Union">, + { + "definition_ptr" : 7, + "is_complete_definition" : true + } + )>, + <"RecordDecl" : ( + { + "pointer" : 13, + "parent_pointer" : 1, + "source_range" : ( + { + "line" : 7, + "column" : 9 + }, + { + "line" : 10, + "column" : 1 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "U2" + ] + }, + 14, + [ + <"FieldDecl" : ( + { + "pointer" : 15, + "parent_pointer" : 13, + "source_range" : ( + { + "line" : 8, + "column" : 5 + }, + { + "column" : 9 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "x", + "qual_name" : [ + "x", + "U2" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"FieldDecl" : ( + { + "pointer" : 16, + "parent_pointer" : 13, + "source_range" : ( + { + "line" : 9, + "column" : 5 + }, + { + "column" : 10 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "y", + "qual_name" : [ + "y", + "U2" + ] + }, + { + "type_ptr" : 12 + }, + { + } + )> + ], + { + }, + <"TTK_Union">, + { + "definition_ptr" : 13, + "is_complete_definition" : true + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 17, + "source_range" : ( + { + "line" : 7, + "column" : 1 + }, + { + "line" : 10, + "column" : 3 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "U2", + "qual_name" : [ + "U2" + ] + }, + 18, + { + } + )>, + <"RecordDecl" : ( + { + "pointer" : 19, + "parent_pointer" : 1, + "source_range" : ( + { + "line" : 12, + "column" : 1 + }, + { + "column" : 7 + } + ) + }, + { + "name" : "U3", + "qual_name" : [ + "U3" + ] + }, + 20, + [ + ], + { + }, + <"TTK_Union">, + { + "definition_ptr" : 0 + } + )>, + <"RecordDecl" : ( + { + "pointer" : 21, + "parent_pointer" : 1, + "source_range" : ( + { + "line" : 14, + "column" : 1 + }, + { + "line" : 17, + "column" : 1 + } + ) + }, + { + "name" : "U4", + "qual_name" : [ + "U4" + ] + }, + 22, + [ + <"FieldDecl" : ( + { + "pointer" : 23, + "parent_pointer" : 21, + "source_range" : ( + { + "line" : 15, + "column" : 5 + }, + { + "column" : 22 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "x", + "qual_name" : [ + "x", + "U4" + ] + }, + { + "type_ptr" : 24 + }, + { + "bit_width_expr" : <"ConstantExpr" : ( + { + "pointer" : 25, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 26, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "8" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + } + )> + } + )>, + <"FieldDecl" : ( + { + "pointer" : 27, + "parent_pointer" : 21, + "source_range" : ( + { + "line" : 16, + "column" : 5 + }, + { + "column" : 22 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "y", + "qual_name" : [ + "y", + "U4" + ] + }, + { + "type_ptr" : 24 + }, + { + "bit_width_expr" : <"ConstantExpr" : ( + { + "pointer" : 28, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 29, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "12" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + } + )> + } + )> + ], + { + }, + <"TTK_Union">, + { + "definition_ptr" : 21, + "is_complete_definition" : true + } + )>, + <"FunctionDecl" : ( + { + "pointer" : 30, + "source_range" : ( + { + "line" : 19, + "column" : 1 + }, + { + "line" : 49, + "column" : 1 + } + ) + }, + { + "name" : "main", + "qual_name" : [ + "main" + ] + }, + { + "type_ptr" : 31 + }, + { + "decl_ptr_with_body" : 30, + "body" : <"CompoundStmt" : ( + { + "pointer" : 32, + "source_range" : ( + { + "line" : 20, + "column" : 1 + }, + { + "line" : 49, + "column" : 1 + } + ) + }, + [ + <"DeclStmt" : ( + { + "pointer" : 33, + "source_range" : ( + { + "line" : 21, + "column" : 5 + }, + { + "column" : 22 + } + ) + }, + [ + ], + [ + <"VarDecl" : ( + { + "pointer" : 34, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 14 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "u11", + "qual_name" : [ + "u11" + ] + }, + { + "type_ptr" : 35 + }, + { + } + )>, + <"VarDecl" : ( + { + "pointer" : 36, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 19 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "u12", + "qual_name" : [ + "u12" + ] + }, + { + "type_ptr" : 35 + }, + { + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 37, + "source_range" : ( + { + "line" : 22, + "column" : 5 + }, + { + "column" : 13 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 38, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 9 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 39, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 35 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 34, + "name" : { + "name" : "u11", + "qual_name" : [ + "u11" + ] + }, + "qual_type" : { + "type_ptr" : 35 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "x", + "qual_name" : [ + "x", + "U1" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 9, + "name" : { + "name" : "x", + "qual_name" : [ + "x", + "U1" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 40, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "42" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 41, + "source_range" : ( + { + "line" : 23, + "column" : 5 + }, + { + "column" : 13 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 42, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 9 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 43, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 35 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 36, + "name" : { + "name" : "u12", + "qual_name" : [ + "u12" + ] + }, + "qual_type" : { + "type_ptr" : 35 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "y", + "qual_name" : [ + "y", + "U1" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 11, + "name" : { + "name" : "y", + "qual_name" : [ + "y", + "U1" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 44, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 45, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "99" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"DeclStmt" : ( + { + "pointer" : 46, + "source_range" : ( + { + "line" : 24, + "column" : 5 + }, + { + "column" : 25 + } + ) + }, + [ + <"InitListExpr" : ( + { + "pointer" : 47, + "source_range" : ( + { + "column" : 20 + }, + { + "column" : 24 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 48, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 35 + } + } + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 49, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 24 + } + ) + }, + { + "name" : "u13", + "qual_name" : [ + "u13" + ] + }, + { + "type_ptr" : 35 + }, + { + "init_expr" : <"InitListExpr" : ( + { + "pointer" : 47, + "source_range" : ( + { + "column" : 20 + }, + { + "column" : 24 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 48, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 35 + } + } + )> + } + )> + ] + )>, + <"DeclStmt" : ( + { + "pointer" : 50, + "source_range" : ( + { + "line" : 26, + "column" : 5 + }, + { + "column" : 16 + } + ) + }, + [ + ], + [ + <"VarDecl" : ( + { + "pointer" : 51, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 8 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "u21", + "qual_name" : [ + "u21" + ] + }, + { + "type_ptr" : 18 + }, + { + } + )>, + <"VarDecl" : ( + { + "pointer" : 52, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 13 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "u22", + "qual_name" : [ + "u22" + ] + }, + { + "type_ptr" : 18 + }, + { + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 53, + "source_range" : ( + { + "line" : 27, + "column" : 5 + }, + { + "column" : 13 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 54, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 9 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 55, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 18 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 51, + "name" : { + "name" : "u21", + "qual_name" : [ + "u21" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "x", + "qual_name" : [ + "x", + "U2" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 15, + "name" : { + "name" : "x", + "qual_name" : [ + "x", + "U2" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 56, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "42" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 57, + "source_range" : ( + { + "line" : 28, + "column" : 5 + }, + { + "column" : 13 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 58, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 9 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 59, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 18 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 52, + "name" : { + "name" : "u22", + "qual_name" : [ + "u22" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "y", + "qual_name" : [ + "y", + "U2" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 16, + "name" : { + "name" : "y", + "qual_name" : [ + "y", + "U2" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 60, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 61, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "99" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"DeclStmt" : ( + { + "pointer" : 62, + "source_range" : ( + { + "line" : 29, + "column" : 5 + }, + { + "column" : 24 + } + ) + }, + [ + <"InitListExpr" : ( + { + "pointer" : 63, + "source_range" : ( + { + "column" : 14 + }, + { + "column" : 23 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 64, + "source_range" : ( + { + "column" : 21 + }, + { + "column" : 21 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 65, + "source_range" : ( + { + "column" : 21 + }, + { + "column" : 21 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + } + } + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 66, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 23 + } + ) + }, + { + "name" : "u23", + "qual_name" : [ + "u23" + ] + }, + { + "type_ptr" : 18 + }, + { + "init_expr" : <"InitListExpr" : ( + { + "pointer" : 63, + "source_range" : ( + { + "column" : 14 + }, + { + "column" : 23 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 64, + "source_range" : ( + { + "column" : 21 + }, + { + "column" : 21 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 65, + "source_range" : ( + { + "column" : 21 + }, + { + "column" : 21 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + } + } + )> + } + )> + ] + )>, + <"DeclStmt" : ( + { + "pointer" : 67, + "source_range" : ( + { + "line" : 31, + "column" : 5 + }, + { + "column" : 16 + } + ) + }, + [ + ], + [ + <"VarDecl" : ( + { + "pointer" : 68, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 14 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "u4", + "qual_name" : [ + "u4" + ] + }, + { + "type_ptr" : 69 + }, + { + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 70, + "source_range" : ( + { + "line" : 32, + "column" : 5 + }, + { + "column" : 12 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 71, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 8 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 72, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 69 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 68, + "name" : { + "name" : "u4", + "qual_name" : [ + "u4" + ] + }, + "qual_type" : { + "type_ptr" : 69 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 24 + }, + "value_kind" : <"LValue">, + "object_kind" : <"BitField"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "x", + "qual_name" : [ + "x", + "U4" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 23, + "name" : { + "name" : "x", + "qual_name" : [ + "x", + "U4" + ] + }, + "qual_type" : { + "type_ptr" : 24 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 73, + "source_range" : ( + { + "column" : 12 + }, + { + "column" : 12 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 74, + "source_range" : ( + { + "column" : 12 + }, + { + "column" : 12 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "0" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 24 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 24 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 75, + "source_range" : ( + { + "line" : 33, + "column" : 5 + }, + { + "column" : 12 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 76, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 8 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 77, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 69 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 68, + "name" : { + "name" : "u4", + "qual_name" : [ + "u4" + ] + }, + "qual_type" : { + "type_ptr" : 69 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 24 + }, + "value_kind" : <"LValue">, + "object_kind" : <"BitField"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "y", + "qual_name" : [ + "y", + "U4" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 27, + "name" : { + "name" : "y", + "qual_name" : [ + "y", + "U4" + ] + }, + "qual_type" : { + "type_ptr" : 24 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 78, + "source_range" : ( + { + "column" : 12 + }, + { + "column" : 12 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 79, + "source_range" : ( + { + "column" : 12 + }, + { + "column" : 12 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 24 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 24 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"DeclStmt" : ( + { + "pointer" : 80, + "source_range" : ( + { + "line" : 35, + "column" : 5 + }, + { + "line" : 38, + "column" : 6 + } + ) + }, + [ + ], + [ + <"RecordDecl" : ( + { + "pointer" : 81, + "parent_pointer" : 30, + "source_range" : ( + { + "line" : 35, + "column" : 5 + }, + { + "line" : 38, + "column" : 5 + } + ) + }, + { + "name" : "U5", + "qual_name" : [ + "U5", + "main" + ] + }, + 82, + [ + <"FieldDecl" : ( + { + "pointer" : 83, + "parent_pointer" : 81, + "source_range" : ( + { + "line" : 36, + "column" : 9 + }, + { + "column" : 13 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "x", + "qual_name" : [ + "x", + "U5", + "main" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"FieldDecl" : ( + { + "pointer" : 84, + "parent_pointer" : 81, + "source_range" : ( + { + "line" : 37, + "column" : 9 + }, + { + "column" : 15 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "y", + "qual_name" : [ + "y", + "U5", + "main" + ] + }, + { + "type_ptr" : 85 + }, + { + } + )> + ], + { + }, + <"TTK_Union">, + { + "definition_ptr" : 81, + "is_complete_definition" : true + } + )> + ] + )>, + <"DeclStmt" : ( + { + "pointer" : 86, + "source_range" : ( + { + "line" : 39, + "column" : 5 + }, + { + "column" : 35 + } + ) + }, + [ + <"InitListExpr" : ( + { + "pointer" : 87, + "source_range" : ( + { + "column" : 30 + }, + { + "column" : 34 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 88, + "source_range" : ( + { + "column" : 32 + }, + { + "column" : 32 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 89 + } + } + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 90, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 14 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "u51", + "qual_name" : [ + "u51" + ] + }, + { + "type_ptr" : 89 + }, + { + } + )>, + <"VarDecl" : ( + { + "pointer" : 91, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 19 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "u52", + "qual_name" : [ + "u52" + ] + }, + { + "type_ptr" : 89 + }, + { + } + )>, + <"VarDecl" : ( + { + "pointer" : 92, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 34 + } + ) + }, + { + "name" : "u53", + "qual_name" : [ + "u53" + ] + }, + { + "type_ptr" : 89 + }, + { + "init_expr" : <"InitListExpr" : ( + { + "pointer" : 87, + "source_range" : ( + { + "column" : 30 + }, + { + "column" : 34 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 88, + "source_range" : ( + { + "column" : 32 + }, + { + "column" : 32 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 89 + } + } + )> + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 93, + "source_range" : ( + { + "line" : 40, + "column" : 5 + }, + { + "column" : 13 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 94, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 9 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 95, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 89 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 90, + "name" : { + "name" : "u51", + "qual_name" : [ + "u51" + ] + }, + "qual_type" : { + "type_ptr" : 89 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "x", + "qual_name" : [ + "x", + "U5", + "main" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 83, + "name" : { + "name" : "x", + "qual_name" : [ + "x", + "U5", + "main" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 96, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "42" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 97, + "source_range" : ( + { + "line" : 41, + "column" : 5 + }, + { + "column" : 13 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 98, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 9 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 99, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 89 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 91, + "name" : { + "name" : "u52", + "qual_name" : [ + "u52" + ] + }, + "qual_type" : { + "type_ptr" : 89 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 85 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "y", + "qual_name" : [ + "y", + "U5", + "main" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 84, + "name" : { + "name" : "y", + "qual_name" : [ + "y", + "U5", + "main" + ] + }, + "qual_type" : { + "type_ptr" : 85 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 100, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + <"FloatingLiteral" : ( + { + "pointer" : 101, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 102 + } + }, + "3.1400000000000001" + )> + ], + { + "qual_type" : { + "type_ptr" : 85 + } + }, + { + "cast_kind" : <"FloatingCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 85 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"DeclStmt" : ( + { + "pointer" : 103, + "source_range" : ( + { + "line" : 43, + "column" : 5 + }, + { + "line" : 46, + "column" : 9 + } + ) + }, + [ + ], + [ + <"RecordDecl" : ( + { + "pointer" : 104, + "parent_pointer" : 30, + "source_range" : ( + { + "line" : 43, + "column" : 5 + }, + { + "line" : 46, + "column" : 5 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "anonymous_union_sample/types/union.c:43:5", + "main" + ] + }, + 105, + [ + <"FieldDecl" : ( + { + "pointer" : 106, + "parent_pointer" : 104, + "source_range" : ( + { + "line" : 44, + "column" : 9 + }, + { + "column" : 13 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "n", + "qual_name" : [ + "n", + "anonymous_union_sample/types/union.c:43:5", + "main" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"FieldDecl" : ( + { + "pointer" : 107, + "parent_pointer" : 104, + "source_range" : ( + { + "line" : 45, + "column" : 9 + }, + { + "column" : 15 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "r", + "qual_name" : [ + "r", + "anonymous_union_sample/types/union.c:43:5", + "main" + ] + }, + { + "type_ptr" : 85 + }, + { + } + )> + ], + { + }, + <"TTK_Union">, + { + "definition_ptr" : 104, + "is_complete_definition" : true + } + )>, + <"VarDecl" : ( + { + "pointer" : 108, + "source_range" : ( + { + "line" : 43, + "column" : 5 + }, + { + "line" : 46, + "column" : 7 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "u6", + "qual_name" : [ + "u6" + ] + }, + { + "type_ptr" : 109 + }, + { + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 110, + "source_range" : ( + { + "line" : 47, + "column" : 5 + }, + { + "column" : 12 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 111, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 8 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 112, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 109 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 108, + "name" : { + "name" : "u6", + "qual_name" : [ + "u6" + ] + }, + "qual_type" : { + "type_ptr" : 109 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "n", + "qual_name" : [ + "n", + "anonymous_union_sample/types/union.c:43:5", + "main" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 106, + "name" : { + "name" : "n", + "qual_name" : [ + "n", + "anonymous_union_sample/types/union.c:43:5", + "main" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 113, + "source_range" : ( + { + "column" : 12 + }, + { + "column" : 12 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "7" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 114, + "source_range" : ( + { + "line" : 48, + "column" : 5 + }, + { + "column" : 12 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 115, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 8 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 116, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 109 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 108, + "name" : { + "name" : "u6", + "qual_name" : [ + "u6" + ] + }, + "qual_type" : { + "type_ptr" : 109 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 85 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "r", + "qual_name" : [ + "r", + "anonymous_union_sample/types/union.c:43:5", + "main" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 107, + "name" : { + "name" : "r", + "qual_name" : [ + "r", + "anonymous_union_sample/types/union.c:43:5", + "main" + ] + }, + "qual_type" : { + "type_ptr" : 85 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 117, + "source_range" : ( + { + "column" : 12 + }, + { + "column" : 12 + } + ) + }, + [ + <"FloatingLiteral" : ( + { + "pointer" : 118, + "source_range" : ( + { + "column" : 12 + }, + { + "column" : 12 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 102 + } + }, + "1.4099999999999999" + )> + ], + { + "qual_type" : { + "type_ptr" : 85 + } + }, + { + "cast_kind" : <"FloatingCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 85 + } + }, + { + "kind" : <"Assign"> + } + )> + ] + )> + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 119, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "instancetype", + "qual_name" : [ + "instancetype" + ] + }, + 120, + { + } + )> + ], + { + }, + { + "input_path" : "sample/types/union.c", + "input_kind" : <"IK_C">, + "integer_type_widths" : { + "char_type" : 8, + "short_type" : 16, + "int_type" : 32, + "long_type" : 64, + "longlong_type" : 64 + }, + "types" : [ + <"BuiltinType" : ( + { + "pointer" : 121 + }, + <"Void"> + )>, + <"BuiltinType" : ( + { + "pointer" : 122 + }, + <"Bool"> + )>, + <"BuiltinType" : ( + { + "pointer" : 123 + }, + <"Char_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 124 + }, + <"SChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 125 + }, + <"Short"> + )>, + <"BuiltinType" : ( + { + "pointer" : 10 + }, + <"Int"> + )>, + <"BuiltinType" : ( + { + "pointer" : 12 + }, + <"Long"> + )>, + <"BuiltinType" : ( + { + "pointer" : 126 + }, + <"LongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 127 + }, + <"UChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 128 + }, + <"UShort"> + )>, + <"BuiltinType" : ( + { + "pointer" : 24 + }, + <"UInt"> + )>, + <"BuiltinType" : ( + { + "pointer" : 129 + }, + <"ULong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 130 + }, + <"ULongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 85 + }, + <"Float"> + )>, + <"BuiltinType" : ( + { + "pointer" : 102 + }, + <"Double"> + )>, + <"BuiltinType" : ( + { + "pointer" : 131 + }, + <"LongDouble"> + )>, + <"BuiltinType" : ( + { + "pointer" : 132 + }, + <"Float128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 133 + }, + <"Float16"> + )>, + <"BuiltinType" : ( + { + "pointer" : 134 + }, + <"ShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 135 + }, + <"Accum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 136 + }, + <"LongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 137 + }, + <"UShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 138 + }, + <"UAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 139 + }, + <"ULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 140 + }, + <"ShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 141 + }, + <"Fract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 142 + }, + <"LongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 143 + }, + <"UShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 144 + }, + <"UFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 145 + }, + <"ULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 146 + }, + <"SatShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 147 + }, + <"SatAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 148 + }, + <"SatLongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 149 + }, + <"SatUShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 150 + }, + <"SatUAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 151 + }, + <"SatULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 152 + }, + <"SatShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 153 + }, + <"SatFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 154 + }, + <"SatLongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 155 + }, + <"SatUShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 156 + }, + <"SatUFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 157 + }, + <"SatULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 158 + }, + <"Int128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 159 + }, + <"UInt128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 160 + }, + <"WChar_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 161 + }, + <"Char8"> + )>, + <"BuiltinType" : ( + { + "pointer" : 162 + }, + <"Dependent"> + )>, + <"BuiltinType" : ( + { + "pointer" : 163 + }, + <"Overload"> + )>, + <"BuiltinType" : ( + { + "pointer" : 164 + }, + <"BoundMember"> + )>, + <"BuiltinType" : ( + { + "pointer" : 165 + }, + <"PseudoObject"> + )>, + <"BuiltinType" : ( + { + "pointer" : 166 + }, + <"UnknownAny"> + )>, + <"BuiltinType" : ( + { + "pointer" : 167 + }, + <"ARCUnbridgedCast"> + )>, + <"BuiltinType" : ( + { + "pointer" : 168 + }, + <"BuiltinFn"> + )>, + <"ComplexType" : ( + { + "pointer" : 169 + } + )>, + <"ComplexType" : ( + { + "pointer" : 170 + } + )>, + <"ComplexType" : ( + { + "pointer" : 171 + } + )>, + <"ComplexType" : ( + { + "pointer" : 172 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 173 + }, + <"ObjCId"> + )>, + <"BuiltinType" : ( + { + "pointer" : 174 + }, + <"ObjCClass"> + )>, + <"BuiltinType" : ( + { + "pointer" : 175 + }, + <"ObjCSel"> + )>, + <"PointerType" : ( + { + "pointer" : 176 + }, + { + "type_ptr" : 121 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 177 + }, + <"NullPtr"> + )>, + <"BuiltinType" : ( + { + "pointer" : 178 + }, + <"Half"> + )>, + <"BuiltinType" : ( + { + "pointer" : 179 + }, + <"BFloat16"> + )>, + <"RecordType" : ( + { + "pointer" : 180 + }, + 181 + )>, + <"PointerType" : ( + { + "pointer" : 182 + }, + { + "type_ptr" : 10, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 183 + }, + { + "type_ptr" : 123, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 184 + }, + { + "type_ptr" : 123 + } + )>, + <"RecordType" : ( + { + "pointer" : 185 + }, + 186 + )>, + <"ConstantArrayType" : ( + { + "pointer" : 187 + }, + { + "element_type" : { + "type_ptr" : 185 + }, + "stride" : 24 + }, + 1 + )>, + <"RecordType" : ( + { + "pointer" : 8 + }, + 7 + )>, + <"RecordType" : ( + { + "pointer" : 14 + }, + 13 + )>, + <"ElaboratedType" : ( + { + "pointer" : 188, + "desugared_type" : 14 + } + )>, + <"RecordType" : ( + { + "pointer" : 20 + }, + 19 + )>, + <"RecordType" : ( + { + "pointer" : 22 + }, + 21 + )>, + <"FunctionProtoType" : ( + { + "pointer" : 31 + }, + { + "return_type" : { + "type_ptr" : 10 + } + }, + { + } + )>, + <"PointerType" : ( + { + "pointer" : 189 + }, + { + "type_ptr" : 184 + } + )>, + <"ElaboratedType" : ( + { + "pointer" : 35, + "desugared_type" : 8 + } + )>, + <"TypedefType" : ( + { + "pointer" : 18, + "desugared_type" : 14 + }, + { + "child_type" : { + "type_ptr" : 188 + }, + "decl_ptr" : 17 + } + )>, + <"ElaboratedType" : ( + { + "pointer" : 69, + "desugared_type" : 22 + } + )>, + <"RecordType" : ( + { + "pointer" : 82 + }, + 81 + )>, + <"ElaboratedType" : ( + { + "pointer" : 89, + "desugared_type" : 82 + } + )>, + <"RecordType" : ( + { + "pointer" : 105 + }, + 104 + )>, + <"ElaboratedType" : ( + { + "pointer" : 109, + "desugared_type" : 105 + } + )>, + <"ObjCObjectType" : ( + { + "pointer" : 190 + }, + { + "base_type" : 173 + } + )>, + <"ObjCObjectPointerType" : ( + { + "pointer" : 191 + }, + { + "type_ptr" : 190 + } + )>, + <"TypedefType" : ( + { + "pointer" : 192, + "desugared_type" : 191 + }, + { + "child_type" : { + "type_ptr" : 191 + }, + "decl_ptr" : 193 + } + )>, + <"TypedefType" : ( + { + "pointer" : 120, + "desugared_type" : 191 + }, + { + "child_type" : { + "type_ptr" : 192 + }, + "decl_ptr" : 119 + } + )>, + <"NoneType" : ( + { + "pointer" : 0 + } + )> + ] + } +)> diff --git a/src/lib/ast.ml b/src/lib/ast.ml index 658c9b4..686d02e 100644 --- a/src/lib/ast.ml +++ b/src/lib/ast.ml @@ -53,6 +53,11 @@ and record = { record_fields: field list; } +and union = { + union_name: string; + union_fields: field list; +} + and init_name_group = CType.t * init_name list and name = string @@ -72,6 +77,7 @@ and definition = | DECDEF of init_name_group * variable_scope * Location.t | TYPEDEF of CType.id * string * Location.t | RECORDDEF of CType.id * record * Location.t + | UNIONDEF of CType.id * union * Location.t and block = statement list @@ -85,6 +91,7 @@ and statement = | RETURN of expression option * Location.t | VARDECL of init_name_group * variable_scope * Location.t | RECORDDEC of CType.id * record * Location.t + | UNIONDEC of CType.id * union * Location.t and binary_operator = | ADD | SUB | MUL | DIV | MOD @@ -111,6 +118,7 @@ and expression = and constant = | CONST_INT of string (* the textual representation *) + | CONST_FLOAT of string (** ditto *) and init_expression = | NO_INIT @@ -125,15 +133,14 @@ let rec show_file indent = function (filename, definition_list) -> indent ^ "File(name: " ^ filename ^ "\n" ^ defs ^ "\n" ^ ")" -and show_record_definition id { record_name; record_fields } _location = - let show_field { field_type; field_name; bit_width_expr } = - let field_type = show_ctype field_type in - let bit_width_expr = bit_width_expr - |> Option.map (fun expr -> " (bit_width: " ^ show_expression expr ^ ")") - |> Option.value ~default:"" - in - " " ^ field_name ^ ": " ^ field_type ^ bit_width_expr +and show_field { field_type; field_name; bit_width_expr } = + let field_type = show_ctype field_type in + let bit_width_expr = bit_width_expr + |> Option.map (fun expr -> " (bit_width: " ^ show_expression expr ^ ")") + |> Option.value ~default:"" in + " " ^ field_name ^ ": " ^ field_type ^ bit_width_expr +and show_record_definition id { record_name; record_fields } _location = let fields = record_fields |> List.map show_field @@ -142,6 +149,15 @@ and show_record_definition id { record_name; record_fields } _location = "struct " ^ record_name ^ " {\n" ^ fields ^ "\n" ^ "}(User defined as " ^ string_of_int id ^ ")\n" +and show_union_definition id { union_name; union_fields } _location = +let fields = + union_fields + |> List.map show_field + |> String.concat "\n" +in +"union " ^ union_name ^ " {\n" ^ +fields ^ "\n" ^ +"}(User defined as " ^ string_of_int id ^ ")\n" and show_variable_scope {is_global; is_static; is_static_local} = let info = [] in let info = if is_static_local then "static_local" :: info else info in @@ -176,6 +192,8 @@ and show_definition indent = function "type " ^ name ^ "(" ^ string_of_int id ^ ")\n" | RECORDDEF (id, record, location) -> show_record_definition id record location + | UNIONDEF (id, union, location) -> + show_union_definition id union location and show_init_name_group indent (ctype, init_name_list) = let names = init_name_list @@ -256,6 +274,8 @@ and show_statement indent = function indent ^ ")" | RECORDDEC (id, record, location) -> show_record_definition id record location + | UNIONDEC (id, union, location) -> + show_union_definition id union location and show_expression = function | CONST_EXPR (expr, _location) -> show_expression expr @@ -312,6 +332,7 @@ and show_binary_operator = function | ASSIGN -> "=" and show_constant = function | CONST_INT i_as_str -> i_as_str + | CONST_FLOAT f_as_str -> f_as_str type file = string * definition list diff --git a/src/lib/ast.mli b/src/lib/ast.mli index d3563d3..58bf772 100644 --- a/src/lib/ast.mli +++ b/src/lib/ast.mli @@ -52,6 +52,11 @@ and record = { record_fields: field list; } +and union = { + union_name: string; + union_fields: field list; +} + (** like name_group, except the declared variables are allowed to have initializers e.g. @@ -98,6 +103,7 @@ and definition = | DECDEF of init_name_group * variable_scope * Location.t (** global variable(s) *) | TYPEDEF of CType.id * string * Location.t (** A definition of type *) | RECORDDEF of CType.id * record * Location.t (** A definition of struct *) + | UNIONDEF of CType.id * union * Location.t (** A definition of union *) and block = statement list @@ -138,6 +144,8 @@ and statement = (** variable declaration *) | RECORDDEC of CType.id * record * Location.t (** struct definition in statements *) + | UNIONDEC of CType.id * union * Location.t + (** union definition in statements *) and binary_operator = | ADD (** [e1 + e2] *) @@ -182,6 +190,7 @@ and expression = and constant = | CONST_INT of string (** the textual representation *) + | CONST_FLOAT of string (** ditto *) and init_expression = | NO_INIT diff --git a/src/lib/ast2cabs.ml b/src/lib/ast2cabs.ml index a01348b..bbb5312 100644 --- a/src/lib/ast2cabs.ml +++ b/src/lib/ast2cabs.ml @@ -19,6 +19,7 @@ let conv_location : Ast.Location.t -> Cabs.cabsloc = function let conv_constant : Ast.constant -> Cabs.constant = function | Ast.CONST_INT i -> Cabs.CONST_INT i + | Ast.CONST_FLOAT _ -> raise (Cannot_convert "Cabs does not support CONST_FLOAT constant") let conv_binary_operator : Ast.binary_operator -> Cabs.binary_operator = function | Ast.ADD -> Cabs.ADD @@ -117,6 +118,8 @@ let rec conv_statement : Ast.statement -> Cabs.statement = function )) | Ast.RECORDDEC (_id, _record, _location) -> raise (Cannot_convert "Cabs does not support the definition in statements") + | Ast.UNIONDEC (_id, _union, _location) -> + raise (Cannot_convert "Cabs does not support the definition in statements") and conv_block block : Cabs.block = { blabels= []; @@ -166,6 +169,8 @@ let conv_definition : Ast.definition -> Cabs.definition = function raise (Unimplemented_error "Cabs cannot accept this definition.") | Ast.RECORDDEF _ -> raise (Unimplemented_error "Cabs cannot accept this definition.") + | Ast.UNIONDEF _ -> + raise (Unimplemented_error "Cabs cannot accept this definition.") let conv_file (filename, definitions) : Cabs.file = filename, List.map conv_definition definitions diff --git a/src/lib/yojson2ast.ml b/src/lib/yojson2ast.ml index eae6184..c7d892b 100644 --- a/src/lib/yojson2ast.ml +++ b/src/lib/yojson2ast.ml @@ -534,6 +534,17 @@ let rec parse_expression typemap : Yojson.Safe.t -> Ast.expression = function in let location = extract_location source_info in Ast.CONSTANT (Ast.CONST_INT value, location) + | `Variant ( + "FloatingLiteral", Some (`Tuple ( + `Assoc source_info :: + _children :: + _qual_type :: + `String value :: + _ + )) + ) -> + let location = extract_location source_info in + Ast.CONSTANT (Ast.CONST_FLOAT value, location) | `Variant ( "CharacterLiteral", Some (`Tuple ( `Assoc source_info :: @@ -600,7 +611,7 @@ let rec parse_expression typemap : Yojson.Safe.t -> Ast.expression = function | yojson -> raise (Invalid_Yojson ("Invalid expression data.", yojson)) -and parse_record typemap yojson = +and parse_record_or_union typemap yojson = let parse_fields fields_yojson = List.fold_left (fun fields -> function | `Variant ( "FieldDecl", Some (`Tuple ( @@ -640,7 +651,7 @@ and parse_record typemap yojson = `Int _type_ptr :: `List fields :: _ :: (* empty? *) - _ :: (* ex. <"TTK_Struct"> *) + struct_or_union :: (* <"TTK_Struct"> or <"TTK_Union"> *) `Assoc _definition_data :: _ )) @@ -656,11 +667,19 @@ and parse_record typemap yojson = in loop qual_names in - let record_fields = parse_fields fields in + let fields = parse_fields fields in begin match ptr, name with - | (Some ptr), (Some record_name) -> - let record = Ast.{ record_name; record_fields } in - ptr, record, location + | (Some ptr), (Some name) -> + begin match struct_or_union with + | `Variant ("TTK_Struct", _) -> + let record = Ast.{ record_name= name; record_fields= fields } in + `TTK_Struct (ptr, record, location) + | `Variant ("TTK_Union", _) -> + let union = Ast.{ union_name= name; union_fields= fields } in + `TTK_Union (ptr, union, location) + | _ -> + raise (Invalid_Yojson ("Invalid record definition.", yojson)) + end | _ -> raise (Invalid_Yojson ("Invalid record definition.", yojson)) end @@ -716,8 +735,10 @@ and parse_statement typemap : Yojson.Safe.t -> Ast.statement = function ) end | `Variant ("RecordDecl", _) as yojson -> - let id, record, location = parse_record typemap yojson in - Ast.RECORDDEC (id, record, location) + begin match parse_record_or_union typemap yojson with + | `TTK_Struct (id, record, location) -> Ast.RECORDDEC (id, record, location) + | `TTK_Union (id, union, location) -> Ast.UNIONDEC (id, union, location) + end | `Variant ( "IfStmt", Some (`Tuple ( `Assoc source_info :: @@ -882,8 +903,10 @@ let ast_of_yojson typemap function_typeinfo definitions = Ast.FUNDEF (single_name, params, [], location) :: definitions end | `Variant ("RecordDecl", _) as yojson -> - let id, record, location = parse_record typemap yojson in - Ast.RECORDDEF (id, record, location) :: definitions + begin match parse_record_or_union typemap yojson with + | `TTK_Struct (id, record, location) -> Ast.RECORDDEF (id, record, location) :: definitions + | `TTK_Union (id, union, location) -> Ast.UNIONDEF (id, union, location) :: definitions + end | _ -> definitions in From dc11db9003ea542285f825a0d6f4f3cd32cd0a85 Mon Sep 17 00:00:00 2001 From: cedretaber Date: Sat, 8 Oct 2022 23:21:31 +0900 Subject: [PATCH 2/6] Add enum type. --- sample/types/enum.c | 38 + sample/types/enum.c.yojson | 2447 ++++++++++++++++++++++++++++++++++++ src/lib/ast.ml | 48 +- src/lib/ast.mli | 14 + src/lib/ast2cabs.ml | 4 + src/lib/yojson2ast.ml | 82 ++ 6 files changed, 2625 insertions(+), 8 deletions(-) create mode 100644 sample/types/enum.c create mode 100644 sample/types/enum.c.yojson diff --git a/sample/types/enum.c b/sample/types/enum.c new file mode 100644 index 0000000..da61553 --- /dev/null +++ b/sample/types/enum.c @@ -0,0 +1,38 @@ + +enum E1 { + E11, + E12 = 4, + E13 +}; + +typedef enum { + E21, + E22 +} E2; + +enum E3; + +int main(void) { + enum E1 e1 = E11; + e1 = E12; + + int x; + x = E13; + + E2 e2 = 0; + e2 = E22; + + enum E4 { + E41 = 1, + E42 + }; + enum E4 e4; + e4 = E41; + + enum { + YES, + NO + } res; + res = YES; + res = NO; +} diff --git a/sample/types/enum.c.yojson b/sample/types/enum.c.yojson new file mode 100644 index 0000000..cf2ecdc --- /dev/null +++ b/sample/types/enum.c.yojson @@ -0,0 +1,2447 @@ +<"TranslationUnitDecl" : ( + { + "pointer" : 1, + "source_range" : ( + { + }, + { + } + ) + }, + [ + <"TypedefDecl" : ( + { + "pointer" : 2, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__int128_t", + "qual_name" : [ + "__int128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 3, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__uint128_t", + "qual_name" : [ + "__uint128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 4, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__NSConstantString", + "qual_name" : [ + "__NSConstantString" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 5, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_ms_va_list", + "qual_name" : [ + "__builtin_ms_va_list" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 6, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_va_list", + "qual_name" : [ + "__builtin_va_list" + ] + }, + 0, + { + } + )>, + <"EnumDecl" : ( + { + "pointer" : 7, + "source_range" : ( + { + "file" : "sample/types/enum.c", + "line" : 2, + "column" : 1 + }, + { + "line" : 6, + "column" : 1 + } + ) + }, + { + "name" : "E1", + "qual_name" : [ + "E1" + ] + }, + 8, + [ + <"EnumConstantDecl" : ( + { + "pointer" : 9, + "source_range" : ( + { + "line" : 3, + "column" : 5 + }, + { + "column" : 5 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "E11", + "qual_name" : [ + "E11", + "E1" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"EnumConstantDecl" : ( + { + "pointer" : 11, + "source_range" : ( + { + "line" : 4, + "column" : 5 + }, + { + "column" : 11 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "E12", + "qual_name" : [ + "E12", + "E1" + ] + }, + { + "type_ptr" : 10 + }, + { + "init_expr" : <"ConstantExpr" : ( + { + "pointer" : 12, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 13, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "4" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + } + )> + } + )>, + <"EnumConstantDecl" : ( + { + "pointer" : 14, + "source_range" : ( + { + "line" : 5, + "column" : 5 + }, + { + "column" : 5 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "E13", + "qual_name" : [ + "E13", + "E1" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )> + ], + { + }, + <"TTK_Enum">, + { + } + )>, + <"EnumDecl" : ( + { + "pointer" : 15, + "source_range" : ( + { + "line" : 8, + "column" : 9 + }, + { + "line" : 11, + "column" : 1 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "E2" + ] + }, + 16, + [ + <"EnumConstantDecl" : ( + { + "pointer" : 17, + "source_range" : ( + { + "line" : 9, + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + { + "name" : "E21", + "qual_name" : [ + "E21", + "E2" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"EnumConstantDecl" : ( + { + "pointer" : 18, + "source_range" : ( + { + "line" : 10, + "column" : 5 + }, + { + "column" : 5 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "E22", + "qual_name" : [ + "E22", + "E2" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )> + ], + { + }, + <"TTK_Enum">, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 19, + "source_range" : ( + { + "line" : 8, + "column" : 1 + }, + { + "line" : 11, + "column" : 3 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "E2", + "qual_name" : [ + "E2" + ] + }, + 20, + { + } + )>, + <"EnumDecl" : ( + { + "pointer" : 21, + "source_range" : ( + { + "line" : 13, + "column" : 1 + }, + { + "column" : 6 + } + ) + }, + { + "name" : "E3", + "qual_name" : [ + "E3" + ] + }, + 22, + [ + ], + { + }, + <"TTK_Enum">, + { + } + )>, + <"FunctionDecl" : ( + { + "pointer" : 23, + "source_range" : ( + { + "line" : 15, + "column" : 1 + }, + { + "line" : 38, + "column" : 1 + } + ) + }, + { + "name" : "main", + "qual_name" : [ + "main" + ] + }, + { + "type_ptr" : 24 + }, + { + "decl_ptr_with_body" : 23, + "body" : <"CompoundStmt" : ( + { + "pointer" : 25, + "source_range" : ( + { + "line" : 15, + "column" : 16 + }, + { + "line" : 38, + "column" : 1 + } + ) + }, + [ + <"DeclStmt" : ( + { + "pointer" : 26, + "source_range" : ( + { + "line" : 16, + "column" : 5 + }, + { + "column" : 21 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 27, + "source_range" : ( + { + "column" : 18 + }, + { + "column" : 18 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 28, + "source_range" : ( + { + "column" : 18 + }, + { + "column" : 18 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 9, + "name" : { + "name" : "E11", + "qual_name" : [ + "E11", + "E1" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 29 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 30, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 18 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "e1", + "qual_name" : [ + "e1" + ] + }, + { + "type_ptr" : 29 + }, + { + "is_init_ice" : true, + "init_expr" : <"ImplicitCastExpr" : ( + { + "pointer" : 27, + "source_range" : ( + { + "column" : 18 + }, + { + "column" : 18 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 28, + "source_range" : ( + { + "column" : 18 + }, + { + "column" : 18 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 9, + "name" : { + "name" : "E11", + "qual_name" : [ + "E11", + "E1" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 29 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 31, + "source_range" : ( + { + "line" : 17, + "column" : 5 + }, + { + "column" : 10 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 32, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 29 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 30, + "name" : { + "name" : "e1", + "qual_name" : [ + "e1" + ] + }, + "qual_type" : { + "type_ptr" : 29 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 33, + "source_range" : ( + { + "column" : 10 + }, + { + "column" : 10 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 34, + "source_range" : ( + { + "column" : 10 + }, + { + "column" : 10 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 11, + "name" : { + "name" : "E12", + "qual_name" : [ + "E12", + "E1" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 29 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 29 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"DeclStmt" : ( + { + "pointer" : 35, + "source_range" : ( + { + "line" : 19, + "column" : 5 + }, + { + "column" : 10 + } + ) + }, + [ + ], + [ + <"VarDecl" : ( + { + "pointer" : 36, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 9 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 37, + "source_range" : ( + { + "line" : 20, + "column" : 5 + }, + { + "column" : 9 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 38, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 36, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )>, + <"DeclRefExpr" : ( + { + "pointer" : 39, + "source_range" : ( + { + "column" : 9 + }, + { + "column" : 9 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 14, + "name" : { + "name" : "E13", + "qual_name" : [ + "E13", + "E1" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"DeclStmt" : ( + { + "pointer" : 40, + "source_range" : ( + { + "line" : 22, + "column" : 5 + }, + { + "column" : 14 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 41, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 42, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "0" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 20 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 43, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 13 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "e2", + "qual_name" : [ + "e2" + ] + }, + { + "type_ptr" : 20 + }, + { + "is_init_ice" : true, + "init_expr" : <"ImplicitCastExpr" : ( + { + "pointer" : 41, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 42, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 13 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "0" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 20 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 44, + "source_range" : ( + { + "line" : 23, + "column" : 5 + }, + { + "column" : 10 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 45, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 20 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 43, + "name" : { + "name" : "e2", + "qual_name" : [ + "e2" + ] + }, + "qual_type" : { + "type_ptr" : 20 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 46, + "source_range" : ( + { + "column" : 10 + }, + { + "column" : 10 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 47, + "source_range" : ( + { + "column" : 10 + }, + { + "column" : 10 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 18, + "name" : { + "name" : "E22", + "qual_name" : [ + "E22", + "E2" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 20 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 20 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"DeclStmt" : ( + { + "pointer" : 48, + "source_range" : ( + { + "line" : 25, + "column" : 5 + }, + { + "line" : 28, + "column" : 6 + } + ) + }, + [ + ], + [ + <"EnumDecl" : ( + { + "pointer" : 49, + "source_range" : ( + { + "line" : 25, + "column" : 5 + }, + { + "line" : 28, + "column" : 5 + } + ) + }, + { + "name" : "E4", + "qual_name" : [ + "E4", + "main" + ] + }, + 50, + [ + <"EnumConstantDecl" : ( + { + "pointer" : 51, + "source_range" : ( + { + "line" : 26, + "column" : 9 + }, + { + "column" : 15 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "E41", + "qual_name" : [ + "E41", + "E4", + "main" + ] + }, + { + "type_ptr" : 10 + }, + { + "init_expr" : <"ConstantExpr" : ( + { + "pointer" : 52, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 53, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + } + )> + } + )>, + <"EnumConstantDecl" : ( + { + "pointer" : 54, + "source_range" : ( + { + "line" : 27, + "column" : 9 + }, + { + "column" : 9 + } + ) + }, + { + "name" : "E42", + "qual_name" : [ + "E42", + "E4", + "main" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )> + ], + { + }, + <"TTK_Enum">, + { + } + )> + ] + )>, + <"DeclStmt" : ( + { + "pointer" : 55, + "source_range" : ( + { + "line" : 29, + "column" : 5 + }, + { + "column" : 15 + } + ) + }, + [ + ], + [ + <"VarDecl" : ( + { + "pointer" : 56, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 13 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "e4", + "qual_name" : [ + "e4" + ] + }, + { + "type_ptr" : 57 + }, + { + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 58, + "source_range" : ( + { + "line" : 30, + "column" : 5 + }, + { + "column" : 10 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 59, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 57 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 56, + "name" : { + "name" : "e4", + "qual_name" : [ + "e4" + ] + }, + "qual_type" : { + "type_ptr" : 57 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 60, + "source_range" : ( + { + "column" : 10 + }, + { + "column" : 10 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 61, + "source_range" : ( + { + "column" : 10 + }, + { + "column" : 10 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 51, + "name" : { + "name" : "E41", + "qual_name" : [ + "E41", + "E4", + "main" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 57 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 57 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"DeclStmt" : ( + { + "pointer" : 62, + "source_range" : ( + { + "line" : 32, + "column" : 5 + }, + { + "line" : 35, + "column" : 10 + } + ) + }, + [ + ], + [ + <"EnumDecl" : ( + { + "pointer" : 63, + "source_range" : ( + { + "line" : 32, + "column" : 5 + }, + { + "line" : 35, + "column" : 5 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "anonymous_enum_sample/types/enum.c:32:5", + "main" + ] + }, + 64, + [ + <"EnumConstantDecl" : ( + { + "pointer" : 65, + "source_range" : ( + { + "line" : 33, + "column" : 9 + }, + { + "column" : 9 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "YES", + "qual_name" : [ + "YES", + "anonymous_enum_sample/types/enum.c:32:5", + "main" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"EnumConstantDecl" : ( + { + "pointer" : 66, + "source_range" : ( + { + "line" : 34, + "column" : 9 + }, + { + "column" : 9 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "NO", + "qual_name" : [ + "NO", + "anonymous_enum_sample/types/enum.c:32:5", + "main" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )> + ], + { + }, + <"TTK_Enum">, + { + } + )>, + <"VarDecl" : ( + { + "pointer" : 67, + "source_range" : ( + { + "line" : 32, + "column" : 5 + }, + { + "line" : 35, + "column" : 7 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "res", + "qual_name" : [ + "res" + ] + }, + { + "type_ptr" : 68 + }, + { + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 69, + "source_range" : ( + { + "line" : 36, + "column" : 5 + }, + { + "column" : 11 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 70, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 68 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 67, + "name" : { + "name" : "res", + "qual_name" : [ + "res" + ] + }, + "qual_type" : { + "type_ptr" : 68 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 71, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 72, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 65, + "name" : { + "name" : "YES", + "qual_name" : [ + "YES", + "anonymous_enum_sample/types/enum.c:32:5", + "main" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 68 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 68 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 73, + "source_range" : ( + { + "line" : 37, + "column" : 5 + }, + { + "column" : 11 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 74, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 5 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 68 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 67, + "name" : { + "name" : "res", + "qual_name" : [ + "res" + ] + }, + "qual_type" : { + "type_ptr" : 68 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 75, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 76, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 66, + "name" : { + "name" : "NO", + "qual_name" : [ + "NO", + "anonymous_enum_sample/types/enum.c:32:5", + "main" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 68 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 68 + } + }, + { + "kind" : <"Assign"> + } + )> + ] + )> + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 77, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "instancetype", + "qual_name" : [ + "instancetype" + ] + }, + 78, + { + } + )> + ], + { + }, + { + "input_path" : "sample/types/enum.c", + "input_kind" : <"IK_C">, + "integer_type_widths" : { + "char_type" : 8, + "short_type" : 16, + "int_type" : 32, + "long_type" : 64, + "longlong_type" : 64 + }, + "types" : [ + <"BuiltinType" : ( + { + "pointer" : 79 + }, + <"Void"> + )>, + <"BuiltinType" : ( + { + "pointer" : 80 + }, + <"Bool"> + )>, + <"BuiltinType" : ( + { + "pointer" : 81 + }, + <"Char_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 82 + }, + <"SChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 83 + }, + <"Short"> + )>, + <"BuiltinType" : ( + { + "pointer" : 10 + }, + <"Int"> + )>, + <"BuiltinType" : ( + { + "pointer" : 84 + }, + <"Long"> + )>, + <"BuiltinType" : ( + { + "pointer" : 85 + }, + <"LongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 86 + }, + <"UChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 87 + }, + <"UShort"> + )>, + <"BuiltinType" : ( + { + "pointer" : 88 + }, + <"UInt"> + )>, + <"BuiltinType" : ( + { + "pointer" : 89 + }, + <"ULong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 90 + }, + <"ULongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 91 + }, + <"Float"> + )>, + <"BuiltinType" : ( + { + "pointer" : 92 + }, + <"Double"> + )>, + <"BuiltinType" : ( + { + "pointer" : 93 + }, + <"LongDouble"> + )>, + <"BuiltinType" : ( + { + "pointer" : 94 + }, + <"Float128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 95 + }, + <"Float16"> + )>, + <"BuiltinType" : ( + { + "pointer" : 96 + }, + <"ShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 97 + }, + <"Accum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 98 + }, + <"LongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 99 + }, + <"UShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 100 + }, + <"UAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 101 + }, + <"ULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 102 + }, + <"ShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 103 + }, + <"Fract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 104 + }, + <"LongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 105 + }, + <"UShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 106 + }, + <"UFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 107 + }, + <"ULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 108 + }, + <"SatShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 109 + }, + <"SatAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 110 + }, + <"SatLongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 111 + }, + <"SatUShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 112 + }, + <"SatUAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 113 + }, + <"SatULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 114 + }, + <"SatShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 115 + }, + <"SatFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 116 + }, + <"SatLongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 117 + }, + <"SatUShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 118 + }, + <"SatUFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 119 + }, + <"SatULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 120 + }, + <"Int128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 121 + }, + <"UInt128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 122 + }, + <"WChar_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 123 + }, + <"Char8"> + )>, + <"BuiltinType" : ( + { + "pointer" : 124 + }, + <"Dependent"> + )>, + <"BuiltinType" : ( + { + "pointer" : 125 + }, + <"Overload"> + )>, + <"BuiltinType" : ( + { + "pointer" : 126 + }, + <"BoundMember"> + )>, + <"BuiltinType" : ( + { + "pointer" : 127 + }, + <"PseudoObject"> + )>, + <"BuiltinType" : ( + { + "pointer" : 128 + }, + <"UnknownAny"> + )>, + <"BuiltinType" : ( + { + "pointer" : 129 + }, + <"ARCUnbridgedCast"> + )>, + <"BuiltinType" : ( + { + "pointer" : 130 + }, + <"BuiltinFn"> + )>, + <"ComplexType" : ( + { + "pointer" : 131 + } + )>, + <"ComplexType" : ( + { + "pointer" : 132 + } + )>, + <"ComplexType" : ( + { + "pointer" : 133 + } + )>, + <"ComplexType" : ( + { + "pointer" : 134 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 135 + }, + <"ObjCId"> + )>, + <"BuiltinType" : ( + { + "pointer" : 136 + }, + <"ObjCClass"> + )>, + <"BuiltinType" : ( + { + "pointer" : 137 + }, + <"ObjCSel"> + )>, + <"PointerType" : ( + { + "pointer" : 138 + }, + { + "type_ptr" : 79 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 139 + }, + <"NullPtr"> + )>, + <"BuiltinType" : ( + { + "pointer" : 140 + }, + <"Half"> + )>, + <"BuiltinType" : ( + { + "pointer" : 141 + }, + <"BFloat16"> + )>, + <"RecordType" : ( + { + "pointer" : 142 + }, + 143 + )>, + <"PointerType" : ( + { + "pointer" : 144 + }, + { + "type_ptr" : 10, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 145 + }, + { + "type_ptr" : 81, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 146 + }, + { + "type_ptr" : 81 + } + )>, + <"RecordType" : ( + { + "pointer" : 147 + }, + 148 + )>, + <"ConstantArrayType" : ( + { + "pointer" : 149 + }, + { + "element_type" : { + "type_ptr" : 147 + }, + "stride" : 24 + }, + 1 + )>, + <"EnumType" : ( + { + "pointer" : 8 + }, + 7 + )>, + <"EnumType" : ( + { + "pointer" : 16 + }, + 15 + )>, + <"ElaboratedType" : ( + { + "pointer" : 150, + "desugared_type" : 16 + } + )>, + <"EnumType" : ( + { + "pointer" : 22 + }, + 21 + )>, + <"FunctionProtoType" : ( + { + "pointer" : 24 + }, + { + "return_type" : { + "type_ptr" : 10 + } + }, + { + } + )>, + <"PointerType" : ( + { + "pointer" : 151 + }, + { + "type_ptr" : 146 + } + )>, + <"ElaboratedType" : ( + { + "pointer" : 29, + "desugared_type" : 8 + } + )>, + <"TypedefType" : ( + { + "pointer" : 20, + "desugared_type" : 16 + }, + { + "child_type" : { + "type_ptr" : 150 + }, + "decl_ptr" : 19 + } + )>, + <"EnumType" : ( + { + "pointer" : 50 + }, + 49 + )>, + <"ElaboratedType" : ( + { + "pointer" : 57, + "desugared_type" : 50 + } + )>, + <"EnumType" : ( + { + "pointer" : 64 + }, + 63 + )>, + <"ElaboratedType" : ( + { + "pointer" : 68, + "desugared_type" : 64 + } + )>, + <"ObjCObjectType" : ( + { + "pointer" : 152 + }, + { + "base_type" : 135 + } + )>, + <"ObjCObjectPointerType" : ( + { + "pointer" : 153 + }, + { + "type_ptr" : 152 + } + )>, + <"TypedefType" : ( + { + "pointer" : 154, + "desugared_type" : 153 + }, + { + "child_type" : { + "type_ptr" : 153 + }, + "decl_ptr" : 155 + } + )>, + <"TypedefType" : ( + { + "pointer" : 78, + "desugared_type" : 153 + }, + { + "child_type" : { + "type_ptr" : 154 + }, + "decl_ptr" : 77 + } + )>, + <"NoneType" : ( + { + "pointer" : 0 + } + )> + ] + } +)> diff --git a/src/lib/ast.ml b/src/lib/ast.ml index 686d02e..49b2de1 100644 --- a/src/lib/ast.ml +++ b/src/lib/ast.ml @@ -58,6 +58,17 @@ and union = { union_fields: field list; } +and enumerator = { + enumerator_type: CType.t; + enumerator_name: string; + init_expr: expression option; +} + +and enum = { + enum_name: string; + enumerators: enumerator list; +} + and init_name_group = CType.t * init_name list and name = string @@ -78,6 +89,7 @@ and definition = | TYPEDEF of CType.id * string * Location.t | RECORDDEF of CType.id * record * Location.t | UNIONDEF of CType.id * union * Location.t + | ENUMDEF of CType.id * enum * Location.t and block = statement list @@ -92,6 +104,7 @@ and statement = | VARDECL of init_name_group * variable_scope * Location.t | RECORDDEC of CType.id * record * Location.t | UNIONDEC of CType.id * union * Location.t + | ENUMDEC of CType.id * enum * Location.t and binary_operator = | ADD | SUB | MUL | DIV | MOD @@ -150,14 +163,29 @@ and show_record_definition id { record_name; record_fields } _location = fields ^ "\n" ^ "}(User defined as " ^ string_of_int id ^ ")\n" and show_union_definition id { union_name; union_fields } _location = -let fields = - union_fields - |> List.map show_field - |> String.concat "\n" -in -"union " ^ union_name ^ " {\n" ^ -fields ^ "\n" ^ -"}(User defined as " ^ string_of_int id ^ ")\n" + let fields = + union_fields + |> List.map show_field + |> String.concat "\n" + in + "union " ^ union_name ^ " {\n" ^ + fields ^ "\n" ^ + "}(User defined as " ^ string_of_int id ^ ")\n" +and show_enum_definition id { enum_name; enumerators } _location = + let show_enumerators { enumerator_type; enumerator_name; init_expr } = + let name = enumerator_name ^ ": " ^ show_ctype enumerator_type in + match init_expr with + | Some expr -> name ^ " = " ^ show_expression expr + | None -> name + in + let enumerators = + enumerators + |> List.map show_enumerators + |> String.concat "\n" + in + "enum " ^ enum_name ^ " {\n" ^ + enumerators ^ "\n" ^ + "}(User defined as " ^ string_of_int id ^ ")\n" and show_variable_scope {is_global; is_static; is_static_local} = let info = [] in let info = if is_static_local then "static_local" :: info else info in @@ -194,6 +222,8 @@ and show_definition indent = function show_record_definition id record location | UNIONDEF (id, union, location) -> show_union_definition id union location + | ENUMDEF (id, enum, location) -> + show_enum_definition id enum location and show_init_name_group indent (ctype, init_name_list) = let names = init_name_list @@ -276,6 +306,8 @@ and show_statement indent = function show_record_definition id record location | UNIONDEC (id, union, location) -> show_union_definition id union location + | ENUMDEC (id, enum, location) -> + show_enum_definition id enum location and show_expression = function | CONST_EXPR (expr, _location) -> show_expression expr diff --git a/src/lib/ast.mli b/src/lib/ast.mli index 58bf772..fbf7c4c 100644 --- a/src/lib/ast.mli +++ b/src/lib/ast.mli @@ -57,6 +57,17 @@ and union = { union_fields: field list; } +and enumerator = { + enumerator_type: CType.t; + enumerator_name: string; + init_expr: expression option; +} + +and enum = { + enum_name: string; + enumerators: enumerator list; +} + (** like name_group, except the declared variables are allowed to have initializers e.g. @@ -104,6 +115,7 @@ and definition = | TYPEDEF of CType.id * string * Location.t (** A definition of type *) | RECORDDEF of CType.id * record * Location.t (** A definition of struct *) | UNIONDEF of CType.id * union * Location.t (** A definition of union *) + | ENUMDEF of CType.id * enum * Location.t (** A definition of enum *) and block = statement list @@ -146,6 +158,8 @@ and statement = (** struct definition in statements *) | UNIONDEC of CType.id * union * Location.t (** union definition in statements *) + | ENUMDEC of CType.id * enum * Location.t + (** enum definition in statements *) and binary_operator = | ADD (** [e1 + e2] *) diff --git a/src/lib/ast2cabs.ml b/src/lib/ast2cabs.ml index bbb5312..ee343e2 100644 --- a/src/lib/ast2cabs.ml +++ b/src/lib/ast2cabs.ml @@ -120,6 +120,8 @@ let rec conv_statement : Ast.statement -> Cabs.statement = function raise (Cannot_convert "Cabs does not support the definition in statements") | Ast.UNIONDEC (_id, _union, _location) -> raise (Cannot_convert "Cabs does not support the definition in statements") + | Ast.ENUMDEC (_id, _enum, _location) -> + raise (Cannot_convert "Cabs does not support the definition in statements") and conv_block block : Cabs.block = { blabels= []; @@ -171,6 +173,8 @@ let conv_definition : Ast.definition -> Cabs.definition = function raise (Unimplemented_error "Cabs cannot accept this definition.") | Ast.UNIONDEF _ -> raise (Unimplemented_error "Cabs cannot accept this definition.") + | Ast.ENUMDEF _ -> + raise (Unimplemented_error "Cabs cannot accept this definition.") let conv_file (filename, definitions) : Cabs.file = filename, List.map conv_definition definitions diff --git a/src/lib/yojson2ast.ml b/src/lib/yojson2ast.ml index c7d892b..a0a855f 100644 --- a/src/lib/yojson2ast.ml +++ b/src/lib/yojson2ast.ml @@ -168,6 +168,17 @@ let make_typemap typemap typedata = List.fold_left (fun map -> function | Some i -> PointerMap.add i (Just (Ast.CType.Tdefined ptr)) map | _ -> map end + | `Variant ( + "EnumType", Some (`Tuple ( + `Assoc pointer_data :: + `Int ptr :: + _ + )) + ) -> + begin match extract_pointer pointer_data with + | Some i -> PointerMap.add i (Just (Ast.CType.Tdefined ptr)) map + | _ -> map + end | `Variant ( "ElaboratedType", Some (`Tuple ( `Assoc pointer_data :: @@ -685,6 +696,71 @@ and parse_record_or_union typemap yojson = end | _ -> raise (Invalid_Yojson ("Invalid record definition.", yojson)) +and parse_enum typemap yojson = + let parse_enumerators enumerators_yojson = List.fold_left (fun enumerators -> function + | `Variant ( + "EnumConstantDecl", Some (`Tuple( + `Assoc _metadata :: + `Assoc namedata :: + `Assoc typedata :: + `Assoc init_expr :: + _ + )) + ) -> + let ctype = typedata + |> extract_type_ptr + |> Option.flat_map (fun ptr -> PointerMap.find_opt ptr typemap) + in + let name = extract_name namedata in + begin match ctype, name with + | (Some enumerator_type), (Some enumerator_name) -> + let init_expr = init_expr + |> List.assoc_opt "init_expr" + |> Option.map (parse_expression typemap) + in + Ast.{ enumerator_type; enumerator_name; init_expr } :: enumerators + | _ -> + enumerators + end + | _ -> + enumerators + ) + [] + enumerators_yojson + in + match yojson with + | `Variant ( + "EnumDecl", Some (`Tuple ( + `Assoc metadata :: + `Assoc namedata :: + _ :: + `List enumerators :: + _ :: (* empty? *) + _ :: (* TTK_Enum *) + _ :: (* empty? *) + _ + )) + ) -> + let ptr = extract_pointer metadata in + let location = extract_location metadata in + let qual_names = extract_qual_names namedata in + let name = + let rec loop = function + | name :: [] -> Some name + | name :: tail -> Option.map (fun name' -> name' ^ "." ^ name) @@ loop tail + | [] -> None + in + loop qual_names + in + let enumerators = parse_enumerators enumerators in + begin match ptr, name with + | (Some ptr), (Some enum_name) -> + let enum = Ast.{ enum_name; enumerators } in + ptr, enum, location + | _ -> raise (Invalid_Yojson ("Invalid record definition.", yojson)) + end + | _ -> raise (Invalid_Yojson ("Invalid record definition.", yojson)) + and parse_statement typemap : Yojson.Safe.t -> Ast.statement = function | `Variant ( "DeclStmt", Some (`Tuple ( @@ -739,6 +815,9 @@ and parse_statement typemap : Yojson.Safe.t -> Ast.statement = function | `TTK_Struct (id, record, location) -> Ast.RECORDDEC (id, record, location) | `TTK_Union (id, union, location) -> Ast.UNIONDEC (id, union, location) end + | `Variant ("EnumDecl", _) as yojson -> + let id, enum, location = parse_enum typemap yojson in + Ast.ENUMDEC (id, enum, location) | `Variant ( "IfStmt", Some (`Tuple ( `Assoc source_info :: @@ -907,6 +986,9 @@ let ast_of_yojson typemap function_typeinfo definitions = | `TTK_Struct (id, record, location) -> Ast.RECORDDEF (id, record, location) :: definitions | `TTK_Union (id, union, location) -> Ast.UNIONDEF (id, union, location) :: definitions end + | `Variant ("EnumDecl", _) as yojson -> + let id, enum, location = parse_enum typemap yojson in + Ast.ENUMDEF (id, enum, location) :: definitions | _ -> definitions in From f88eac577602b0c7369610f8a176dc4985d65af0 Mon Sep 17 00:00:00 2001 From: cedretaber Date: Sun, 9 Oct 2022 00:12:12 +0900 Subject: [PATCH 3/6] Support string literal. --- sample/primitives/string.c | 5 + sample/primitives/string.c.yojson | 944 ++++++++++++++++++++++++++++++ src/lib/ast.ml | 8 +- src/lib/ast.mli | 4 +- src/lib/ast2cabs.ml | 2 +- src/lib/yojson2ast.ml | 14 +- 6 files changed, 971 insertions(+), 6 deletions(-) create mode 100644 sample/primitives/string.c create mode 100644 sample/primitives/string.c.yojson diff --git a/sample/primitives/string.c b/sample/primitives/string.c new file mode 100644 index 0000000..7f5f01a --- /dev/null +++ b/sample/primitives/string.c @@ -0,0 +1,5 @@ + +int main(void) { + char hello[] = "Hello, world!"; + char a = 'a'; +} diff --git a/sample/primitives/string.c.yojson b/sample/primitives/string.c.yojson new file mode 100644 index 0000000..2af9a24 --- /dev/null +++ b/sample/primitives/string.c.yojson @@ -0,0 +1,944 @@ +<"TranslationUnitDecl" : ( + { + "pointer" : 1, + "source_range" : ( + { + }, + { + } + ) + }, + [ + <"TypedefDecl" : ( + { + "pointer" : 2, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__int128_t", + "qual_name" : [ + "__int128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 3, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__uint128_t", + "qual_name" : [ + "__uint128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 4, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__NSConstantString", + "qual_name" : [ + "__NSConstantString" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 5, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_ms_va_list", + "qual_name" : [ + "__builtin_ms_va_list" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 6, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_va_list", + "qual_name" : [ + "__builtin_va_list" + ] + }, + 0, + { + } + )>, + <"FunctionDecl" : ( + { + "pointer" : 7, + "source_range" : ( + { + "file" : "sample/primitives/string.c", + "line" : 2, + "column" : 1 + }, + { + "line" : 5, + "column" : 1 + } + ) + }, + { + "name" : "main", + "qual_name" : [ + "main" + ] + }, + { + "type_ptr" : 8 + }, + { + "decl_ptr_with_body" : 7, + "body" : <"CompoundStmt" : ( + { + "pointer" : 9, + "source_range" : ( + { + "line" : 2, + "column" : 16 + }, + { + "line" : 5, + "column" : 1 + } + ) + }, + [ + <"DeclStmt" : ( + { + "pointer" : 10, + "source_range" : ( + { + "line" : 3, + "column" : 5 + }, + { + "column" : 35 + } + ) + }, + [ + <"StringLiteral" : ( + { + "pointer" : 11, + "source_range" : ( + { + "column" : 20 + }, + { + "column" : 20 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + [ + "Hello, world!" + ] + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 13, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 20 + } + ) + }, + { + "name" : "hello", + "qual_name" : [ + "hello" + ] + }, + { + "type_ptr" : 12 + }, + { + "init_expr" : <"StringLiteral" : ( + { + "pointer" : 11, + "source_range" : ( + { + "column" : 20 + }, + { + "column" : 20 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + [ + "Hello, world!" + ] + )> + } + )> + ] + )>, + <"DeclStmt" : ( + { + "pointer" : 14, + "source_range" : ( + { + "line" : 4, + "column" : 5 + }, + { + "column" : 17 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 15, + "source_range" : ( + { + "column" : 14 + }, + { + "column" : 14 + } + ) + }, + [ + <"CharacterLiteral" : ( + { + "pointer" : 16, + "source_range" : ( + { + "column" : 14 + }, + { + "column" : 14 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 17 + } + }, + 97 + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 19, + "source_range" : ( + { + "column" : 5 + }, + { + "column" : 14 + } + ) + }, + { + "name" : "a", + "qual_name" : [ + "a" + ] + }, + { + "type_ptr" : 18 + }, + { + "is_init_ice" : true, + "init_expr" : <"ImplicitCastExpr" : ( + { + "pointer" : 15, + "source_range" : ( + { + "column" : 14 + }, + { + "column" : 14 + } + ) + }, + [ + <"CharacterLiteral" : ( + { + "pointer" : 16, + "source_range" : ( + { + "column" : 14 + }, + { + "column" : 14 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 17 + } + }, + 97 + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + } + )> + ] + )> + ] + )> + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 20, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "instancetype", + "qual_name" : [ + "instancetype" + ] + }, + 21, + { + } + )> + ], + { + }, + { + "input_path" : "sample/primitives/string.c", + "input_kind" : <"IK_C">, + "integer_type_widths" : { + "char_type" : 8, + "short_type" : 16, + "int_type" : 32, + "long_type" : 64, + "longlong_type" : 64 + }, + "types" : [ + <"BuiltinType" : ( + { + "pointer" : 22 + }, + <"Void"> + )>, + <"BuiltinType" : ( + { + "pointer" : 23 + }, + <"Bool"> + )>, + <"BuiltinType" : ( + { + "pointer" : 18 + }, + <"Char_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 24 + }, + <"SChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 25 + }, + <"Short"> + )>, + <"BuiltinType" : ( + { + "pointer" : 17 + }, + <"Int"> + )>, + <"BuiltinType" : ( + { + "pointer" : 26 + }, + <"Long"> + )>, + <"BuiltinType" : ( + { + "pointer" : 27 + }, + <"LongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 28 + }, + <"UChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 29 + }, + <"UShort"> + )>, + <"BuiltinType" : ( + { + "pointer" : 30 + }, + <"UInt"> + )>, + <"BuiltinType" : ( + { + "pointer" : 31 + }, + <"ULong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 32 + }, + <"ULongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 33 + }, + <"Float"> + )>, + <"BuiltinType" : ( + { + "pointer" : 34 + }, + <"Double"> + )>, + <"BuiltinType" : ( + { + "pointer" : 35 + }, + <"LongDouble"> + )>, + <"BuiltinType" : ( + { + "pointer" : 36 + }, + <"Float128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 37 + }, + <"Float16"> + )>, + <"BuiltinType" : ( + { + "pointer" : 38 + }, + <"ShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 39 + }, + <"Accum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 40 + }, + <"LongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 41 + }, + <"UShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 42 + }, + <"UAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 43 + }, + <"ULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 44 + }, + <"ShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 45 + }, + <"Fract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 46 + }, + <"LongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 47 + }, + <"UShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 48 + }, + <"UFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 49 + }, + <"ULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 50 + }, + <"SatShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 51 + }, + <"SatAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 52 + }, + <"SatLongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 53 + }, + <"SatUShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 54 + }, + <"SatUAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 55 + }, + <"SatULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 56 + }, + <"SatShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 57 + }, + <"SatFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 58 + }, + <"SatLongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 59 + }, + <"SatUShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 60 + }, + <"SatUFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 61 + }, + <"SatULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 62 + }, + <"Int128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 63 + }, + <"UInt128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 64 + }, + <"WChar_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 65 + }, + <"Char8"> + )>, + <"BuiltinType" : ( + { + "pointer" : 66 + }, + <"Dependent"> + )>, + <"BuiltinType" : ( + { + "pointer" : 67 + }, + <"Overload"> + )>, + <"BuiltinType" : ( + { + "pointer" : 68 + }, + <"BoundMember"> + )>, + <"BuiltinType" : ( + { + "pointer" : 69 + }, + <"PseudoObject"> + )>, + <"BuiltinType" : ( + { + "pointer" : 70 + }, + <"UnknownAny"> + )>, + <"BuiltinType" : ( + { + "pointer" : 71 + }, + <"ARCUnbridgedCast"> + )>, + <"BuiltinType" : ( + { + "pointer" : 72 + }, + <"BuiltinFn"> + )>, + <"ComplexType" : ( + { + "pointer" : 73 + } + )>, + <"ComplexType" : ( + { + "pointer" : 74 + } + )>, + <"ComplexType" : ( + { + "pointer" : 75 + } + )>, + <"ComplexType" : ( + { + "pointer" : 76 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 77 + }, + <"ObjCId"> + )>, + <"BuiltinType" : ( + { + "pointer" : 78 + }, + <"ObjCClass"> + )>, + <"BuiltinType" : ( + { + "pointer" : 79 + }, + <"ObjCSel"> + )>, + <"PointerType" : ( + { + "pointer" : 80 + }, + { + "type_ptr" : 22 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 81 + }, + <"NullPtr"> + )>, + <"BuiltinType" : ( + { + "pointer" : 82 + }, + <"Half"> + )>, + <"BuiltinType" : ( + { + "pointer" : 83 + }, + <"BFloat16"> + )>, + <"RecordType" : ( + { + "pointer" : 84 + }, + 85 + )>, + <"PointerType" : ( + { + "pointer" : 86 + }, + { + "type_ptr" : 17, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 87 + }, + { + "type_ptr" : 18, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 88 + }, + { + "type_ptr" : 18 + } + )>, + <"RecordType" : ( + { + "pointer" : 89 + }, + 90 + )>, + <"ConstantArrayType" : ( + { + "pointer" : 91 + }, + { + "element_type" : { + "type_ptr" : 89 + }, + "stride" : 24 + }, + 1 + )>, + <"FunctionProtoType" : ( + { + "pointer" : 8 + }, + { + "return_type" : { + "type_ptr" : 17 + } + }, + { + } + )>, + <"PointerType" : ( + { + "pointer" : 92 + }, + { + "type_ptr" : 88 + } + )>, + <"IncompleteArrayType" : ( + { + "pointer" : 93 + }, + { + "element_type" : { + "type_ptr" : 18 + }, + "stride" : 1 + } + )>, + <"ConstantArrayType" : ( + { + "pointer" : 12 + }, + { + "element_type" : { + "type_ptr" : 18 + }, + "stride" : 1 + }, + 14 + )>, + <"ObjCObjectType" : ( + { + "pointer" : 94 + }, + { + "base_type" : 77 + } + )>, + <"ObjCObjectPointerType" : ( + { + "pointer" : 95 + }, + { + "type_ptr" : 94 + } + )>, + <"TypedefType" : ( + { + "pointer" : 96, + "desugared_type" : 95 + }, + { + "child_type" : { + "type_ptr" : 95 + }, + "decl_ptr" : 97 + } + )>, + <"TypedefType" : ( + { + "pointer" : 21, + "desugared_type" : 95 + }, + { + "child_type" : { + "type_ptr" : 96 + }, + "decl_ptr" : 20 + } + )>, + <"NoneType" : ( + { + "pointer" : 0 + } + )> + ] + } +)> diff --git a/src/lib/ast.ml b/src/lib/ast.ml index 49b2de1..e9b95b6 100644 --- a/src/lib/ast.ml +++ b/src/lib/ast.ml @@ -130,8 +130,10 @@ and expression = | INIT_LIST of expression list * Location.t and constant = - | CONST_INT of string (* the textual representation *) - | CONST_FLOAT of string (** ditto *) + | CONST_CHAR of string + | CONST_INT of string + | CONST_FLOAT of string + | CONST_STRING of string and init_expression = | NO_INIT @@ -363,8 +365,10 @@ and show_binary_operator = function | GE -> ">=" | ASSIGN -> "=" and show_constant = function + | CONST_CHAR i_as_str -> i_as_str | CONST_INT i_as_str -> i_as_str | CONST_FLOAT f_as_str -> f_as_str + | CONST_STRING str -> str type file = string * definition list diff --git a/src/lib/ast.mli b/src/lib/ast.mli index fbf7c4c..0007161 100644 --- a/src/lib/ast.mli +++ b/src/lib/ast.mli @@ -203,8 +203,10 @@ and expression = | INIT_LIST of expression list * Location.t (** initializer list [struct foo = { 1, { 2, 3 } }] *) and constant = - | CONST_INT of string (** the textual representation *) + | CONST_CHAR of string (** the textual representation *) + | CONST_INT of string (** ditto *) | CONST_FLOAT of string (** ditto *) + | CONST_STRING of string (** ditto *) and init_expression = | NO_INIT diff --git a/src/lib/ast2cabs.ml b/src/lib/ast2cabs.ml index ee343e2..cf720a1 100644 --- a/src/lib/ast2cabs.ml +++ b/src/lib/ast2cabs.ml @@ -19,7 +19,7 @@ let conv_location : Ast.Location.t -> Cabs.cabsloc = function let conv_constant : Ast.constant -> Cabs.constant = function | Ast.CONST_INT i -> Cabs.CONST_INT i - | Ast.CONST_FLOAT _ -> raise (Cannot_convert "Cabs does not support CONST_FLOAT constant") + | _ -> raise (Cannot_convert "Cabs does not support except Int.") let conv_binary_operator : Ast.binary_operator -> Cabs.binary_operator = function | Ast.ADD -> Cabs.ADD diff --git a/src/lib/yojson2ast.ml b/src/lib/yojson2ast.ml index a0a855f..2c07d81 100644 --- a/src/lib/yojson2ast.ml +++ b/src/lib/yojson2ast.ml @@ -566,8 +566,18 @@ let rec parse_expression typemap : Yojson.Safe.t -> Ast.expression = function )) ) -> let location = extract_location source_info in - (* Currently characters are represented as const int. *) - Ast.CONSTANT (Ast.CONST_INT (string_of_int value), location) + Ast.CONSTANT (Ast.CONST_CHAR (string_of_int value), location) + | `Variant ( + "StringLiteral", Some (`Tuple ( + `Assoc source_info :: + _children :: + _qual_type :: + `List [`String value] :: + _ + )) + ) -> + let location = extract_location source_info in + Ast.CONSTANT (Ast.CONST_STRING value, location) | `Variant ( "ArraySubscriptExpr", Some (`Tuple ( `Assoc source_info :: From 39e17613abeb5c7436f9a73ace6b8e73be6de678 Mon Sep 17 00:00:00 2001 From: cedretaber Date: Sun, 9 Oct 2022 00:27:07 +0900 Subject: [PATCH 4/6] Add sample of discriminated union. --- sample/types/discriminated_union.c | 30 + sample/types/discriminated_union.c.yojson | 2599 +++++++++++++++++++++ 2 files changed, 2629 insertions(+) create mode 100644 sample/types/discriminated_union.c create mode 100644 sample/types/discriminated_union.c.yojson diff --git a/sample/types/discriminated_union.c b/sample/types/discriminated_union.c new file mode 100644 index 0000000..8812887 --- /dev/null +++ b/sample/types/discriminated_union.c @@ -0,0 +1,30 @@ + +typedef enum { + INT, + THREE, + STRING +} Tag; + +typedef struct { + int a, b, c; +} Three; + +typedef struct { + Tag tag; + union { + int num; + Three *three; + char *str; + } value; +} Value; + +int main(void) { + Value x = { INT, { 0 } }; + + x.tag = THREE; + Three t = { 1, 2, 3 }; + x.value.three = &t; + + x.tag = STRING; + x.value.str = "hogehoge"; +} diff --git a/sample/types/discriminated_union.c.yojson b/sample/types/discriminated_union.c.yojson new file mode 100644 index 0000000..27fa8b0 --- /dev/null +++ b/sample/types/discriminated_union.c.yojson @@ -0,0 +1,2599 @@ +<"TranslationUnitDecl" : ( + { + "pointer" : 1, + "source_range" : ( + { + }, + { + } + ) + }, + [ + <"TypedefDecl" : ( + { + "pointer" : 2, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__int128_t", + "qual_name" : [ + "__int128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 3, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__uint128_t", + "qual_name" : [ + "__uint128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 4, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__NSConstantString", + "qual_name" : [ + "__NSConstantString" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 5, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_ms_va_list", + "qual_name" : [ + "__builtin_ms_va_list" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 6, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_va_list", + "qual_name" : [ + "__builtin_va_list" + ] + }, + 0, + { + } + )>, + <"EnumDecl" : ( + { + "pointer" : 7, + "source_range" : ( + { + "file" : "sample/types/discriminated_union.c", + "line" : 2, + "column" : 9 + }, + { + "line" : 6, + "column" : 1 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "Tag" + ] + }, + 8, + [ + <"EnumConstantDecl" : ( + { + "pointer" : 9, + "source_range" : ( + { + "line" : 3, + "column" : 3 + }, + { + "column" : 3 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "INT", + "qual_name" : [ + "INT", + "Tag" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"EnumConstantDecl" : ( + { + "pointer" : 11, + "source_range" : ( + { + "line" : 4, + "column" : 3 + }, + { + "column" : 3 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "THREE", + "qual_name" : [ + "THREE", + "Tag" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"EnumConstantDecl" : ( + { + "pointer" : 12, + "source_range" : ( + { + "line" : 5, + "column" : 3 + }, + { + "column" : 3 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "STRING", + "qual_name" : [ + "STRING", + "Tag" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )> + ], + { + }, + <"TTK_Enum">, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 13, + "source_range" : ( + { + "line" : 2, + "column" : 1 + }, + { + "line" : 6, + "column" : 3 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "Tag", + "qual_name" : [ + "Tag" + ] + }, + 14, + { + } + )>, + <"RecordDecl" : ( + { + "pointer" : 15, + "parent_pointer" : 1, + "source_range" : ( + { + "line" : 8, + "column" : 9 + }, + { + "line" : 10, + "column" : 1 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "Three" + ] + }, + 16, + [ + <"FieldDecl" : ( + { + "pointer" : 17, + "parent_pointer" : 15, + "source_range" : ( + { + "line" : 9, + "column" : 3 + }, + { + "column" : 7 + } + ), + "access" : <"Public"> + }, + { + "name" : "a", + "qual_name" : [ + "a", + "Three" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"FieldDecl" : ( + { + "pointer" : 18, + "parent_pointer" : 15, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 10 + } + ), + "access" : <"Public"> + }, + { + "name" : "b", + "qual_name" : [ + "b", + "Three" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"FieldDecl" : ( + { + "pointer" : 19, + "parent_pointer" : 15, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 13 + } + ), + "access" : <"Public"> + }, + { + "name" : "c", + "qual_name" : [ + "c", + "Three" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )> + ], + { + }, + <"TTK_Struct">, + { + "definition_ptr" : 15, + "is_complete_definition" : true + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 20, + "source_range" : ( + { + "line" : 8, + "column" : 1 + }, + { + "line" : 10, + "column" : 3 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "Three", + "qual_name" : [ + "Three" + ] + }, + 21, + { + } + )>, + <"RecordDecl" : ( + { + "pointer" : 22, + "parent_pointer" : 1, + "source_range" : ( + { + "line" : 12, + "column" : 9 + }, + { + "line" : 19, + "column" : 1 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "Value" + ] + }, + 23, + [ + <"FieldDecl" : ( + { + "pointer" : 24, + "parent_pointer" : 22, + "source_range" : ( + { + "line" : 13, + "column" : 3 + }, + { + "column" : 7 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + { + "type_ptr" : 14 + }, + { + } + )>, + <"RecordDecl" : ( + { + "pointer" : 25, + "parent_pointer" : 22, + "source_range" : ( + { + "line" : 14, + "column" : 3 + }, + { + "line" : 18, + "column" : 3 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + 26, + [ + <"FieldDecl" : ( + { + "pointer" : 27, + "parent_pointer" : 25, + "source_range" : ( + { + "line" : 15, + "column" : 5 + }, + { + "column" : 9 + } + ), + "access" : <"Public"> + }, + { + "name" : "num", + "qual_name" : [ + "num", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"FieldDecl" : ( + { + "pointer" : 28, + "parent_pointer" : 25, + "source_range" : ( + { + "line" : 16, + "column" : 5 + }, + { + "column" : 12 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "three", + "qual_name" : [ + "three", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + { + "type_ptr" : 29 + }, + { + } + )>, + <"FieldDecl" : ( + { + "pointer" : 30, + "parent_pointer" : 25, + "source_range" : ( + { + "line" : 17, + "column" : 5 + }, + { + "column" : 11 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "str", + "qual_name" : [ + "str", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + { + "type_ptr" : 31 + }, + { + } + )> + ], + { + }, + <"TTK_Union">, + { + "definition_ptr" : 25, + "is_complete_definition" : true + } + )>, + <"FieldDecl" : ( + { + "pointer" : 32, + "parent_pointer" : 22, + "source_range" : ( + { + "line" : 14, + "column" : 3 + }, + { + "line" : 18, + "column" : 5 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + { + "type_ptr" : 33 + }, + { + } + )> + ], + { + }, + <"TTK_Struct">, + { + "definition_ptr" : 22, + "is_complete_definition" : true + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 34, + "source_range" : ( + { + "line" : 12, + "column" : 1 + }, + { + "line" : 19, + "column" : 3 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "Value", + "qual_name" : [ + "Value" + ] + }, + 35, + { + } + )>, + <"FunctionDecl" : ( + { + "pointer" : 36, + "source_range" : ( + { + "line" : 21, + "column" : 1 + }, + { + "line" : 30, + "column" : 1 + } + ) + }, + { + "name" : "main", + "qual_name" : [ + "main" + ] + }, + { + "type_ptr" : 37 + }, + { + "decl_ptr_with_body" : 36, + "body" : <"CompoundStmt" : ( + { + "pointer" : 38, + "source_range" : ( + { + "line" : 21, + "column" : 16 + }, + { + "line" : 30, + "column" : 1 + } + ) + }, + [ + <"DeclStmt" : ( + { + "pointer" : 39, + "source_range" : ( + { + "line" : 22, + "column" : 3 + }, + { + "column" : 27 + } + ) + }, + [ + <"InitListExpr" : ( + { + "pointer" : 40, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 26 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 41, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 42, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 9, + "name" : { + "name" : "INT", + "qual_name" : [ + "INT", + "Tag" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )>, + <"InitListExpr" : ( + { + "pointer" : 43, + "source_range" : ( + { + "column" : 20 + }, + { + "column" : 24 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 44, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "0" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 33 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 35 + } + } + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 45, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 26 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + { + "type_ptr" : 35 + }, + { + "init_expr" : <"InitListExpr" : ( + { + "pointer" : 40, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 26 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 41, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 42, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 9, + "name" : { + "name" : "INT", + "qual_name" : [ + "INT", + "Tag" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )>, + <"InitListExpr" : ( + { + "pointer" : 43, + "source_range" : ( + { + "column" : 20 + }, + { + "column" : 24 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 44, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "0" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 33 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 35 + } + } + )> + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 46, + "source_range" : ( + { + "line" : 24, + "column" : 3 + }, + { + "column" : 11 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 47, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 48, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 35 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 45, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 35 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 24, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 14 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 49, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 50, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 11, + "name" : { + "name" : "THREE", + "qual_name" : [ + "THREE", + "Tag" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"DeclStmt" : ( + { + "pointer" : 51, + "source_range" : ( + { + "line" : 25, + "column" : 3 + }, + { + "column" : 24 + } + ) + }, + [ + <"InitListExpr" : ( + { + "pointer" : 52, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 23 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 53, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 54, + "source_range" : ( + { + "column" : 18 + }, + { + "column" : 18 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "2" + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 55, + "source_range" : ( + { + "column" : 21 + }, + { + "column" : 21 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "3" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 21 + } + } + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 56, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 23 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "t", + "qual_name" : [ + "t" + ] + }, + { + "type_ptr" : 21 + }, + { + "init_expr" : <"InitListExpr" : ( + { + "pointer" : 52, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 23 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 53, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 54, + "source_range" : ( + { + "column" : 18 + }, + { + "column" : 18 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "2" + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 55, + "source_range" : ( + { + "column" : 21 + }, + { + "column" : 21 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "3" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 21 + } + } + )> + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 57, + "source_range" : ( + { + "line" : 26, + "column" : 3 + }, + { + "column" : 20 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 58, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 11 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 59, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 60, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 35 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 45, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 35 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 33 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 32, + "name" : { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 33 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 29 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "three", + "qual_name" : [ + "three", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 28, + "name" : { + "name" : "three", + "qual_name" : [ + "three", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 29 + } + } + } + )>, + <"UnaryOperator" : ( + { + "pointer" : 61, + "source_range" : ( + { + "column" : 19 + }, + { + "column" : 20 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 62, + "source_range" : ( + { + "column" : 20 + }, + { + "column" : 20 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 21 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 56, + "name" : { + "name" : "t", + "qual_name" : [ + "t" + ] + }, + "qual_type" : { + "type_ptr" : 21 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 29 + } + }, + { + "kind" : <"AddrOf"> + } + )> + ], + { + "qual_type" : { + "type_ptr" : 29 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 63, + "source_range" : ( + { + "line" : 28, + "column" : 3 + }, + { + "column" : 11 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 64, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 65, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 35 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 45, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 35 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 24, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 14 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 66, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 67, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 12, + "name" : { + "name" : "STRING", + "qual_name" : [ + "STRING", + "Tag" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 68, + "source_range" : ( + { + "line" : 29, + "column" : 3 + }, + { + "column" : 17 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 69, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 11 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 70, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 71, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 35 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 45, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 35 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 33 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 32, + "name" : { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 33 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 31 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "str", + "qual_name" : [ + "str", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 30, + "name" : { + "name" : "str", + "qual_name" : [ + "str", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 31 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 72, + "source_range" : ( + { + "column" : 17 + }, + { + "column" : 17 + } + ) + }, + [ + <"StringLiteral" : ( + { + "pointer" : 73, + "source_range" : ( + { + "column" : 17 + }, + { + "column" : 17 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 74 + }, + "value_kind" : <"LValue"> + }, + [ + "hogehoge" + ] + )> + ], + { + "qual_type" : { + "type_ptr" : 31 + } + }, + { + "cast_kind" : <"ArrayToPointerDecay">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 31 + } + }, + { + "kind" : <"Assign"> + } + )> + ] + )> + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 75, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "instancetype", + "qual_name" : [ + "instancetype" + ] + }, + 76, + { + } + )> + ], + { + }, + { + "input_path" : "sample/types/discriminated_union.c", + "input_kind" : <"IK_C">, + "integer_type_widths" : { + "char_type" : 8, + "short_type" : 16, + "int_type" : 32, + "long_type" : 64, + "longlong_type" : 64 + }, + "types" : [ + <"BuiltinType" : ( + { + "pointer" : 77 + }, + <"Void"> + )>, + <"BuiltinType" : ( + { + "pointer" : 78 + }, + <"Bool"> + )>, + <"BuiltinType" : ( + { + "pointer" : 79 + }, + <"Char_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 80 + }, + <"SChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 81 + }, + <"Short"> + )>, + <"BuiltinType" : ( + { + "pointer" : 10 + }, + <"Int"> + )>, + <"BuiltinType" : ( + { + "pointer" : 82 + }, + <"Long"> + )>, + <"BuiltinType" : ( + { + "pointer" : 83 + }, + <"LongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 84 + }, + <"UChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 85 + }, + <"UShort"> + )>, + <"BuiltinType" : ( + { + "pointer" : 86 + }, + <"UInt"> + )>, + <"BuiltinType" : ( + { + "pointer" : 87 + }, + <"ULong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 88 + }, + <"ULongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 89 + }, + <"Float"> + )>, + <"BuiltinType" : ( + { + "pointer" : 90 + }, + <"Double"> + )>, + <"BuiltinType" : ( + { + "pointer" : 91 + }, + <"LongDouble"> + )>, + <"BuiltinType" : ( + { + "pointer" : 92 + }, + <"Float128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 93 + }, + <"Float16"> + )>, + <"BuiltinType" : ( + { + "pointer" : 94 + }, + <"ShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 95 + }, + <"Accum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 96 + }, + <"LongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 97 + }, + <"UShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 98 + }, + <"UAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 99 + }, + <"ULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 100 + }, + <"ShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 101 + }, + <"Fract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 102 + }, + <"LongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 103 + }, + <"UShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 104 + }, + <"UFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 105 + }, + <"ULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 106 + }, + <"SatShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 107 + }, + <"SatAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 108 + }, + <"SatLongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 109 + }, + <"SatUShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 110 + }, + <"SatUAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 111 + }, + <"SatULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 112 + }, + <"SatShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 113 + }, + <"SatFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 114 + }, + <"SatLongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 115 + }, + <"SatUShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 116 + }, + <"SatUFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 117 + }, + <"SatULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 118 + }, + <"Int128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 119 + }, + <"UInt128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 120 + }, + <"WChar_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 121 + }, + <"Char8"> + )>, + <"BuiltinType" : ( + { + "pointer" : 122 + }, + <"Dependent"> + )>, + <"BuiltinType" : ( + { + "pointer" : 123 + }, + <"Overload"> + )>, + <"BuiltinType" : ( + { + "pointer" : 124 + }, + <"BoundMember"> + )>, + <"BuiltinType" : ( + { + "pointer" : 125 + }, + <"PseudoObject"> + )>, + <"BuiltinType" : ( + { + "pointer" : 126 + }, + <"UnknownAny"> + )>, + <"BuiltinType" : ( + { + "pointer" : 127 + }, + <"ARCUnbridgedCast"> + )>, + <"BuiltinType" : ( + { + "pointer" : 128 + }, + <"BuiltinFn"> + )>, + <"ComplexType" : ( + { + "pointer" : 129 + } + )>, + <"ComplexType" : ( + { + "pointer" : 130 + } + )>, + <"ComplexType" : ( + { + "pointer" : 131 + } + )>, + <"ComplexType" : ( + { + "pointer" : 132 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 133 + }, + <"ObjCId"> + )>, + <"BuiltinType" : ( + { + "pointer" : 134 + }, + <"ObjCClass"> + )>, + <"BuiltinType" : ( + { + "pointer" : 135 + }, + <"ObjCSel"> + )>, + <"PointerType" : ( + { + "pointer" : 136 + }, + { + "type_ptr" : 77 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 137 + }, + <"NullPtr"> + )>, + <"BuiltinType" : ( + { + "pointer" : 138 + }, + <"Half"> + )>, + <"BuiltinType" : ( + { + "pointer" : 139 + }, + <"BFloat16"> + )>, + <"RecordType" : ( + { + "pointer" : 140 + }, + 141 + )>, + <"PointerType" : ( + { + "pointer" : 142 + }, + { + "type_ptr" : 10, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 143 + }, + { + "type_ptr" : 79, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 31 + }, + { + "type_ptr" : 79 + } + )>, + <"RecordType" : ( + { + "pointer" : 144 + }, + 145 + )>, + <"ConstantArrayType" : ( + { + "pointer" : 146 + }, + { + "element_type" : { + "type_ptr" : 144 + }, + "stride" : 24 + }, + 1 + )>, + <"EnumType" : ( + { + "pointer" : 8 + }, + 7 + )>, + <"ElaboratedType" : ( + { + "pointer" : 147, + "desugared_type" : 8 + } + )>, + <"RecordType" : ( + { + "pointer" : 16 + }, + 15 + )>, + <"ElaboratedType" : ( + { + "pointer" : 148, + "desugared_type" : 16 + } + )>, + <"RecordType" : ( + { + "pointer" : 23 + }, + 22 + )>, + <"TypedefType" : ( + { + "pointer" : 14, + "desugared_type" : 8 + }, + { + "child_type" : { + "type_ptr" : 147 + }, + "decl_ptr" : 13 + } + )>, + <"RecordType" : ( + { + "pointer" : 26 + }, + 25 + )>, + <"TypedefType" : ( + { + "pointer" : 21, + "desugared_type" : 16 + }, + { + "child_type" : { + "type_ptr" : 148 + }, + "decl_ptr" : 20 + } + )>, + <"PointerType" : ( + { + "pointer" : 149 + }, + { + "type_ptr" : 16 + } + )>, + <"PointerType" : ( + { + "pointer" : 29 + }, + { + "type_ptr" : 21 + } + )>, + <"ElaboratedType" : ( + { + "pointer" : 33, + "desugared_type" : 26 + } + )>, + <"ElaboratedType" : ( + { + "pointer" : 150, + "desugared_type" : 23 + } + )>, + <"FunctionProtoType" : ( + { + "pointer" : 37 + }, + { + "return_type" : { + "type_ptr" : 10 + } + }, + { + } + )>, + <"PointerType" : ( + { + "pointer" : 151 + }, + { + "type_ptr" : 31 + } + )>, + <"TypedefType" : ( + { + "pointer" : 35, + "desugared_type" : 23 + }, + { + "child_type" : { + "type_ptr" : 150 + }, + "decl_ptr" : 34 + } + )>, + <"ConstantArrayType" : ( + { + "pointer" : 74 + }, + { + "element_type" : { + "type_ptr" : 79 + }, + "stride" : 1 + }, + 9 + )>, + <"ObjCObjectType" : ( + { + "pointer" : 152 + }, + { + "base_type" : 133 + } + )>, + <"ObjCObjectPointerType" : ( + { + "pointer" : 153 + }, + { + "type_ptr" : 152 + } + )>, + <"TypedefType" : ( + { + "pointer" : 154, + "desugared_type" : 153 + }, + { + "child_type" : { + "type_ptr" : 153 + }, + "decl_ptr" : 155 + } + )>, + <"TypedefType" : ( + { + "pointer" : 76, + "desugared_type" : 153 + }, + { + "child_type" : { + "type_ptr" : 154 + }, + "decl_ptr" : 75 + } + )>, + <"NoneType" : ( + { + "pointer" : 0 + } + )> + ] + } +)> From 40baf6407d44cd3055ef6a5c855f8f883ce435b3 Mon Sep 17 00:00:00 2001 From: cedretaber Date: Sun, 9 Oct 2022 00:37:52 +0900 Subject: [PATCH 5/6] Update sample code. --- sample/types/discriminated_union.c | 23 +- sample/types/discriminated_union.c.yojson | 2980 ++++++++++++++++----- 2 files changed, 2312 insertions(+), 691 deletions(-) diff --git a/sample/types/discriminated_union.c b/sample/types/discriminated_union.c index 8812887..33766ce 100644 --- a/sample/types/discriminated_union.c +++ b/sample/types/discriminated_union.c @@ -18,13 +18,28 @@ typedef struct { } value; } Value; +void set_num(Value *value, int num) { + value->tag = INT; + value->value.num = num; +} + +void set_three(Value *value, Three *three) { + value->tag = THREE; + value->value.three = three; +} + +void set_str(Value *value, char *str) { + value->tag = STRING; + value->value.str = str; +} + int main(void) { Value x = { INT, { 0 } }; - x.tag = THREE; + set_num(&x, 42); + Three t = { 1, 2, 3 }; - x.value.three = &t; + set_three(&x, &t); - x.tag = STRING; - x.value.str = "hogehoge"; + set_str(&x, "hogehoge"); } diff --git a/sample/types/discriminated_union.c.yojson b/sample/types/discriminated_union.c.yojson index 27fa8b0..a3b25c7 100644 --- a/sample/types/discriminated_union.c.yojson +++ b/sample/types/discriminated_union.c.yojson @@ -478,6 +478,7 @@ "column" : 9 } ), + "is_this_declaration_referenced" : true, "access" : <"Public"> }, { @@ -636,86 +637,144 @@ "column" : 1 }, { - "line" : 30, + "line" : 24, "column" : 1 } - ) + ), + "is_used" : true, + "is_this_declaration_referenced" : true }, { - "name" : "main", + "name" : "set_num", "qual_name" : [ - "main" + "set_num" ] }, { "type_ptr" : 37 }, { + "parameters" : [ + <"ParmVarDecl" : ( + { + "pointer" : 38, + "source_range" : ( + { + "line" : 21, + "column" : 14 + }, + { + "column" : 21 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "value", + "qual_name" : [ + "value" + ] + }, + { + "type_ptr" : 39 + }, + { + "parm_index_in_function" : 0 + } + )>, + <"ParmVarDecl" : ( + { + "pointer" : 40, + "source_range" : ( + { + "column" : 28 + }, + { + "column" : 32 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "num", + "qual_name" : [ + "num" + ] + }, + { + "type_ptr" : 10 + }, + { + "parm_index_in_function" : 1 + } + )> + ], "decl_ptr_with_body" : 36, "body" : <"CompoundStmt" : ( { - "pointer" : 38, + "pointer" : 41, "source_range" : ( { - "line" : 21, - "column" : 16 + "column" : 37 }, { - "line" : 30, + "line" : 24, "column" : 1 } ) }, [ - <"DeclStmt" : ( + <"BinaryOperator" : ( { - "pointer" : 39, + "pointer" : 42, "source_range" : ( { "line" : 22, "column" : 3 }, { - "column" : 27 + "column" : 16 } ) }, [ - <"InitListExpr" : ( + <"MemberExpr" : ( { - "pointer" : 40, + "pointer" : 43, "source_range" : ( { - "column" : 13 + "column" : 3 }, { - "column" : 26 + "column" : 10 } ) }, [ <"ImplicitCastExpr" : ( { - "pointer" : 41, + "pointer" : 44, "source_range" : ( { - "column" : 15 + "column" : 3 }, { - "column" : 15 + "column" : 3 } ) }, [ <"DeclRefExpr" : ( { - "pointer" : 42, + "pointer" : 45, "source_range" : ( { - "column" : 15 + "column" : 3 }, { - "column" : 15 + "column" : 3 } ) }, @@ -723,22 +782,22 @@ ], { "qual_type" : { - "type_ptr" : 10 - } + "type_ptr" : 39 + }, + "value_kind" : <"LValue"> }, { "decl_ref" : { - "kind" : <"EnumConstant">, - "decl_pointer" : 9, + "kind" : <"ParmVar">, + "decl_pointer" : 38, "name" : { - "name" : "INT", + "name" : "value", "qual_name" : [ - "INT", - "Tag" + "value" ] }, "qual_type" : { - "type_ptr" : 10 + "type_ptr" : 39 } } } @@ -746,129 +805,183 @@ ], { "qual_type" : { - "type_ptr" : 14 + "type_ptr" : 39 } }, { - "cast_kind" : <"IntegralCast">, + "cast_kind" : <"LValueToRValue">, "base_path" : [ ] }, false - )>, - <"InitListExpr" : ( + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + }, + "value_kind" : <"LValue"> + }, + { + "is_arrow" : true, + "performs_virtual_dispatch" : true, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 24, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 14 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 46, + "source_range" : ( + { + "column" : 16 + }, + { + "column" : 16 + } + ) + }, + [ + <"DeclRefExpr" : ( { - "pointer" : 43, + "pointer" : 47, "source_range" : ( { - "column" : 20 + "column" : 16 }, { - "column" : 24 + "column" : 16 } ) }, [ - <"IntegerLiteral" : ( - { - "pointer" : 44, - "source_range" : ( - { - "column" : 22 - }, - { - "column" : 22 - } - ) - }, - [ - ], - { - "qual_type" : { - "type_ptr" : 10 - } - }, - { - "is_signed" : true, - "bitwidth" : 32, - "value" : "0" - } - )> ], { "qual_type" : { - "type_ptr" : 33 + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 9, + "name" : { + "name" : "INT", + "qual_name" : [ + "INT", + "Tag" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } } } )> ], { "qual_type" : { - "type_ptr" : 35 + "type_ptr" : 14 } - } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false )> ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 48, + "source_range" : ( + { + "line" : 23, + "column" : 3 + }, + { + "column" : 22 + } + ) + }, [ - <"VarDecl" : ( + <"MemberExpr" : ( { - "pointer" : 45, + "pointer" : 49, "source_range" : ( { "column" : 3 }, { - "column" : 26 + "column" : 16 } - ), - "is_used" : true, - "is_this_declaration_referenced" : true - }, - { - "name" : "x", - "qual_name" : [ - "x" - ] - }, - { - "type_ptr" : 35 + ) }, - { - "init_expr" : <"InitListExpr" : ( + [ + <"MemberExpr" : ( { - "pointer" : 40, + "pointer" : 50, "source_range" : ( { - "column" : 13 + "column" : 3 }, { - "column" : 26 + "column" : 10 } ) }, [ <"ImplicitCastExpr" : ( { - "pointer" : 41, + "pointer" : 51, "source_range" : ( { - "column" : 15 + "column" : 3 }, { - "column" : 15 + "column" : 3 } ) }, [ <"DeclRefExpr" : ( { - "pointer" : 42, + "pointer" : 52, "source_range" : ( { - "column" : 15 + "column" : 3 }, { - "column" : 15 + "column" : 3 } ) }, @@ -876,22 +989,22 @@ ], { "qual_type" : { - "type_ptr" : 10 - } + "type_ptr" : 39 + }, + "value_kind" : <"LValue"> }, { "decl_ref" : { - "kind" : <"EnumConstant">, - "decl_pointer" : 9, + "kind" : <"ParmVar">, + "decl_pointer" : 38, "name" : { - "name" : "INT", + "name" : "value", "qual_name" : [ - "INT", - "Tag" + "value" ] }, "qual_type" : { - "type_ptr" : 10 + "type_ptr" : 39 } } } @@ -899,102 +1012,1601 @@ ], { "qual_type" : { - "type_ptr" : 14 + "type_ptr" : 39 } }, { - "cast_kind" : <"IntegralCast">, + "cast_kind" : <"LValueToRValue">, "base_path" : [ ] }, false - )>, - <"InitListExpr" : ( - { - "pointer" : 43, - "source_range" : ( - { - "column" : 20 - }, - { - "column" : 24 - } - ) - }, - [ - <"IntegerLiteral" : ( - { - "pointer" : 44, - "source_range" : ( - { - "column" : 22 - }, - { - "column" : 22 - } - ) - }, - [ - ], - { - "qual_type" : { - "type_ptr" : 10 - } - }, - { - "is_signed" : true, - "bitwidth" : 32, - "value" : "0" - } - )> - ], - { - "qual_type" : { - "type_ptr" : 33 - } - } )> ], { "qual_type" : { - "type_ptr" : 35 - } - } - )> - } - )> - ] - )>, - <"BinaryOperator" : ( - { - "pointer" : 46, - "source_range" : ( - { - "line" : 24, - "column" : 3 - }, - { - "column" : 11 - } + "type_ptr" : 33 + }, + "value_kind" : <"LValue"> + }, + { + "is_arrow" : true, + "performs_virtual_dispatch" : true, + "name" : { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 32, + "name" : { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 33 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "num", + "qual_name" : [ + "num", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 27, + "name" : { + "name" : "num", + "qual_name" : [ + "num", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 53, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 54, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"ParmVar">, + "decl_pointer" : 40, + "name" : { + "name" : "num", + "qual_name" : [ + "num" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "cast_kind" : <"LValueToRValue">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "kind" : <"Assign"> + } + )> + ] + )> + } + )>, + <"FunctionDecl" : ( + { + "pointer" : 55, + "source_range" : ( + { + "line" : 26, + "column" : 1 + }, + { + "line" : 29, + "column" : 1 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "set_three", + "qual_name" : [ + "set_three" + ] + }, + { + "type_ptr" : 56 + }, + { + "parameters" : [ + <"ParmVarDecl" : ( + { + "pointer" : 57, + "source_range" : ( + { + "line" : 26, + "column" : 16 + }, + { + "column" : 23 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "value", + "qual_name" : [ + "value" + ] + }, + { + "type_ptr" : 39 + }, + { + "parm_index_in_function" : 0 + } + )>, + <"ParmVarDecl" : ( + { + "pointer" : 58, + "source_range" : ( + { + "column" : 30 + }, + { + "column" : 37 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "three", + "qual_name" : [ + "three" + ] + }, + { + "type_ptr" : 29 + }, + { + "parm_index_in_function" : 1 + } + )> + ], + "decl_ptr_with_body" : 55, + "body" : <"CompoundStmt" : ( + { + "pointer" : 59, + "source_range" : ( + { + "column" : 44 + }, + { + "line" : 29, + "column" : 1 + } + ) + }, + [ + <"BinaryOperator" : ( + { + "pointer" : 60, + "source_range" : ( + { + "line" : 27, + "column" : 3 + }, + { + "column" : 16 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 61, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 10 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 62, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 63, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 39 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"ParmVar">, + "decl_pointer" : 57, + "name" : { + "name" : "value", + "qual_name" : [ + "value" + ] + }, + "qual_type" : { + "type_ptr" : 39 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 39 + } + }, + { + "cast_kind" : <"LValueToRValue">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + }, + "value_kind" : <"LValue"> + }, + { + "is_arrow" : true, + "performs_virtual_dispatch" : true, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 24, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 14 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 64, + "source_range" : ( + { + "column" : 16 + }, + { + "column" : 16 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 65, + "source_range" : ( + { + "column" : 16 + }, + { + "column" : 16 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 11, + "name" : { + "name" : "THREE", + "qual_name" : [ + "THREE", + "Tag" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 66, + "source_range" : ( + { + "line" : 28, + "column" : 3 + }, + { + "column" : 24 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 67, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 16 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 68, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 10 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 69, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 70, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 39 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"ParmVar">, + "decl_pointer" : 57, + "name" : { + "name" : "value", + "qual_name" : [ + "value" + ] + }, + "qual_type" : { + "type_ptr" : 39 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 39 + } + }, + { + "cast_kind" : <"LValueToRValue">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 33 + }, + "value_kind" : <"LValue"> + }, + { + "is_arrow" : true, + "performs_virtual_dispatch" : true, + "name" : { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 32, + "name" : { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 33 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 29 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "three", + "qual_name" : [ + "three", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 28, + "name" : { + "name" : "three", + "qual_name" : [ + "three", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 29 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 71, + "source_range" : ( + { + "column" : 24 + }, + { + "column" : 24 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 72, + "source_range" : ( + { + "column" : 24 + }, + { + "column" : 24 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 29 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"ParmVar">, + "decl_pointer" : 58, + "name" : { + "name" : "three", + "qual_name" : [ + "three" + ] + }, + "qual_type" : { + "type_ptr" : 29 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 29 + } + }, + { + "cast_kind" : <"LValueToRValue">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 29 + } + }, + { + "kind" : <"Assign"> + } + )> + ] + )> + } + )>, + <"FunctionDecl" : ( + { + "pointer" : 73, + "source_range" : ( + { + "line" : 31, + "column" : 1 + }, + { + "line" : 34, + "column" : 1 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "set_str", + "qual_name" : [ + "set_str" + ] + }, + { + "type_ptr" : 74 + }, + { + "parameters" : [ + <"ParmVarDecl" : ( + { + "pointer" : 75, + "source_range" : ( + { + "line" : 31, + "column" : 14 + }, + { + "column" : 21 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "value", + "qual_name" : [ + "value" + ] + }, + { + "type_ptr" : 39 + }, + { + "parm_index_in_function" : 0 + } + )>, + <"ParmVarDecl" : ( + { + "pointer" : 76, + "source_range" : ( + { + "column" : 28 + }, + { + "column" : 34 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "str", + "qual_name" : [ + "str" + ] + }, + { + "type_ptr" : 31 + }, + { + "parm_index_in_function" : 1 + } + )> + ], + "decl_ptr_with_body" : 73, + "body" : <"CompoundStmt" : ( + { + "pointer" : 77, + "source_range" : ( + { + "column" : 39 + }, + { + "line" : 34, + "column" : 1 + } + ) + }, + [ + <"BinaryOperator" : ( + { + "pointer" : 78, + "source_range" : ( + { + "line" : 32, + "column" : 3 + }, + { + "column" : 16 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 79, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 10 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 80, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 81, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 39 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"ParmVar">, + "decl_pointer" : 75, + "name" : { + "name" : "value", + "qual_name" : [ + "value" + ] + }, + "qual_type" : { + "type_ptr" : 39 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 39 + } + }, + { + "cast_kind" : <"LValueToRValue">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + }, + "value_kind" : <"LValue"> + }, + { + "is_arrow" : true, + "performs_virtual_dispatch" : true, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 24, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 14 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 82, + "source_range" : ( + { + "column" : 16 + }, + { + "column" : 16 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 83, + "source_range" : ( + { + "column" : 16 + }, + { + "column" : 16 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 12, + "name" : { + "name" : "STRING", + "qual_name" : [ + "STRING", + "Tag" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 84, + "source_range" : ( + { + "line" : 33, + "column" : 3 + }, + { + "column" : 22 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 85, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 16 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 86, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 10 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 87, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 88, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 39 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"ParmVar">, + "decl_pointer" : 75, + "name" : { + "name" : "value", + "qual_name" : [ + "value" + ] + }, + "qual_type" : { + "type_ptr" : 39 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 39 + } + }, + { + "cast_kind" : <"LValueToRValue">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 33 + }, + "value_kind" : <"LValue"> + }, + { + "is_arrow" : true, + "performs_virtual_dispatch" : true, + "name" : { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 32, + "name" : { + "name" : "value", + "qual_name" : [ + "value", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 33 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 31 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "str", + "qual_name" : [ + "str", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 30, + "name" : { + "name" : "str", + "qual_name" : [ + "str", + "anonymous_union_sample/types/discriminated_union.c:14:3", + "Value" + ] + }, + "qual_type" : { + "type_ptr" : 31 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 89, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 90, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 31 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"ParmVar">, + "decl_pointer" : 76, + "name" : { + "name" : "str", + "qual_name" : [ + "str" + ] + }, + "qual_type" : { + "type_ptr" : 31 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 31 + } + }, + { + "cast_kind" : <"LValueToRValue">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 31 + } + }, + { + "kind" : <"Assign"> + } + )> + ] + )> + } + )>, + <"FunctionDecl" : ( + { + "pointer" : 91, + "source_range" : ( + { + "line" : 36, + "column" : 1 + }, + { + "line" : 45, + "column" : 1 + } + ) + }, + { + "name" : "main", + "qual_name" : [ + "main" + ] + }, + { + "type_ptr" : 92 + }, + { + "decl_ptr_with_body" : 91, + "body" : <"CompoundStmt" : ( + { + "pointer" : 93, + "source_range" : ( + { + "line" : 36, + "column" : 16 + }, + { + "line" : 45, + "column" : 1 + } + ) + }, + [ + <"DeclStmt" : ( + { + "pointer" : 94, + "source_range" : ( + { + "line" : 37, + "column" : 3 + }, + { + "column" : 27 + } + ) + }, + [ + <"InitListExpr" : ( + { + "pointer" : 95, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 26 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 96, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 97, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 9, + "name" : { + "name" : "INT", + "qual_name" : [ + "INT", + "Tag" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )>, + <"InitListExpr" : ( + { + "pointer" : 98, + "source_range" : ( + { + "column" : 20 + }, + { + "column" : 24 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 99, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "0" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 33 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 35 + } + } + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 100, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 26 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + { + "type_ptr" : 35 + }, + { + "init_expr" : <"InitListExpr" : ( + { + "pointer" : 95, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 26 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 96, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 97, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 9, + "name" : { + "name" : "INT", + "qual_name" : [ + "INT", + "Tag" + ] + }, + "qual_type" : { + "type_ptr" : 10 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )>, + <"InitListExpr" : ( + { + "pointer" : 98, + "source_range" : ( + { + "column" : 20 + }, + { + "column" : 24 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 99, + "source_range" : ( + { + "column" : 22 + }, + { + "column" : 22 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "0" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 33 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 35 + } + } + )> + } + )> + ] + )>, + <"CallExpr" : ( + { + "pointer" : 101, + "source_range" : ( + { + "line" : 39, + "column" : 3 + }, + { + "column" : 17 + } ) }, [ - <"MemberExpr" : ( + <"ImplicitCastExpr" : ( { - "pointer" : 47, + "pointer" : 102, "source_range" : ( { "column" : 3 }, { - "column" : 5 + "column" : 3 } ) }, [ <"DeclRefExpr" : ( { - "pointer" : 48, + "pointer" : 103, "source_range" : ( { "column" : 3 @@ -1008,22 +2620,21 @@ ], { "qual_type" : { - "type_ptr" : 35 - }, - "value_kind" : <"LValue"> + "type_ptr" : 37 + } }, { "decl_ref" : { - "kind" : <"Var">, - "decl_pointer" : 45, + "kind" : <"Function">, + "decl_pointer" : 36, "name" : { - "name" : "x", + "name" : "set_num", "qual_name" : [ - "x" + "set_num" ] }, "qual_type" : { - "type_ptr" : 35 + "type_ptr" : 37 } } } @@ -1031,57 +2642,38 @@ ], { "qual_type" : { - "type_ptr" : 14 - }, - "value_kind" : <"LValue"> + "type_ptr" : 104 + } }, { - "performs_virtual_dispatch" : true, - "name" : { - "name" : "tag", - "qual_name" : [ - "tag", - "Value" - ] - }, - "decl_ref" : { - "kind" : <"Field">, - "decl_pointer" : 24, - "name" : { - "name" : "tag", - "qual_name" : [ - "tag", - "Value" - ] - }, - "qual_type" : { - "type_ptr" : 14 - } - } - } + "cast_kind" : <"FunctionToPointerDecay">, + "base_path" : [ + ] + }, + false )>, - <"ImplicitCastExpr" : ( + <"UnaryOperator" : ( { - "pointer" : 49, + "pointer" : 105, "source_range" : ( { "column" : 11 }, { - "column" : 11 + "column" : 12 } ) }, [ <"DeclRefExpr" : ( { - "pointer" : 50, + "pointer" : 106, "source_range" : ( { - "column" : 11 + "column" : 12 }, { - "column" : 11 + "column" : 12 } ) }, @@ -1089,22 +2681,22 @@ ], { "qual_type" : { - "type_ptr" : 10 - } + "type_ptr" : 35 + }, + "value_kind" : <"LValue"> }, { "decl_ref" : { - "kind" : <"EnumConstant">, - "decl_pointer" : 11, + "kind" : <"Var">, + "decl_pointer" : 100, "name" : { - "name" : "THREE", + "name" : "x", "qual_name" : [ - "THREE", - "Tag" + "x" ] }, "qual_type" : { - "type_ptr" : 10 + "type_ptr" : 35 } } } @@ -1112,32 +2704,51 @@ ], { "qual_type" : { - "type_ptr" : 14 + "type_ptr" : 39 } }, { - "cast_kind" : <"IntegralCast">, - "base_path" : [ - ] + "kind" : <"AddrOf"> + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 107, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) }, - false + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "42" + } )> ], { "qual_type" : { - "type_ptr" : 14 + "type_ptr" : 108 } - }, - { - "kind" : <"Assign"> } )>, <"DeclStmt" : ( { - "pointer" : 51, + "pointer" : 109, "source_range" : ( { - "line" : 25, + "line" : 41, "column" : 3 }, { @@ -1148,7 +2759,7 @@ [ <"InitListExpr" : ( { - "pointer" : 52, + "pointer" : 110, "source_range" : ( { "column" : 13 @@ -1161,7 +2772,7 @@ [ <"IntegerLiteral" : ( { - "pointer" : 53, + "pointer" : 111, "source_range" : ( { "column" : 15 @@ -1186,7 +2797,7 @@ )>, <"IntegerLiteral" : ( { - "pointer" : 54, + "pointer" : 112, "source_range" : ( { "column" : 18 @@ -1211,7 +2822,7 @@ )>, <"IntegerLiteral" : ( { - "pointer" : 55, + "pointer" : 113, "source_range" : ( { "column" : 21 @@ -1245,7 +2856,7 @@ [ <"VarDecl" : ( { - "pointer" : 56, + "pointer" : 114, "source_range" : ( { "column" : 3 @@ -1269,7 +2880,7 @@ { "init_expr" : <"InitListExpr" : ( { - "pointer" : 52, + "pointer" : 110, "source_range" : ( { "column" : 13 @@ -1282,7 +2893,7 @@ [ <"IntegerLiteral" : ( { - "pointer" : 53, + "pointer" : 111, "source_range" : ( { "column" : 15 @@ -1307,7 +2918,7 @@ )>, <"IntegerLiteral" : ( { - "pointer" : 54, + "pointer" : 112, "source_range" : ( { "column" : 18 @@ -1328,93 +2939,17 @@ "is_signed" : true, "bitwidth" : 32, "value" : "2" - } - )>, - <"IntegerLiteral" : ( - { - "pointer" : 55, - "source_range" : ( - { - "column" : 21 - }, - { - "column" : 21 - } - ) - }, - [ - ], - { - "qual_type" : { - "type_ptr" : 10 - } - }, - { - "is_signed" : true, - "bitwidth" : 32, - "value" : "3" - } - )> - ], - { - "qual_type" : { - "type_ptr" : 21 - } - } - )> - } - )> - ] - )>, - <"BinaryOperator" : ( - { - "pointer" : 57, - "source_range" : ( - { - "line" : 26, - "column" : 3 - }, - { - "column" : 20 - } - ) - }, - [ - <"MemberExpr" : ( - { - "pointer" : 58, - "source_range" : ( - { - "column" : 3 - }, - { - "column" : 11 - } - ) - }, - [ - <"MemberExpr" : ( - { - "pointer" : 59, - "source_range" : ( - { - "column" : 3 - }, - { - "column" : 5 - } - ) - }, - [ - <"DeclRefExpr" : ( + } + )>, + <"IntegerLiteral" : ( { - "pointer" : 60, + "pointer" : 113, "source_range" : ( { - "column" : 3 + "column" : 21 }, { - "column" : 3 + "column" : 21 } ) }, @@ -1422,114 +2957,62 @@ ], { "qual_type" : { - "type_ptr" : 35 - }, - "value_kind" : <"LValue"> + "type_ptr" : 10 + } }, { - "decl_ref" : { - "kind" : <"Var">, - "decl_pointer" : 45, - "name" : { - "name" : "x", - "qual_name" : [ - "x" - ] - }, - "qual_type" : { - "type_ptr" : 35 - } - } + "is_signed" : true, + "bitwidth" : 32, + "value" : "3" } )> ], { "qual_type" : { - "type_ptr" : 33 - }, - "value_kind" : <"LValue"> - }, - { - "performs_virtual_dispatch" : true, - "name" : { - "name" : "value", - "qual_name" : [ - "value", - "Value" - ] - }, - "decl_ref" : { - "kind" : <"Field">, - "decl_pointer" : 32, - "name" : { - "name" : "value", - "qual_name" : [ - "value", - "Value" - ] - }, - "qual_type" : { - "type_ptr" : 33 - } + "type_ptr" : 21 } } )> - ], + } + )> + ] + )>, + <"CallExpr" : ( + { + "pointer" : 115, + "source_range" : ( { - "qual_type" : { - "type_ptr" : 29 - }, - "value_kind" : <"LValue"> + "line" : 42, + "column" : 3 }, { - "performs_virtual_dispatch" : true, - "name" : { - "name" : "three", - "qual_name" : [ - "three", - "anonymous_union_sample/types/discriminated_union.c:14:3", - "Value" - ] - }, - "decl_ref" : { - "kind" : <"Field">, - "decl_pointer" : 28, - "name" : { - "name" : "three", - "qual_name" : [ - "three", - "anonymous_union_sample/types/discriminated_union.c:14:3", - "Value" - ] - }, - "qual_type" : { - "type_ptr" : 29 - } - } + "column" : 19 } - )>, - <"UnaryOperator" : ( + ) + }, + [ + <"ImplicitCastExpr" : ( { - "pointer" : 61, + "pointer" : 116, "source_range" : ( { - "column" : 19 + "column" : 3 }, { - "column" : 20 + "column" : 3 } ) }, [ <"DeclRefExpr" : ( { - "pointer" : 62, + "pointer" : 117, "source_range" : ( { - "column" : 20 + "column" : 3 }, { - "column" : 20 + "column" : 3 } ) }, @@ -1537,22 +3020,21 @@ ], { "qual_type" : { - "type_ptr" : 21 - }, - "value_kind" : <"LValue"> + "type_ptr" : 56 + } }, { "decl_ref" : { - "kind" : <"Var">, - "decl_pointer" : 56, + "kind" : <"Function">, + "decl_pointer" : 55, "name" : { - "name" : "t", + "name" : "set_three", "qual_name" : [ - "t" + "set_three" ] }, "qual_type" : { - "type_ptr" : 21 + "type_ptr" : 56 } } } @@ -1560,59 +3042,38 @@ ], { "qual_type" : { - "type_ptr" : 29 + "type_ptr" : 118 } }, { - "kind" : <"AddrOf"> - } - )> - ], - { - "qual_type" : { - "type_ptr" : 29 - } - }, - { - "kind" : <"Assign"> - } - )>, - <"BinaryOperator" : ( - { - "pointer" : 63, - "source_range" : ( - { - "line" : 28, - "column" : 3 + "cast_kind" : <"FunctionToPointerDecay">, + "base_path" : [ + ] }, + false + )>, + <"UnaryOperator" : ( { - "column" : 11 - } - ) - }, - [ - <"MemberExpr" : ( - { - "pointer" : 64, + "pointer" : 119, "source_range" : ( { - "column" : 3 + "column" : 13 }, { - "column" : 5 + "column" : 14 } ) }, [ <"DeclRefExpr" : ( { - "pointer" : 65, + "pointer" : 120, "source_range" : ( { - "column" : 3 + "column" : 14 }, { - "column" : 3 + "column" : 14 } ) }, @@ -1627,7 +3088,7 @@ { "decl_ref" : { "kind" : <"Var">, - "decl_pointer" : 45, + "decl_pointer" : 100, "name" : { "name" : "x", "qual_name" : [ @@ -1643,57 +3104,35 @@ ], { "qual_type" : { - "type_ptr" : 14 - }, - "value_kind" : <"LValue"> + "type_ptr" : 39 + } }, { - "performs_virtual_dispatch" : true, - "name" : { - "name" : "tag", - "qual_name" : [ - "tag", - "Value" - ] - }, - "decl_ref" : { - "kind" : <"Field">, - "decl_pointer" : 24, - "name" : { - "name" : "tag", - "qual_name" : [ - "tag", - "Value" - ] - }, - "qual_type" : { - "type_ptr" : 14 - } - } + "kind" : <"AddrOf"> } )>, - <"ImplicitCastExpr" : ( + <"UnaryOperator" : ( { - "pointer" : 66, + "pointer" : 121, "source_range" : ( { - "column" : 11 + "column" : 17 }, { - "column" : 11 + "column" : 18 } ) }, [ <"DeclRefExpr" : ( { - "pointer" : 67, + "pointer" : 122, "source_range" : ( { - "column" : 11 + "column" : 18 }, { - "column" : 11 + "column" : 18 } ) }, @@ -1701,22 +3140,22 @@ ], { "qual_type" : { - "type_ptr" : 10 - } + "type_ptr" : 21 + }, + "value_kind" : <"LValue"> }, { "decl_ref" : { - "kind" : <"EnumConstant">, - "decl_pointer" : 12, + "kind" : <"Var">, + "decl_pointer" : 114, "name" : { - "name" : "STRING", + "name" : "t", "qual_name" : [ - "STRING", - "Tag" + "t" ] }, "qual_type" : { - "type_ptr" : 10 + "type_ptr" : 21 } } } @@ -1724,130 +3163,140 @@ ], { "qual_type" : { - "type_ptr" : 14 + "type_ptr" : 29 } }, { - "cast_kind" : <"IntegralCast">, - "base_path" : [ - ] - }, - false + "kind" : <"AddrOf"> + } )> ], { "qual_type" : { - "type_ptr" : 14 + "type_ptr" : 108 } - }, - { - "kind" : <"Assign"> } )>, - <"BinaryOperator" : ( + <"CallExpr" : ( { - "pointer" : 68, + "pointer" : 123, "source_range" : ( { - "line" : 29, + "line" : 44, "column" : 3 }, { - "column" : 17 + "column" : 25 } ) }, [ - <"MemberExpr" : ( + <"ImplicitCastExpr" : ( { - "pointer" : 69, + "pointer" : 124, "source_range" : ( { "column" : 3 }, { - "column" : 11 + "column" : 3 } ) }, [ - <"MemberExpr" : ( + <"DeclRefExpr" : ( { - "pointer" : 70, + "pointer" : 125, "source_range" : ( { "column" : 3 }, { - "column" : 5 + "column" : 3 } ) }, [ - <"DeclRefExpr" : ( - { - "pointer" : 71, - "source_range" : ( - { - "column" : 3 - }, - { - "column" : 3 - } - ) + ], + { + "qual_type" : { + "type_ptr" : 74 + } + }, + { + "decl_ref" : { + "kind" : <"Function">, + "decl_pointer" : 73, + "name" : { + "name" : "set_str", + "qual_name" : [ + "set_str" + ] }, - [ - ], + "qual_type" : { + "type_ptr" : 74 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 126 + } + }, + { + "cast_kind" : <"FunctionToPointerDecay">, + "base_path" : [ + ] + }, + false + )>, + <"UnaryOperator" : ( + { + "pointer" : 127, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 12 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 128, + "source_range" : ( { - "qual_type" : { - "type_ptr" : 35 - }, - "value_kind" : <"LValue"> + "column" : 12 }, { - "decl_ref" : { - "kind" : <"Var">, - "decl_pointer" : 45, - "name" : { - "name" : "x", - "qual_name" : [ - "x" - ] - }, - "qual_type" : { - "type_ptr" : 35 - } - } + "column" : 12 } - )> + ) + }, + [ ], { "qual_type" : { - "type_ptr" : 33 + "type_ptr" : 35 }, "value_kind" : <"LValue"> }, { - "performs_virtual_dispatch" : true, - "name" : { - "name" : "value", - "qual_name" : [ - "value", - "Value" - ] - }, "decl_ref" : { - "kind" : <"Field">, - "decl_pointer" : 32, + "kind" : <"Var">, + "decl_pointer" : 100, "name" : { - "name" : "value", + "name" : "x", "qual_name" : [ - "value", - "Value" + "x" ] }, "qual_type" : { - "type_ptr" : 33 + "type_ptr" : 35 } } } @@ -1855,59 +3304,35 @@ ], { "qual_type" : { - "type_ptr" : 31 - }, - "value_kind" : <"LValue"> + "type_ptr" : 39 + } }, { - "performs_virtual_dispatch" : true, - "name" : { - "name" : "str", - "qual_name" : [ - "str", - "anonymous_union_sample/types/discriminated_union.c:14:3", - "Value" - ] - }, - "decl_ref" : { - "kind" : <"Field">, - "decl_pointer" : 30, - "name" : { - "name" : "str", - "qual_name" : [ - "str", - "anonymous_union_sample/types/discriminated_union.c:14:3", - "Value" - ] - }, - "qual_type" : { - "type_ptr" : 31 - } - } + "kind" : <"AddrOf"> } )>, <"ImplicitCastExpr" : ( { - "pointer" : 72, + "pointer" : 129, "source_range" : ( { - "column" : 17 + "column" : 15 }, { - "column" : 17 + "column" : 15 } ) }, [ <"StringLiteral" : ( { - "pointer" : 73, + "pointer" : 130, "source_range" : ( { - "column" : 17 + "column" : 15 }, { - "column" : 17 + "column" : 15 } ) }, @@ -1915,7 +3340,7 @@ ], { "qual_type" : { - "type_ptr" : 74 + "type_ptr" : 131 }, "value_kind" : <"LValue"> }, @@ -1939,11 +3364,8 @@ ], { "qual_type" : { - "type_ptr" : 31 + "type_ptr" : 108 } - }, - { - "kind" : <"Assign"> } )> ] @@ -1952,7 +3374,7 @@ )>, <"TypedefDecl" : ( { - "pointer" : 75, + "pointer" : 132, "source_range" : ( { }, @@ -1967,7 +3389,7 @@ "instancetype" ] }, - 76, + 133, { } )> @@ -1987,31 +3409,31 @@ "types" : [ <"BuiltinType" : ( { - "pointer" : 77 + "pointer" : 108 }, <"Void"> )>, <"BuiltinType" : ( { - "pointer" : 78 + "pointer" : 134 }, <"Bool"> )>, <"BuiltinType" : ( { - "pointer" : 79 + "pointer" : 135 }, <"Char_S"> )>, <"BuiltinType" : ( { - "pointer" : 80 + "pointer" : 136 }, <"SChar"> )>, <"BuiltinType" : ( { - "pointer" : 81 + "pointer" : 137 }, <"Short"> )>, @@ -2023,359 +3445,359 @@ )>, <"BuiltinType" : ( { - "pointer" : 82 + "pointer" : 138 }, <"Long"> )>, <"BuiltinType" : ( { - "pointer" : 83 + "pointer" : 139 }, <"LongLong"> )>, <"BuiltinType" : ( { - "pointer" : 84 + "pointer" : 140 }, <"UChar"> )>, <"BuiltinType" : ( { - "pointer" : 85 + "pointer" : 141 }, <"UShort"> )>, <"BuiltinType" : ( { - "pointer" : 86 + "pointer" : 142 }, <"UInt"> )>, <"BuiltinType" : ( { - "pointer" : 87 + "pointer" : 143 }, <"ULong"> )>, <"BuiltinType" : ( { - "pointer" : 88 + "pointer" : 144 }, <"ULongLong"> )>, <"BuiltinType" : ( { - "pointer" : 89 + "pointer" : 145 }, <"Float"> )>, <"BuiltinType" : ( { - "pointer" : 90 + "pointer" : 146 }, <"Double"> )>, <"BuiltinType" : ( { - "pointer" : 91 + "pointer" : 147 }, <"LongDouble"> )>, <"BuiltinType" : ( { - "pointer" : 92 + "pointer" : 148 }, <"Float128"> )>, <"BuiltinType" : ( { - "pointer" : 93 + "pointer" : 149 }, <"Float16"> )>, <"BuiltinType" : ( { - "pointer" : 94 + "pointer" : 150 }, <"ShortAccum"> )>, <"BuiltinType" : ( { - "pointer" : 95 + "pointer" : 151 }, <"Accum"> )>, <"BuiltinType" : ( { - "pointer" : 96 + "pointer" : 152 }, <"LongAccum"> )>, <"BuiltinType" : ( { - "pointer" : 97 + "pointer" : 153 }, <"UShortAccum"> )>, <"BuiltinType" : ( { - "pointer" : 98 + "pointer" : 154 }, <"UAccum"> )>, <"BuiltinType" : ( { - "pointer" : 99 + "pointer" : 155 }, <"ULongAccum"> )>, <"BuiltinType" : ( { - "pointer" : 100 + "pointer" : 156 }, <"ShortFract"> )>, <"BuiltinType" : ( { - "pointer" : 101 + "pointer" : 157 }, <"Fract"> )>, <"BuiltinType" : ( { - "pointer" : 102 + "pointer" : 158 }, <"LongFract"> )>, <"BuiltinType" : ( { - "pointer" : 103 + "pointer" : 159 }, <"UShortFract"> )>, <"BuiltinType" : ( { - "pointer" : 104 + "pointer" : 160 }, <"UFract"> )>, <"BuiltinType" : ( { - "pointer" : 105 + "pointer" : 161 }, <"ULongFract"> )>, <"BuiltinType" : ( { - "pointer" : 106 + "pointer" : 162 }, <"SatShortAccum"> )>, <"BuiltinType" : ( { - "pointer" : 107 + "pointer" : 163 }, <"SatAccum"> )>, <"BuiltinType" : ( { - "pointer" : 108 + "pointer" : 164 }, <"SatLongAccum"> )>, <"BuiltinType" : ( { - "pointer" : 109 + "pointer" : 165 }, <"SatUShortAccum"> )>, <"BuiltinType" : ( { - "pointer" : 110 + "pointer" : 166 }, <"SatUAccum"> )>, <"BuiltinType" : ( { - "pointer" : 111 + "pointer" : 167 }, <"SatULongAccum"> )>, <"BuiltinType" : ( { - "pointer" : 112 + "pointer" : 168 }, <"SatShortFract"> )>, <"BuiltinType" : ( { - "pointer" : 113 + "pointer" : 169 }, <"SatFract"> )>, <"BuiltinType" : ( { - "pointer" : 114 + "pointer" : 170 }, <"SatLongFract"> )>, <"BuiltinType" : ( { - "pointer" : 115 + "pointer" : 171 }, <"SatUShortFract"> )>, <"BuiltinType" : ( { - "pointer" : 116 + "pointer" : 172 }, <"SatUFract"> )>, <"BuiltinType" : ( { - "pointer" : 117 + "pointer" : 173 }, <"SatULongFract"> )>, <"BuiltinType" : ( { - "pointer" : 118 + "pointer" : 174 }, <"Int128"> )>, <"BuiltinType" : ( { - "pointer" : 119 + "pointer" : 175 }, <"UInt128"> )>, <"BuiltinType" : ( { - "pointer" : 120 + "pointer" : 176 }, <"WChar_S"> )>, <"BuiltinType" : ( { - "pointer" : 121 + "pointer" : 177 }, <"Char8"> )>, <"BuiltinType" : ( { - "pointer" : 122 + "pointer" : 178 }, <"Dependent"> )>, <"BuiltinType" : ( { - "pointer" : 123 + "pointer" : 179 }, <"Overload"> )>, <"BuiltinType" : ( { - "pointer" : 124 + "pointer" : 180 }, <"BoundMember"> )>, <"BuiltinType" : ( { - "pointer" : 125 + "pointer" : 181 }, <"PseudoObject"> )>, <"BuiltinType" : ( { - "pointer" : 126 + "pointer" : 182 }, <"UnknownAny"> )>, <"BuiltinType" : ( { - "pointer" : 127 + "pointer" : 183 }, <"ARCUnbridgedCast"> )>, <"BuiltinType" : ( { - "pointer" : 128 + "pointer" : 184 }, <"BuiltinFn"> )>, <"ComplexType" : ( { - "pointer" : 129 + "pointer" : 185 } )>, <"ComplexType" : ( { - "pointer" : 130 + "pointer" : 186 } )>, <"ComplexType" : ( { - "pointer" : 131 + "pointer" : 187 } )>, <"ComplexType" : ( { - "pointer" : 132 + "pointer" : 188 } )>, <"BuiltinType" : ( { - "pointer" : 133 + "pointer" : 189 }, <"ObjCId"> )>, <"BuiltinType" : ( { - "pointer" : 134 + "pointer" : 190 }, <"ObjCClass"> )>, <"BuiltinType" : ( { - "pointer" : 135 + "pointer" : 191 }, <"ObjCSel"> )>, <"PointerType" : ( { - "pointer" : 136 + "pointer" : 192 }, { - "type_ptr" : 77 + "type_ptr" : 108 } )>, <"BuiltinType" : ( { - "pointer" : 137 + "pointer" : 193 }, <"NullPtr"> )>, <"BuiltinType" : ( { - "pointer" : 138 + "pointer" : 194 }, <"Half"> )>, <"BuiltinType" : ( { - "pointer" : 139 + "pointer" : 195 }, <"BFloat16"> )>, <"RecordType" : ( { - "pointer" : 140 + "pointer" : 196 }, - 141 + 197 )>, <"PointerType" : ( { - "pointer" : 142 + "pointer" : 198 }, { "type_ptr" : 10, @@ -2384,10 +3806,10 @@ )>, <"PointerType" : ( { - "pointer" : 143 + "pointer" : 199 }, { - "type_ptr" : 79, + "type_ptr" : 135, "is_const" : true } )>, @@ -2396,22 +3818,22 @@ "pointer" : 31 }, { - "type_ptr" : 79 + "type_ptr" : 135 } )>, <"RecordType" : ( { - "pointer" : 144 + "pointer" : 200 }, - 145 + 201 )>, <"ConstantArrayType" : ( { - "pointer" : 146 + "pointer" : 202 }, { "element_type" : { - "type_ptr" : 144 + "type_ptr" : 200 }, "stride" : 24 }, @@ -2425,7 +3847,7 @@ )>, <"ElaboratedType" : ( { - "pointer" : 147, + "pointer" : 203, "desugared_type" : 8 } )>, @@ -2437,7 +3859,7 @@ )>, <"ElaboratedType" : ( { - "pointer" : 148, + "pointer" : 204, "desugared_type" : 16 } )>, @@ -2454,7 +3876,7 @@ }, { "child_type" : { - "type_ptr" : 147 + "type_ptr" : 203 }, "decl_ptr" : 13 } @@ -2472,14 +3894,14 @@ }, { "child_type" : { - "type_ptr" : 148 + "type_ptr" : 204 }, "decl_ptr" : 20 } )>, <"PointerType" : ( { - "pointer" : 149 + "pointer" : 205 }, { "type_ptr" : 16 @@ -2501,14 +3923,162 @@ )>, <"ElaboratedType" : ( { - "pointer" : 150, + "pointer" : 206, "desugared_type" : 23 } )>, + <"TypedefType" : ( + { + "pointer" : 35, + "desugared_type" : 23 + }, + { + "child_type" : { + "type_ptr" : 206 + }, + "decl_ptr" : 34 + } + )>, + <"PointerType" : ( + { + "pointer" : 207 + }, + { + "type_ptr" : 23 + } + )>, + <"PointerType" : ( + { + "pointer" : 39 + }, + { + "type_ptr" : 35 + } + )>, + <"FunctionProtoType" : ( + { + "pointer" : 208 + }, + { + "return_type" : { + "type_ptr" : 108 + } + }, + { + "params_type" : [ + { + "type_ptr" : 207 + }, + { + "type_ptr" : 10 + } + ] + } + )>, <"FunctionProtoType" : ( { "pointer" : 37 }, + { + "return_type" : { + "type_ptr" : 108 + } + }, + { + "params_type" : [ + { + "type_ptr" : 39 + }, + { + "type_ptr" : 10 + } + ] + } + )>, + <"FunctionProtoType" : ( + { + "pointer" : 209 + }, + { + "return_type" : { + "type_ptr" : 108 + } + }, + { + "params_type" : [ + { + "type_ptr" : 207 + }, + { + "type_ptr" : 205 + } + ] + } + )>, + <"FunctionProtoType" : ( + { + "pointer" : 56 + }, + { + "return_type" : { + "type_ptr" : 108 + } + }, + { + "params_type" : [ + { + "type_ptr" : 39 + }, + { + "type_ptr" : 29 + } + ] + } + )>, + <"FunctionProtoType" : ( + { + "pointer" : 210 + }, + { + "return_type" : { + "type_ptr" : 108 + } + }, + { + "params_type" : [ + { + "type_ptr" : 207 + }, + { + "type_ptr" : 31 + } + ] + } + )>, + <"FunctionProtoType" : ( + { + "pointer" : 74 + }, + { + "return_type" : { + "type_ptr" : 108 + } + }, + { + "params_type" : [ + { + "type_ptr" : 39 + }, + { + "type_ptr" : 31 + } + ] + } + )>, + <"FunctionProtoType" : ( + { + "pointer" : 92 + }, { "return_type" : { "type_ptr" : 10 @@ -2519,74 +4089,110 @@ )>, <"PointerType" : ( { - "pointer" : 151 + "pointer" : 211 }, { "type_ptr" : 31 } )>, - <"TypedefType" : ( + <"PointerType" : ( { - "pointer" : 35, - "desugared_type" : 23 + "pointer" : 212 }, { - "child_type" : { - "type_ptr" : 150 - }, - "decl_ptr" : 34 + "type_ptr" : 208 + } + )>, + <"PointerType" : ( + { + "pointer" : 104 + }, + { + "type_ptr" : 37 + } + )>, + <"PointerType" : ( + { + "pointer" : 213 + }, + { + "type_ptr" : 209 + } + )>, + <"PointerType" : ( + { + "pointer" : 118 + }, + { + "type_ptr" : 56 } )>, <"ConstantArrayType" : ( { - "pointer" : 74 + "pointer" : 131 }, { "element_type" : { - "type_ptr" : 79 + "type_ptr" : 135 }, "stride" : 1 }, 9 )>, + <"PointerType" : ( + { + "pointer" : 214 + }, + { + "type_ptr" : 210 + } + )>, + <"PointerType" : ( + { + "pointer" : 126 + }, + { + "type_ptr" : 74 + } + )>, <"ObjCObjectType" : ( { - "pointer" : 152 + "pointer" : 215 }, { - "base_type" : 133 + "base_type" : 189 } )>, <"ObjCObjectPointerType" : ( { - "pointer" : 153 + "pointer" : 216 }, { - "type_ptr" : 152 + "type_ptr" : 215 } )>, <"TypedefType" : ( { - "pointer" : 154, - "desugared_type" : 153 + "pointer" : 217, + "desugared_type" : 216 }, { "child_type" : { - "type_ptr" : 153 + "type_ptr" : 216 }, - "decl_ptr" : 155 + "decl_ptr" : 218 } )>, <"TypedefType" : ( { - "pointer" : 76, - "desugared_type" : 153 + "pointer" : 133, + "desugared_type" : 216 }, { "child_type" : { - "type_ptr" : 154 + "type_ptr" : 217 }, - "decl_ptr" : 75 + "decl_ptr" : 132 } )>, <"NoneType" : ( From 6863368d68c778b31c1169f89349f176664df2f5 Mon Sep 17 00:00:00 2001 From: cedretaber Date: Wed, 12 Oct 2022 17:16:29 +0900 Subject: [PATCH 6/6] Enhance record, union and enum. --- sample/types/discriminated_union2.c | 29 + sample/types/discriminated_union2.c.yojson | 3748 ++++++++++++++++++++ sample/types/linked_list.c | 10 + sample/types/linked_list.c.yojson | 1350 +++++++ src/lib/ast.ml | 39 +- src/lib/ast.mli | 11 +- src/lib/ast2cabs.ml | 2 + src/lib/yojson2ast.ml | 34 +- 8 files changed, 5210 insertions(+), 13 deletions(-) create mode 100644 sample/types/discriminated_union2.c create mode 100644 sample/types/discriminated_union2.c.yojson create mode 100644 sample/types/linked_list.c create mode 100644 sample/types/linked_list.c.yojson diff --git a/sample/types/discriminated_union2.c b/sample/types/discriminated_union2.c new file mode 100644 index 0000000..7353661 --- /dev/null +++ b/sample/types/discriminated_union2.c @@ -0,0 +1,29 @@ +typedef struct { + enum { + INT, + THREE, + STRING + } tag; + + union { + int i; + struct { + int a : 12, b : 12, c : 12; + }; + char *str; + }; +} X; + +int main(void) { + X x = { INT, 0 }; + + x.tag = THREE; + x.a = 1; + x.b = 2; + x.c = 3; + + x.tag = STRING; + x.str = "hogehoge"; + + X y = { .tag = STRING, .str = "fugafuga" }; +} diff --git a/sample/types/discriminated_union2.c.yojson b/sample/types/discriminated_union2.c.yojson new file mode 100644 index 0000000..f4e3e9e --- /dev/null +++ b/sample/types/discriminated_union2.c.yojson @@ -0,0 +1,3748 @@ +<"TranslationUnitDecl" : ( + { + "pointer" : 1, + "source_range" : ( + { + }, + { + } + ) + }, + [ + <"TypedefDecl" : ( + { + "pointer" : 2, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__int128_t", + "qual_name" : [ + "__int128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 3, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__uint128_t", + "qual_name" : [ + "__uint128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 4, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__NSConstantString", + "qual_name" : [ + "__NSConstantString" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 5, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_ms_va_list", + "qual_name" : [ + "__builtin_ms_va_list" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 6, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_va_list", + "qual_name" : [ + "__builtin_va_list" + ] + }, + 0, + { + } + )>, + <"RecordDecl" : ( + { + "pointer" : 7, + "parent_pointer" : 1, + "source_range" : ( + { + "file" : "sample/types/discriminated_union2.c", + "line" : 1, + "column" : 9 + }, + { + "line" : 15, + "column" : 1 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "X" + ] + }, + 8, + [ + <"EnumDecl" : ( + { + "pointer" : 9, + "source_range" : ( + { + "line" : 2, + "column" : 3 + }, + { + "line" : 6, + "column" : 3 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "anonymous_enum_sample/types/discriminated_union2.c:2:3", + "X" + ] + }, + 10, + [ + <"EnumConstantDecl" : ( + { + "pointer" : 11, + "source_range" : ( + { + "line" : 3, + "column" : 5 + }, + { + "column" : 5 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "INT", + "qual_name" : [ + "INT", + "anonymous_enum_sample/types/discriminated_union2.c:2:3", + "X" + ] + }, + { + "type_ptr" : 12 + }, + { + } + )>, + <"EnumConstantDecl" : ( + { + "pointer" : 13, + "source_range" : ( + { + "line" : 4, + "column" : 5 + }, + { + "column" : 5 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "THREE", + "qual_name" : [ + "THREE", + "anonymous_enum_sample/types/discriminated_union2.c:2:3", + "X" + ] + }, + { + "type_ptr" : 12 + }, + { + } + )>, + <"EnumConstantDecl" : ( + { + "pointer" : 14, + "source_range" : ( + { + "line" : 5, + "column" : 5 + }, + { + "column" : 5 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "STRING", + "qual_name" : [ + "STRING", + "anonymous_enum_sample/types/discriminated_union2.c:2:3", + "X" + ] + }, + { + "type_ptr" : 12 + }, + { + } + )> + ], + { + }, + <"TTK_Enum">, + { + } + )>, + <"FieldDecl" : ( + { + "pointer" : 15, + "parent_pointer" : 7, + "source_range" : ( + { + "line" : 2, + "column" : 3 + }, + { + "line" : 6, + "column" : 5 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "tag", + "qual_name" : [ + "tag", + "X" + ] + }, + { + "type_ptr" : 16 + }, + { + } + )>, + <"RecordDecl" : ( + { + "pointer" : 17, + "parent_pointer" : 7, + "source_range" : ( + { + "line" : 8, + "column" : 3 + }, + { + "line" : 14, + "column" : 3 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + 18, + [ + <"FieldDecl" : ( + { + "pointer" : 19, + "parent_pointer" : 17, + "source_range" : ( + { + "line" : 9, + "column" : 5 + }, + { + "column" : 9 + } + ), + "access" : <"Public"> + }, + { + "name" : "i", + "qual_name" : [ + "i", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + { + "type_ptr" : 12 + }, + { + } + )>, + <"RecordDecl" : ( + { + "pointer" : 20, + "parent_pointer" : 17, + "source_range" : ( + { + "line" : 10, + "column" : 5 + }, + { + "line" : 12, + "column" : 5 + } + ) + }, + { + "name" : "", + "qual_name" : [ + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + 21, + [ + <"FieldDecl" : ( + { + "pointer" : 22, + "parent_pointer" : 20, + "source_range" : ( + { + "line" : 11, + "column" : 7 + }, + { + "column" : 15 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "a", + "qual_name" : [ + "a", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + { + "type_ptr" : 12 + }, + { + "bit_width_expr" : <"ConstantExpr" : ( + { + "pointer" : 23, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 24, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "12" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + } + )> + } + )>, + <"FieldDecl" : ( + { + "pointer" : 25, + "parent_pointer" : 20, + "source_range" : ( + { + "column" : 7 + }, + { + "column" : 23 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "b", + "qual_name" : [ + "b", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + { + "type_ptr" : 12 + }, + { + "bit_width_expr" : <"ConstantExpr" : ( + { + "pointer" : 26, + "source_range" : ( + { + "column" : 23 + }, + { + "column" : 23 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 27, + "source_range" : ( + { + "column" : 23 + }, + { + "column" : 23 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "12" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + } + )> + } + )>, + <"FieldDecl" : ( + { + "pointer" : 28, + "parent_pointer" : 20, + "source_range" : ( + { + "column" : 7 + }, + { + "column" : 31 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "c", + "qual_name" : [ + "c", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + { + "type_ptr" : 12 + }, + { + "bit_width_expr" : <"ConstantExpr" : ( + { + "pointer" : 29, + "source_range" : ( + { + "column" : 31 + }, + { + "column" : 31 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 30, + "source_range" : ( + { + "column" : 31 + }, + { + "column" : 31 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "12" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + } + )> + } + )> + ], + { + }, + <"TTK_Struct">, + { + "definition_ptr" : 20, + "is_complete_definition" : true + } + )>, + <"FieldDecl" : ( + { + "pointer" : 31, + "parent_pointer" : 17, + "source_range" : ( + { + "line" : 10, + "column" : 5 + }, + { + "column" : 5 + } + ), + "is_implicit" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + { + "type_ptr" : 21 + }, + { + } + )>, + <"IndirectFieldDecl" : ( + { + "pointer" : 32, + "source_range" : ( + { + "line" : 11, + "column" : 11 + }, + { + "column" : 11 + } + ), + "is_implicit" : true + }, + { + "name" : "a", + "qual_name" : [ + "a", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + { + "type_ptr" : 12 + }, + [ + { + "kind" : <"Field">, + "decl_pointer" : 31, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 21 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 22, + "name" : { + "name" : "a", + "qual_name" : [ + "a", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + ] + )>, + <"IndirectFieldDecl" : ( + { + "pointer" : 33, + "source_range" : ( + { + "column" : 19 + }, + { + "column" : 19 + } + ), + "is_implicit" : true + }, + { + "name" : "b", + "qual_name" : [ + "b", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + { + "type_ptr" : 12 + }, + [ + { + "kind" : <"Field">, + "decl_pointer" : 31, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 21 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 25, + "name" : { + "name" : "b", + "qual_name" : [ + "b", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + ] + )>, + <"IndirectFieldDecl" : ( + { + "pointer" : 34, + "source_range" : ( + { + "column" : 27 + }, + { + "column" : 27 + } + ), + "is_implicit" : true + }, + { + "name" : "c", + "qual_name" : [ + "c", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + { + "type_ptr" : 12 + }, + [ + { + "kind" : <"Field">, + "decl_pointer" : 31, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 21 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 28, + "name" : { + "name" : "c", + "qual_name" : [ + "c", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + ] + )>, + <"FieldDecl" : ( + { + "pointer" : 35, + "parent_pointer" : 17, + "source_range" : ( + { + "line" : 13, + "column" : 5 + }, + { + "column" : 11 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "str", + "qual_name" : [ + "str", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + { + "type_ptr" : 36 + }, + { + } + )> + ], + { + }, + <"TTK_Union">, + { + "definition_ptr" : 17, + "is_complete_definition" : true + } + )>, + <"FieldDecl" : ( + { + "pointer" : 37, + "parent_pointer" : 7, + "source_range" : ( + { + "line" : 8, + "column" : 3 + }, + { + "column" : 3 + } + ), + "is_implicit" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + { + "type_ptr" : 18 + }, + { + } + )>, + <"IndirectFieldDecl" : ( + { + "pointer" : 38, + "source_range" : ( + { + "line" : 9, + "column" : 9 + }, + { + "column" : 9 + } + ), + "is_implicit" : true + }, + { + "name" : "i", + "qual_name" : [ + "i", + "X" + ] + }, + { + "type_ptr" : 12 + }, + [ + { + "kind" : <"Field">, + "decl_pointer" : 37, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 19, + "name" : { + "name" : "i", + "qual_name" : [ + "i", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + ] + )>, + <"IndirectFieldDecl" : ( + { + "pointer" : 39, + "source_range" : ( + { + "line" : 11, + "column" : 11 + }, + { + "column" : 11 + } + ), + "is_implicit" : true + }, + { + "name" : "a", + "qual_name" : [ + "a", + "X" + ] + }, + { + "type_ptr" : 12 + }, + [ + { + "kind" : <"Field">, + "decl_pointer" : 37, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 31, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 21 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 22, + "name" : { + "name" : "a", + "qual_name" : [ + "a", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + ] + )>, + <"IndirectFieldDecl" : ( + { + "pointer" : 40, + "source_range" : ( + { + "column" : 19 + }, + { + "column" : 19 + } + ), + "is_implicit" : true + }, + { + "name" : "b", + "qual_name" : [ + "b", + "X" + ] + }, + { + "type_ptr" : 12 + }, + [ + { + "kind" : <"Field">, + "decl_pointer" : 37, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 31, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 21 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 25, + "name" : { + "name" : "b", + "qual_name" : [ + "b", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + ] + )>, + <"IndirectFieldDecl" : ( + { + "pointer" : 41, + "source_range" : ( + { + "column" : 27 + }, + { + "column" : 27 + } + ), + "is_implicit" : true + }, + { + "name" : "c", + "qual_name" : [ + "c", + "X" + ] + }, + { + "type_ptr" : 12 + }, + [ + { + "kind" : <"Field">, + "decl_pointer" : 37, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 31, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 21 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 28, + "name" : { + "name" : "c", + "qual_name" : [ + "c", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + ] + )>, + <"IndirectFieldDecl" : ( + { + "pointer" : 42, + "source_range" : ( + { + "line" : 13, + "column" : 11 + }, + { + "column" : 11 + } + ), + "is_implicit" : true + }, + { + "name" : "str", + "qual_name" : [ + "str", + "X" + ] + }, + { + "type_ptr" : 36 + }, + [ + { + "kind" : <"Field">, + "decl_pointer" : 37, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + }, + { + "kind" : <"Field">, + "decl_pointer" : 35, + "name" : { + "name" : "str", + "qual_name" : [ + "str", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 36 + } + } + ] + )> + ], + { + }, + <"TTK_Struct">, + { + "definition_ptr" : 7, + "is_complete_definition" : true + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 43, + "source_range" : ( + { + "line" : 1, + "column" : 1 + }, + { + "line" : 15, + "column" : 3 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "X", + "qual_name" : [ + "X" + ] + }, + 44, + { + } + )>, + <"FunctionDecl" : ( + { + "pointer" : 45, + "source_range" : ( + { + "line" : 17, + "column" : 1 + }, + { + "line" : 29, + "column" : 1 + } + ) + }, + { + "name" : "main", + "qual_name" : [ + "main" + ] + }, + { + "type_ptr" : 46 + }, + { + "decl_ptr_with_body" : 45, + "body" : <"CompoundStmt" : ( + { + "pointer" : 47, + "source_range" : ( + { + "line" : 17, + "column" : 16 + }, + { + "line" : 29, + "column" : 1 + } + ) + }, + [ + <"DeclStmt" : ( + { + "pointer" : 48, + "source_range" : ( + { + "line" : 18, + "column" : 3 + }, + { + "column" : 19 + } + ) + }, + [ + <"InitListExpr" : ( + { + "pointer" : 49, + "source_range" : ( + { + "column" : 9 + }, + { + "column" : 18 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 50, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 51, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 11, + "name" : { + "name" : "INT", + "qual_name" : [ + "INT", + "anonymous_enum_sample/types/discriminated_union2.c:2:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 16 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )>, + <"InitListExpr" : ( + { + "pointer" : 52, + "source_range" : ( + { + "column" : 16 + }, + { + "column" : 16 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 53, + "source_range" : ( + { + "column" : 16 + }, + { + "column" : 16 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "0" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 44 + } + } + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 54, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 18 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + { + "type_ptr" : 44 + }, + { + "init_expr" : <"InitListExpr" : ( + { + "pointer" : 49, + "source_range" : ( + { + "column" : 9 + }, + { + "column" : 18 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 50, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 51, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 11, + "name" : { + "name" : "INT", + "qual_name" : [ + "INT", + "anonymous_enum_sample/types/discriminated_union2.c:2:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 16 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )>, + <"InitListExpr" : ( + { + "pointer" : 52, + "source_range" : ( + { + "column" : 16 + }, + { + "column" : 16 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 53, + "source_range" : ( + { + "column" : 16 + }, + { + "column" : 16 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "0" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 44 + } + } + )> + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 55, + "source_range" : ( + { + "line" : 20, + "column" : 3 + }, + { + "column" : 11 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 56, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 57, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 44 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 54, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 44 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 16 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 15, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 16 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 58, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 59, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 13, + "name" : { + "name" : "THREE", + "qual_name" : [ + "THREE", + "anonymous_enum_sample/types/discriminated_union2.c:2:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 16 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 16 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 60, + "source_range" : ( + { + "line" : 21, + "column" : 3 + }, + { + "column" : 9 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 61, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 62, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 63, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 64, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 44 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 54, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 44 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 37, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 21 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 31, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 21 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + }, + "value_kind" : <"LValue">, + "object_kind" : <"BitField"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "a", + "qual_name" : [ + "a", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 22, + "name" : { + "name" : "a", + "qual_name" : [ + "a", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 65, + "source_range" : ( + { + "column" : 9 + }, + { + "column" : 9 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "1" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 66, + "source_range" : ( + { + "line" : 22, + "column" : 3 + }, + { + "column" : 9 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 67, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 68, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 69, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 70, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 44 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 54, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 44 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 37, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 21 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 31, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 21 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + }, + "value_kind" : <"LValue">, + "object_kind" : <"BitField"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "b", + "qual_name" : [ + "b", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 25, + "name" : { + "name" : "b", + "qual_name" : [ + "b", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 71, + "source_range" : ( + { + "column" : 9 + }, + { + "column" : 9 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "2" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 72, + "source_range" : ( + { + "line" : 23, + "column" : 3 + }, + { + "column" : 9 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 73, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 74, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 75, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 76, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 44 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 54, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 44 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 37, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 21 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 31, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 21 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + }, + "value_kind" : <"LValue">, + "object_kind" : <"BitField"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "c", + "qual_name" : [ + "c", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 28, + "name" : { + "name" : "c", + "qual_name" : [ + "c", + "anonymous_struct_sample/types/discriminated_union2.c:10:5", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )>, + <"IntegerLiteral" : ( + { + "pointer" : 77, + "source_range" : ( + { + "column" : 9 + }, + { + "column" : 9 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "3" + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 78, + "source_range" : ( + { + "line" : 25, + "column" : 3 + }, + { + "column" : 11 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 79, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 80, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 44 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 54, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 44 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 16 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 15, + "name" : { + "name" : "tag", + "qual_name" : [ + "tag", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 16 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 81, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 82, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 14, + "name" : { + "name" : "STRING", + "qual_name" : [ + "STRING", + "anonymous_enum_sample/types/discriminated_union2.c:2:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 16 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 16 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"BinaryOperator" : ( + { + "pointer" : 83, + "source_range" : ( + { + "line" : 26, + "column" : 3 + }, + { + "column" : 11 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 84, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 85, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 5 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 86, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 44 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 54, + "name" : { + "name" : "x", + "qual_name" : [ + "x" + ] + }, + "qual_type" : { + "type_ptr" : 44 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 37, + "name" : { + "name" : "__anon_field_1", + "qual_name" : [ + "", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 18 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 36 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "str", + "qual_name" : [ + "str", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 35, + "name" : { + "name" : "str", + "qual_name" : [ + "str", + "anonymous_union_sample/types/discriminated_union2.c:8:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 36 + } + } + } + )>, + <"ImplicitCastExpr" : ( + { + "pointer" : 87, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + <"StringLiteral" : ( + { + "pointer" : 88, + "source_range" : ( + { + "column" : 11 + }, + { + "column" : 11 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 89 + }, + "value_kind" : <"LValue"> + }, + [ + "hogehoge" + ] + )> + ], + { + "qual_type" : { + "type_ptr" : 36 + } + }, + { + "cast_kind" : <"ArrayToPointerDecay">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 36 + } + }, + { + "kind" : <"Assign"> + } + )>, + <"DeclStmt" : ( + { + "pointer" : 90, + "source_range" : ( + { + "line" : 28, + "column" : 3 + }, + { + "column" : 45 + } + ) + }, + [ + <"InitListExpr" : ( + { + "pointer" : 91, + "source_range" : ( + { + "column" : 9 + }, + { + "column" : 44 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 92, + "source_range" : ( + { + "column" : 18 + }, + { + "column" : 18 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 93, + "source_range" : ( + { + "column" : 18 + }, + { + "column" : 18 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 14, + "name" : { + "name" : "STRING", + "qual_name" : [ + "STRING", + "anonymous_enum_sample/types/discriminated_union2.c:2:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 16 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )>, + <"InitListExpr" : ( + { + "pointer" : 94, + "source_range" : ( + { + "column" : 26 + }, + { + "column" : 33 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 95, + "source_range" : ( + { + "column" : 33 + }, + { + "column" : 33 + } + ) + }, + [ + <"StringLiteral" : ( + { + "pointer" : 96, + "source_range" : ( + { + "column" : 33 + }, + { + "column" : 33 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 89 + }, + "value_kind" : <"LValue"> + }, + [ + "fugafuga" + ] + )> + ], + { + "qual_type" : { + "type_ptr" : 36 + } + }, + { + "cast_kind" : <"ArrayToPointerDecay">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 44 + } + } + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 97, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 44 + } + ) + }, + { + "name" : "y", + "qual_name" : [ + "y" + ] + }, + { + "type_ptr" : 44 + }, + { + "init_expr" : <"InitListExpr" : ( + { + "pointer" : 91, + "source_range" : ( + { + "column" : 9 + }, + { + "column" : 44 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 92, + "source_range" : ( + { + "column" : 18 + }, + { + "column" : 18 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 93, + "source_range" : ( + { + "column" : 18 + }, + { + "column" : 18 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "decl_ref" : { + "kind" : <"EnumConstant">, + "decl_pointer" : 14, + "name" : { + "name" : "STRING", + "qual_name" : [ + "STRING", + "anonymous_enum_sample/types/discriminated_union2.c:2:3", + "X" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 16 + } + }, + { + "cast_kind" : <"IntegralCast">, + "base_path" : [ + ] + }, + false + )>, + <"InitListExpr" : ( + { + "pointer" : 94, + "source_range" : ( + { + "column" : 26 + }, + { + "column" : 33 + } + ) + }, + [ + <"ImplicitCastExpr" : ( + { + "pointer" : 95, + "source_range" : ( + { + "column" : 33 + }, + { + "column" : 33 + } + ) + }, + [ + <"StringLiteral" : ( + { + "pointer" : 96, + "source_range" : ( + { + "column" : 33 + }, + { + "column" : 33 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 89 + }, + "value_kind" : <"LValue"> + }, + [ + "fugafuga" + ] + )> + ], + { + "qual_type" : { + "type_ptr" : 36 + } + }, + { + "cast_kind" : <"ArrayToPointerDecay">, + "base_path" : [ + ] + }, + false + )> + ], + { + "qual_type" : { + "type_ptr" : 18 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 44 + } + } + )> + } + )> + ] + )> + ] + )> + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 98, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "instancetype", + "qual_name" : [ + "instancetype" + ] + }, + 99, + { + } + )> + ], + { + }, + { + "input_path" : "sample/types/discriminated_union2.c", + "input_kind" : <"IK_C">, + "integer_type_widths" : { + "char_type" : 8, + "short_type" : 16, + "int_type" : 32, + "long_type" : 64, + "longlong_type" : 64 + }, + "types" : [ + <"BuiltinType" : ( + { + "pointer" : 100 + }, + <"Void"> + )>, + <"BuiltinType" : ( + { + "pointer" : 101 + }, + <"Bool"> + )>, + <"BuiltinType" : ( + { + "pointer" : 102 + }, + <"Char_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 103 + }, + <"SChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 104 + }, + <"Short"> + )>, + <"BuiltinType" : ( + { + "pointer" : 12 + }, + <"Int"> + )>, + <"BuiltinType" : ( + { + "pointer" : 105 + }, + <"Long"> + )>, + <"BuiltinType" : ( + { + "pointer" : 106 + }, + <"LongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 107 + }, + <"UChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 108 + }, + <"UShort"> + )>, + <"BuiltinType" : ( + { + "pointer" : 109 + }, + <"UInt"> + )>, + <"BuiltinType" : ( + { + "pointer" : 110 + }, + <"ULong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 111 + }, + <"ULongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 112 + }, + <"Float"> + )>, + <"BuiltinType" : ( + { + "pointer" : 113 + }, + <"Double"> + )>, + <"BuiltinType" : ( + { + "pointer" : 114 + }, + <"LongDouble"> + )>, + <"BuiltinType" : ( + { + "pointer" : 115 + }, + <"Float128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 116 + }, + <"Float16"> + )>, + <"BuiltinType" : ( + { + "pointer" : 117 + }, + <"ShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 118 + }, + <"Accum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 119 + }, + <"LongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 120 + }, + <"UShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 121 + }, + <"UAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 122 + }, + <"ULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 123 + }, + <"ShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 124 + }, + <"Fract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 125 + }, + <"LongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 126 + }, + <"UShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 127 + }, + <"UFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 128 + }, + <"ULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 129 + }, + <"SatShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 130 + }, + <"SatAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 131 + }, + <"SatLongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 132 + }, + <"SatUShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 133 + }, + <"SatUAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 134 + }, + <"SatULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 135 + }, + <"SatShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 136 + }, + <"SatFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 137 + }, + <"SatLongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 138 + }, + <"SatUShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 139 + }, + <"SatUFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 140 + }, + <"SatULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 141 + }, + <"Int128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 142 + }, + <"UInt128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 143 + }, + <"WChar_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 144 + }, + <"Char8"> + )>, + <"BuiltinType" : ( + { + "pointer" : 145 + }, + <"Dependent"> + )>, + <"BuiltinType" : ( + { + "pointer" : 146 + }, + <"Overload"> + )>, + <"BuiltinType" : ( + { + "pointer" : 147 + }, + <"BoundMember"> + )>, + <"BuiltinType" : ( + { + "pointer" : 148 + }, + <"PseudoObject"> + )>, + <"BuiltinType" : ( + { + "pointer" : 149 + }, + <"UnknownAny"> + )>, + <"BuiltinType" : ( + { + "pointer" : 150 + }, + <"ARCUnbridgedCast"> + )>, + <"BuiltinType" : ( + { + "pointer" : 151 + }, + <"BuiltinFn"> + )>, + <"ComplexType" : ( + { + "pointer" : 152 + } + )>, + <"ComplexType" : ( + { + "pointer" : 153 + } + )>, + <"ComplexType" : ( + { + "pointer" : 154 + } + )>, + <"ComplexType" : ( + { + "pointer" : 155 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 156 + }, + <"ObjCId"> + )>, + <"BuiltinType" : ( + { + "pointer" : 157 + }, + <"ObjCClass"> + )>, + <"BuiltinType" : ( + { + "pointer" : 158 + }, + <"ObjCSel"> + )>, + <"PointerType" : ( + { + "pointer" : 159 + }, + { + "type_ptr" : 100 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 160 + }, + <"NullPtr"> + )>, + <"BuiltinType" : ( + { + "pointer" : 161 + }, + <"Half"> + )>, + <"BuiltinType" : ( + { + "pointer" : 162 + }, + <"BFloat16"> + )>, + <"RecordType" : ( + { + "pointer" : 163 + }, + 164 + )>, + <"PointerType" : ( + { + "pointer" : 165 + }, + { + "type_ptr" : 12, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 166 + }, + { + "type_ptr" : 102, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 36 + }, + { + "type_ptr" : 102 + } + )>, + <"RecordType" : ( + { + "pointer" : 167 + }, + 168 + )>, + <"ConstantArrayType" : ( + { + "pointer" : 169 + }, + { + "element_type" : { + "type_ptr" : 167 + }, + "stride" : 24 + }, + 1 + )>, + <"RecordType" : ( + { + "pointer" : 8 + }, + 7 + )>, + <"EnumType" : ( + { + "pointer" : 10 + }, + 9 + )>, + <"ElaboratedType" : ( + { + "pointer" : 16, + "desugared_type" : 10 + } + )>, + <"RecordType" : ( + { + "pointer" : 18 + }, + 17 + )>, + <"RecordType" : ( + { + "pointer" : 21 + }, + 20 + )>, + <"ElaboratedType" : ( + { + "pointer" : 170, + "desugared_type" : 21 + } + )>, + <"ElaboratedType" : ( + { + "pointer" : 171, + "desugared_type" : 18 + } + )>, + <"ElaboratedType" : ( + { + "pointer" : 172, + "desugared_type" : 8 + } + )>, + <"FunctionProtoType" : ( + { + "pointer" : 46 + }, + { + "return_type" : { + "type_ptr" : 12 + } + }, + { + } + )>, + <"PointerType" : ( + { + "pointer" : 173 + }, + { + "type_ptr" : 36 + } + )>, + <"TypedefType" : ( + { + "pointer" : 44, + "desugared_type" : 8 + }, + { + "child_type" : { + "type_ptr" : 172 + }, + "decl_ptr" : 43 + } + )>, + <"ConstantArrayType" : ( + { + "pointer" : 89 + }, + { + "element_type" : { + "type_ptr" : 102 + }, + "stride" : 1 + }, + 9 + )>, + <"ObjCObjectType" : ( + { + "pointer" : 174 + }, + { + "base_type" : 156 + } + )>, + <"ObjCObjectPointerType" : ( + { + "pointer" : 175 + }, + { + "type_ptr" : 174 + } + )>, + <"TypedefType" : ( + { + "pointer" : 176, + "desugared_type" : 175 + }, + { + "child_type" : { + "type_ptr" : 175 + }, + "decl_ptr" : 177 + } + )>, + <"TypedefType" : ( + { + "pointer" : 99, + "desugared_type" : 175 + }, + { + "child_type" : { + "type_ptr" : 176 + }, + "decl_ptr" : 98 + } + )>, + <"NoneType" : ( + { + "pointer" : 0 + } + )> + ] + } +)> diff --git a/sample/types/linked_list.c b/sample/types/linked_list.c new file mode 100644 index 0000000..6ad24d8 --- /dev/null +++ b/sample/types/linked_list.c @@ -0,0 +1,10 @@ + +typedef struct list { + int value; + struct list *next; +} List; + +int main(void) { + List l1 = { 42 }, l2 = { 99 }; + l1.next = &l2; +} diff --git a/sample/types/linked_list.c.yojson b/sample/types/linked_list.c.yojson new file mode 100644 index 0000000..4825a23 --- /dev/null +++ b/sample/types/linked_list.c.yojson @@ -0,0 +1,1350 @@ +<"TranslationUnitDecl" : ( + { + "pointer" : 1, + "source_range" : ( + { + }, + { + } + ) + }, + [ + <"TypedefDecl" : ( + { + "pointer" : 2, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__int128_t", + "qual_name" : [ + "__int128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 3, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__uint128_t", + "qual_name" : [ + "__uint128_t" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 4, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__NSConstantString", + "qual_name" : [ + "__NSConstantString" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 5, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_ms_va_list", + "qual_name" : [ + "__builtin_ms_va_list" + ] + }, + 0, + { + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 6, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "__builtin_va_list", + "qual_name" : [ + "__builtin_va_list" + ] + }, + 0, + { + } + )>, + <"RecordDecl" : ( + { + "pointer" : 7, + "parent_pointer" : 1, + "source_range" : ( + { + "file" : "sample/types/linked_list.c", + "line" : 2, + "column" : 9 + }, + { + "line" : 5, + "column" : 1 + } + ) + }, + { + "name" : "list", + "qual_name" : [ + "list" + ] + }, + 8, + [ + <"FieldDecl" : ( + { + "pointer" : 9, + "parent_pointer" : 7, + "source_range" : ( + { + "line" : 3, + "column" : 3 + }, + { + "column" : 7 + } + ), + "access" : <"Public"> + }, + { + "name" : "value", + "qual_name" : [ + "value", + "list" + ] + }, + { + "type_ptr" : 10 + }, + { + } + )>, + <"FieldDecl" : ( + { + "pointer" : 11, + "parent_pointer" : 7, + "source_range" : ( + { + "line" : 4, + "column" : 3 + }, + { + "column" : 16 + } + ), + "is_this_declaration_referenced" : true, + "access" : <"Public"> + }, + { + "name" : "next", + "qual_name" : [ + "next", + "list" + ] + }, + { + "type_ptr" : 12 + }, + { + } + )> + ], + { + }, + <"TTK_Struct">, + { + "definition_ptr" : 7, + "is_complete_definition" : true + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 13, + "source_range" : ( + { + "line" : 2, + "column" : 1 + }, + { + "line" : 5, + "column" : 3 + } + ), + "is_this_declaration_referenced" : true + }, + { + "name" : "List", + "qual_name" : [ + "List" + ] + }, + 14, + { + } + )>, + <"FunctionDecl" : ( + { + "pointer" : 15, + "source_range" : ( + { + "line" : 7, + "column" : 1 + }, + { + "line" : 10, + "column" : 1 + } + ) + }, + { + "name" : "main", + "qual_name" : [ + "main" + ] + }, + { + "type_ptr" : 16 + }, + { + "decl_ptr_with_body" : 15, + "body" : <"CompoundStmt" : ( + { + "pointer" : 17, + "source_range" : ( + { + "line" : 7, + "column" : 16 + }, + { + "line" : 10, + "column" : 1 + } + ) + }, + [ + <"DeclStmt" : ( + { + "pointer" : 18, + "source_range" : ( + { + "line" : 8, + "column" : 3 + }, + { + "column" : 32 + } + ) + }, + [ + <"InitListExpr" : ( + { + "pointer" : 19, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 18 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 20, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "42" + } + )>, + <"ImplicitValueInitExpr" : ( + { + "pointer" : 21, + "source_range" : ( + { + }, + { + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + } + )>, + <"InitListExpr" : ( + { + "pointer" : 22, + "source_range" : ( + { + "column" : 26 + }, + { + "column" : 31 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 23, + "source_range" : ( + { + "column" : 28 + }, + { + "column" : 28 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "99" + } + )>, + <"ImplicitValueInitExpr" : ( + { + "pointer" : 24, + "source_range" : ( + { + }, + { + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + } + )> + ], + [ + <"VarDecl" : ( + { + "pointer" : 25, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 18 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "l1", + "qual_name" : [ + "l1" + ] + }, + { + "type_ptr" : 14 + }, + { + "init_expr" : <"InitListExpr" : ( + { + "pointer" : 19, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 18 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 20, + "source_range" : ( + { + "column" : 15 + }, + { + "column" : 15 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "42" + } + )>, + <"ImplicitValueInitExpr" : ( + { + "pointer" : 21, + "source_range" : ( + { + }, + { + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + } + )> + } + )>, + <"VarDecl" : ( + { + "pointer" : 26, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 31 + } + ), + "is_used" : true, + "is_this_declaration_referenced" : true + }, + { + "name" : "l2", + "qual_name" : [ + "l2" + ] + }, + { + "type_ptr" : 14 + }, + { + "init_expr" : <"InitListExpr" : ( + { + "pointer" : 22, + "source_range" : ( + { + "column" : 26 + }, + { + "column" : 31 + } + ) + }, + [ + <"IntegerLiteral" : ( + { + "pointer" : 23, + "source_range" : ( + { + "column" : 28 + }, + { + "column" : 28 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 10 + } + }, + { + "is_signed" : true, + "bitwidth" : 32, + "value" : "99" + } + )>, + <"ImplicitValueInitExpr" : ( + { + "pointer" : 24, + "source_range" : ( + { + }, + { + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 12 + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 14 + } + } + )> + } + )> + ] + )>, + <"BinaryOperator" : ( + { + "pointer" : 27, + "source_range" : ( + { + "line" : 9, + "column" : 3 + }, + { + "column" : 14 + } + ) + }, + [ + <"MemberExpr" : ( + { + "pointer" : 28, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 6 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 29, + "source_range" : ( + { + "column" : 3 + }, + { + "column" : 3 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 14 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 25, + "name" : { + "name" : "l1", + "qual_name" : [ + "l1" + ] + }, + "qual_type" : { + "type_ptr" : 14 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + }, + "value_kind" : <"LValue"> + }, + { + "performs_virtual_dispatch" : true, + "name" : { + "name" : "next", + "qual_name" : [ + "next", + "list" + ] + }, + "decl_ref" : { + "kind" : <"Field">, + "decl_pointer" : 11, + "name" : { + "name" : "next", + "qual_name" : [ + "next", + "list" + ] + }, + "qual_type" : { + "type_ptr" : 12 + } + } + } + )>, + <"UnaryOperator" : ( + { + "pointer" : 30, + "source_range" : ( + { + "column" : 13 + }, + { + "column" : 14 + } + ) + }, + [ + <"DeclRefExpr" : ( + { + "pointer" : 31, + "source_range" : ( + { + "column" : 14 + }, + { + "column" : 14 + } + ) + }, + [ + ], + { + "qual_type" : { + "type_ptr" : 14 + }, + "value_kind" : <"LValue"> + }, + { + "decl_ref" : { + "kind" : <"Var">, + "decl_pointer" : 26, + "name" : { + "name" : "l2", + "qual_name" : [ + "l2" + ] + }, + "qual_type" : { + "type_ptr" : 14 + } + } + } + )> + ], + { + "qual_type" : { + "type_ptr" : 32 + } + }, + { + "kind" : <"AddrOf"> + } + )> + ], + { + "qual_type" : { + "type_ptr" : 12 + } + }, + { + "kind" : <"Assign"> + } + )> + ] + )> + } + )>, + <"TypedefDecl" : ( + { + "pointer" : 33, + "source_range" : ( + { + }, + { + } + ), + "is_implicit" : true + }, + { + "name" : "instancetype", + "qual_name" : [ + "instancetype" + ] + }, + 34, + { + } + )> + ], + { + }, + { + "input_path" : "sample/types/linked_list.c", + "input_kind" : <"IK_C">, + "integer_type_widths" : { + "char_type" : 8, + "short_type" : 16, + "int_type" : 32, + "long_type" : 64, + "longlong_type" : 64 + }, + "types" : [ + <"BuiltinType" : ( + { + "pointer" : 35 + }, + <"Void"> + )>, + <"BuiltinType" : ( + { + "pointer" : 36 + }, + <"Bool"> + )>, + <"BuiltinType" : ( + { + "pointer" : 37 + }, + <"Char_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 38 + }, + <"SChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 39 + }, + <"Short"> + )>, + <"BuiltinType" : ( + { + "pointer" : 10 + }, + <"Int"> + )>, + <"BuiltinType" : ( + { + "pointer" : 40 + }, + <"Long"> + )>, + <"BuiltinType" : ( + { + "pointer" : 41 + }, + <"LongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 42 + }, + <"UChar"> + )>, + <"BuiltinType" : ( + { + "pointer" : 43 + }, + <"UShort"> + )>, + <"BuiltinType" : ( + { + "pointer" : 44 + }, + <"UInt"> + )>, + <"BuiltinType" : ( + { + "pointer" : 45 + }, + <"ULong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 46 + }, + <"ULongLong"> + )>, + <"BuiltinType" : ( + { + "pointer" : 47 + }, + <"Float"> + )>, + <"BuiltinType" : ( + { + "pointer" : 48 + }, + <"Double"> + )>, + <"BuiltinType" : ( + { + "pointer" : 49 + }, + <"LongDouble"> + )>, + <"BuiltinType" : ( + { + "pointer" : 50 + }, + <"Float128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 51 + }, + <"Float16"> + )>, + <"BuiltinType" : ( + { + "pointer" : 52 + }, + <"ShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 53 + }, + <"Accum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 54 + }, + <"LongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 55 + }, + <"UShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 56 + }, + <"UAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 57 + }, + <"ULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 58 + }, + <"ShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 59 + }, + <"Fract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 60 + }, + <"LongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 61 + }, + <"UShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 62 + }, + <"UFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 63 + }, + <"ULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 64 + }, + <"SatShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 65 + }, + <"SatAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 66 + }, + <"SatLongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 67 + }, + <"SatUShortAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 68 + }, + <"SatUAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 69 + }, + <"SatULongAccum"> + )>, + <"BuiltinType" : ( + { + "pointer" : 70 + }, + <"SatShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 71 + }, + <"SatFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 72 + }, + <"SatLongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 73 + }, + <"SatUShortFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 74 + }, + <"SatUFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 75 + }, + <"SatULongFract"> + )>, + <"BuiltinType" : ( + { + "pointer" : 76 + }, + <"Int128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 77 + }, + <"UInt128"> + )>, + <"BuiltinType" : ( + { + "pointer" : 78 + }, + <"WChar_S"> + )>, + <"BuiltinType" : ( + { + "pointer" : 79 + }, + <"Char8"> + )>, + <"BuiltinType" : ( + { + "pointer" : 80 + }, + <"Dependent"> + )>, + <"BuiltinType" : ( + { + "pointer" : 81 + }, + <"Overload"> + )>, + <"BuiltinType" : ( + { + "pointer" : 82 + }, + <"BoundMember"> + )>, + <"BuiltinType" : ( + { + "pointer" : 83 + }, + <"PseudoObject"> + )>, + <"BuiltinType" : ( + { + "pointer" : 84 + }, + <"UnknownAny"> + )>, + <"BuiltinType" : ( + { + "pointer" : 85 + }, + <"ARCUnbridgedCast"> + )>, + <"BuiltinType" : ( + { + "pointer" : 86 + }, + <"BuiltinFn"> + )>, + <"ComplexType" : ( + { + "pointer" : 87 + } + )>, + <"ComplexType" : ( + { + "pointer" : 88 + } + )>, + <"ComplexType" : ( + { + "pointer" : 89 + } + )>, + <"ComplexType" : ( + { + "pointer" : 90 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 91 + }, + <"ObjCId"> + )>, + <"BuiltinType" : ( + { + "pointer" : 92 + }, + <"ObjCClass"> + )>, + <"BuiltinType" : ( + { + "pointer" : 93 + }, + <"ObjCSel"> + )>, + <"PointerType" : ( + { + "pointer" : 94 + }, + { + "type_ptr" : 35 + } + )>, + <"BuiltinType" : ( + { + "pointer" : 95 + }, + <"NullPtr"> + )>, + <"BuiltinType" : ( + { + "pointer" : 96 + }, + <"Half"> + )>, + <"BuiltinType" : ( + { + "pointer" : 97 + }, + <"BFloat16"> + )>, + <"RecordType" : ( + { + "pointer" : 98 + }, + 99 + )>, + <"PointerType" : ( + { + "pointer" : 100 + }, + { + "type_ptr" : 10, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 101 + }, + { + "type_ptr" : 37, + "is_const" : true + } + )>, + <"PointerType" : ( + { + "pointer" : 102 + }, + { + "type_ptr" : 37 + } + )>, + <"RecordType" : ( + { + "pointer" : 103 + }, + 104 + )>, + <"ConstantArrayType" : ( + { + "pointer" : 105 + }, + { + "element_type" : { + "type_ptr" : 103 + }, + "stride" : 24 + }, + 1 + )>, + <"RecordType" : ( + { + "pointer" : 8 + }, + 7 + )>, + <"ElaboratedType" : ( + { + "pointer" : 106, + "desugared_type" : 8 + } + )>, + <"PointerType" : ( + { + "pointer" : 107 + }, + { + "type_ptr" : 8 + } + )>, + <"PointerType" : ( + { + "pointer" : 12 + }, + { + "type_ptr" : 106 + } + )>, + <"ElaboratedType" : ( + { + "pointer" : 108, + "desugared_type" : 8 + } + )>, + <"FunctionProtoType" : ( + { + "pointer" : 16 + }, + { + "return_type" : { + "type_ptr" : 10 + } + }, + { + } + )>, + <"PointerType" : ( + { + "pointer" : 109 + }, + { + "type_ptr" : 102 + } + )>, + <"TypedefType" : ( + { + "pointer" : 14, + "desugared_type" : 8 + }, + { + "child_type" : { + "type_ptr" : 108 + }, + "decl_ptr" : 13 + } + )>, + <"PointerType" : ( + { + "pointer" : 32 + }, + { + "type_ptr" : 14 + } + )>, + <"ObjCObjectType" : ( + { + "pointer" : 110 + }, + { + "base_type" : 91 + } + )>, + <"ObjCObjectPointerType" : ( + { + "pointer" : 111 + }, + { + "type_ptr" : 110 + } + )>, + <"TypedefType" : ( + { + "pointer" : 112, + "desugared_type" : 111 + }, + { + "child_type" : { + "type_ptr" : 111 + }, + "decl_ptr" : 113 + } + )>, + <"TypedefType" : ( + { + "pointer" : 34, + "desugared_type" : 111 + }, + { + "child_type" : { + "type_ptr" : 112 + }, + "decl_ptr" : 33 + } + )>, + <"NoneType" : ( + { + "pointer" : 0 + } + )> + ] + } +)> diff --git a/src/lib/ast.ml b/src/lib/ast.ml index e9b95b6..baa8176 100644 --- a/src/lib/ast.ml +++ b/src/lib/ast.ml @@ -48,14 +48,20 @@ type field = { bit_width_expr: expression option; } +and field_definition = + | FieldDecl of field + | FieldRecordDecl of CType.id * record * Location.t + | FieldUnionDecl of CType.id * union * Location.t + | FieldEnumDecl of CType.id * enum * Location.t + and record = { record_name: string; - record_fields: field list; + record_fields: field_definition list; } and union = { union_name: string; - union_fields: field list; + union_fields: field_definition list; } and enumerator = { @@ -128,6 +134,7 @@ and expression = | INDEX of expression * expression * Location.t | MEMBER of expression * string * Location.t | INIT_LIST of expression list * Location.t + | IMPLICIT_VALUE_INIT of expression list * Location.t and constant = | CONST_CHAR of string @@ -148,6 +155,13 @@ let rec show_file indent = function (filename, definition_list) -> indent ^ "File(name: " ^ filename ^ "\n" ^ defs ^ "\n" ^ ")" + +and show_field_definition = function + | FieldDecl field -> show_field field + | FieldRecordDecl (id, record, location) -> show_record_definition id record location + | FieldUnionDecl (id, union, location) -> show_union_definition id union location + | FieldEnumDecl (id, enum, location) -> show_enum_definition id enum location + and show_field { field_type; field_name; bit_width_expr } = let field_type = show_ctype field_type in let bit_width_expr = bit_width_expr @@ -155,24 +169,27 @@ and show_field { field_type; field_name; bit_width_expr } = |> Option.value ~default:"" in " " ^ field_name ^ ": " ^ field_type ^ bit_width_expr + and show_record_definition id { record_name; record_fields } _location = let fields = record_fields - |> List.map show_field + |> List.map show_field_definition |> String.concat "\n" in "struct " ^ record_name ^ " {\n" ^ fields ^ "\n" ^ "}(User defined as " ^ string_of_int id ^ ")\n" + and show_union_definition id { union_name; union_fields } _location = let fields = union_fields - |> List.map show_field + |> List.map show_field_definition |> String.concat "\n" in "union " ^ union_name ^ " {\n" ^ fields ^ "\n" ^ "}(User defined as " ^ string_of_int id ^ ")\n" + and show_enum_definition id { enum_name; enumerators } _location = let show_enumerators { enumerator_type; enumerator_name; init_expr } = let name = enumerator_name ^ ": " ^ show_ctype enumerator_type in @@ -188,12 +205,14 @@ and show_enum_definition id { enum_name; enumerators } _location = "enum " ^ enum_name ^ " {\n" ^ enumerators ^ "\n" ^ "}(User defined as " ^ string_of_int id ^ ")\n" + and show_variable_scope {is_global; is_static; is_static_local} = let info = [] in let info = if is_static_local then "static_local" :: info else info in let info = if is_static then "static" :: info else info in let info = if is_global then "global" :: info else info in String.concat " " info + and show_definition indent = function | FUNDEF ((return_type, func_name, _location1), single_name_list, block, _location2) -> let args = @@ -226,6 +245,7 @@ and show_definition indent = function show_union_definition id union location | ENUMDEF (id, enum, location) -> show_enum_definition id enum location + and show_init_name_group indent (ctype, init_name_list) = let names = init_name_list @@ -235,12 +255,14 @@ and show_init_name_group indent (ctype, init_name_list) = indent ^ "names: \n" ^ names ^ "\n" ^ indent ^ "types: " ^ show_ctype ctype + and show_init_name (name, init_expr) = match init_expr with | NO_INIT -> name | SINGLE_INIT expr -> name ^ " = " ^ show_expression expr + and show_ctype = function | Tvoid -> "void" | Tbool -> "bool" @@ -260,10 +282,12 @@ and show_ctype = function | Tarray (tpe, len) -> "Type:" ^ show_ctype tpe ^ "[" ^ string_of_int len ^ "]" | Tpointer tpe -> "*" ^ "Type:" ^ show_ctype tpe | Tdefined p -> "(User Defined Type of ->" ^ string_of_int p ^ ")" + and show_block indent block = block |> List.map (show_statement indent) |> String.concat "\n" + and show_statement indent = function | NOP -> "" @@ -310,6 +334,7 @@ and show_statement indent = function show_union_definition id union location | ENUMDEC (id, enum, location) -> show_enum_definition id enum location + and show_expression = function | CONST_EXPR (expr, _location) -> show_expression expr @@ -334,10 +359,14 @@ and show_expression = function | INIT_LIST (exprs, _location) -> let exprs = exprs + |> List.filter (function IMPLICIT_VALUE_INIT _ -> false | _ -> true) |> List.map show_expression |> String.concat ", " in "{ " ^ exprs ^ " }" + | IMPLICIT_VALUE_INIT (_exprs, _location) -> + "" + and show_unary_operator v = function | MINUS -> "-" ^ v | PLUS -> "+" ^ v @@ -349,6 +378,7 @@ and show_unary_operator v = function | PREDECR -> "--" ^ v | POSINCR -> v ^ "++" | POSDECR -> v ^ "--" + and show_binary_operator = function | ADD -> "+" | SUB -> "-" @@ -364,6 +394,7 @@ and show_binary_operator = function | LE -> "<=" | GE -> ">=" | ASSIGN -> "=" + and show_constant = function | CONST_CHAR i_as_str -> i_as_str | CONST_INT i_as_str -> i_as_str diff --git a/src/lib/ast.mli b/src/lib/ast.mli index 0007161..d800821 100644 --- a/src/lib/ast.mli +++ b/src/lib/ast.mli @@ -47,14 +47,20 @@ type field = { bit_width_expr: expression option; } +and field_definition = + | FieldDecl of field + | FieldRecordDecl of CType.id * record * Location.t + | FieldUnionDecl of CType.id * union * Location.t + | FieldEnumDecl of CType.id * enum * Location.t + and record = { record_name: string; - record_fields: field list; + record_fields: field_definition list; } and union = { union_name: string; - union_fields: field list; + union_fields: field_definition list; } and enumerator = { @@ -201,6 +207,7 @@ and expression = | INDEX of expression * expression * Location.t (** array index expression [a[i]] *) | MEMBER of expression * string * Location.t (** record's field expression [a.x] *) | INIT_LIST of expression list * Location.t (** initializer list [struct foo = { 1, { 2, 3 } }] *) + | IMPLICIT_VALUE_INIT of expression list * Location.t (** implicit initializer *) and constant = | CONST_CHAR of string (** the textual representation *) diff --git a/src/lib/ast2cabs.ml b/src/lib/ast2cabs.ml index cf720a1..c8002a8 100644 --- a/src/lib/ast2cabs.ml +++ b/src/lib/ast2cabs.ml @@ -85,6 +85,8 @@ let rec conv_expression : Ast.expression -> Cabs.expression = function raise (Cannot_convert "Cabs does not support MEMBER expression") | Ast.INIT_LIST _ -> raise (Cannot_convert "Cabs does not support INIT_LIST expression") + | Ast.IMPLICIT_VALUE_INIT _ -> + raise (Cannot_convert "Cabs does not support IMPLICIT_VALUE_INIT expression") let rec conv_statement : Ast.statement -> Cabs.statement = function | Ast.NOP -> Cabs.NOP dummy_loc diff --git a/src/lib/yojson2ast.ml b/src/lib/yojson2ast.ml index 2c07d81..3b2dfa7 100644 --- a/src/lib/yojson2ast.ml +++ b/src/lib/yojson2ast.ml @@ -629,6 +629,16 @@ let rec parse_expression typemap : Yojson.Safe.t -> Ast.expression = function let location = extract_location source_info in let exprs = List.map (parse_expression typemap) exprs in Ast.INIT_LIST (exprs, location) + | `Variant ( + "ImplicitValueInitExpr", Some (`Tuple ( + `Assoc source_info :: + `List [] :: + `Assoc _type_info :: + _ + )) + ) -> + let location = extract_location source_info in + Ast.IMPLICIT_VALUE_INIT ([], location) | yojson -> raise (Invalid_Yojson ("Invalid expression data.", yojson)) @@ -654,12 +664,22 @@ and parse_record_or_union typemap yojson = |> List.assoc_opt "bit_width_expr" |> Option.map (parse_expression typemap) in - Ast.{ field_type; field_name; bit_width_expr } :: fields + Ast.(FieldDecl { field_type; field_name; bit_width_expr }) :: fields | _ -> fields end - | _ -> - fields + (* While this field(s) are defined at other place, this indirect field decl is skipped. *) + | `Variant ("IndirectFieldDecl", _) -> fields + | `Variant ("RecordDecl", _) as yojson -> + begin match parse_record_or_union typemap yojson with + | `TTK_Struct (id, record, location) -> Ast.FieldRecordDecl (id, record, location) :: fields + | `TTK_Union (id, union, location) -> Ast.FieldUnionDecl (id, union, location) :: fields + end + | `Variant ("EnumDecl", _) as yojson -> + let id, enum, location = parse_enum typemap yojson in + Ast.FieldEnumDecl (id, enum, location) :: fields + | yojson -> + raise (Invalid_Yojson ("Invalid field decl in struct or union.", yojson)) ) [] fields_yojson @@ -698,11 +718,11 @@ and parse_record_or_union typemap yojson = | `Variant ("TTK_Union", _) -> let union = Ast.{ union_name= name; union_fields= fields } in `TTK_Union (ptr, union, location) - | _ -> + | yojson -> raise (Invalid_Yojson ("Invalid record definition.", yojson)) end | _ -> - raise (Invalid_Yojson ("Invalid record definition.", yojson)) + raise (Invalid_Yojson ("Invalid record definition. ptr and name must be defined.", yojson)) end | _ -> raise (Invalid_Yojson ("Invalid record definition.", yojson)) @@ -767,9 +787,9 @@ and parse_enum typemap yojson = | (Some ptr), (Some enum_name) -> let enum = Ast.{ enum_name; enumerators } in ptr, enum, location - | _ -> raise (Invalid_Yojson ("Invalid record definition.", yojson)) + | _ -> raise (Invalid_Yojson ("Invalid enum definition. ptr and name must be defined.", yojson)) end - | _ -> raise (Invalid_Yojson ("Invalid record definition.", yojson)) + | yojson -> raise (Invalid_Yojson ("Invalid enum definition.", yojson)) and parse_statement typemap : Yojson.Safe.t -> Ast.statement = function | `Variant (