Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: elliotchance/c2go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.17.4
Choose a base ref
...
head repository: elliotchance/c2go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 15,527 additions and 2,236 deletions.
  1. +5 −5 .snapshots/c2go-TestCLI-func1-AstHelpFlag
  2. +5 −5 .snapshots/c2go-TestCLI-func1-AstNoFilesHelp
  3. +10 −12 .snapshots/c2go-TestCLI-func1-TranspileHelpFlag
  4. +10 −12 .snapshots/c2go-TestCLI-func1-TranspileNoFilesHelp
  5. +13 −7 .travis.yml
  6. +1 −1 LICENSE
  7. +7 −8 README.md
  8. +1 −0 ast/array_filler.go
  9. +7 −3 ast/array_subscript_expr.go
  10. +18 −1 ast/array_subscript_expr_test.go
  11. +15 −11 ast/asm_label_attr.go
  12. +20 −10 ast/asm_label_attr_test.go
  13. +68 −4 ast/ast.go
  14. +43 −0 ast/attributed_type.go
  15. +18 −0 ast/attributed_type_test.go
  16. +2 −0 ast/availability_attr.go
  17. +1 −0 ast/binary_operator.go
  18. +46 −0 ast/block_command_comment.go
  19. +18 −0 ast/block_command_comment_test.go
  20. +1 −0 ast/break_stmt.go
  21. +1 −0 ast/builtin_type.go
  22. +45 −0 ast/c11_no_return_attr.go
  23. +17 −0 ast/c11_no_return_attr_test.go
  24. +7 −0 ast/c_style_cast_expr.go
  25. +1 −0 ast/call_expr.go
  26. +1 −0 ast/case_stmt.go
  27. +262 −0 ast/character_literal.go
  28. +382 −0 ast/character_literal_test.go
  29. +1 −0 ast/compound_assign_operator.go
  30. +1 −1 ast/compound_literal_expr.go
  31. +1 −0 ast/compound_stmt.go
  32. +1 −0 ast/conditional_operator.go
  33. +2 −0 ast/const_attr.go
  34. +1 −0 ast/constant_array_type.go
  35. +2 −2 ast/constant_array_type_test.go
  36. +46 −0 ast/constant_expr.go
  37. +18 −0 ast/constant_expr_test.go
  38. +1 −0 ast/continue_stmt.go
  39. +44 −0 ast/decayed_type.go
  40. +17 −0 ast/decayed_type_test.go
  41. +32 −20 ast/decl_ref_expr.go
  42. +24 −0 ast/decl_ref_expr_test.go
  43. +1 −0 ast/decl_stmt.go
  44. +1 −0 ast/default_stmt.go
  45. +2 −0 ast/deprecated_attr.go
  46. +1 −0 ast/do_stmt.go
  47. +2 −1 ast/elaborated_type.go
  48. +2 −1 ast/enum.go
  49. +1 −0 ast/enum_constant_decl.go
  50. +4 −1 ast/enum_decl.go
  51. +8 −0 ast/enum_decl_test.go
  52. +2 −1 ast/enum_type.go
  53. +1 −0 ast/field.go
  54. +6 −1 ast/field_decl.go
  55. +20 −0 ast/field_decl_test.go
  56. +14 −3 ast/floating_literal.go
  57. +44 −0 ast/floating_literal_test.go
  58. +1 −0 ast/for_stmt.go
  59. +48 −0 ast/format_arg_attr.go
  60. +18 −0 ast/format_arg_attr_test.go
  61. +2 −0 ast/format_attr.go
  62. +44 −0 ast/full_comment.go
  63. +17 −0 ast/full_comment_test.go
  64. +17 −3 ast/function_decl.go
  65. +119 −0 ast/function_decl_test.go
  66. +49 −0 ast/function_no_proto_type.go
  67. +18 −0 ast/function_no_proto_type_test.go
  68. +2 −1 ast/function_proto_type.go
  69. +1 −0 ast/gcc_asm_stmt.go
  70. +1 −0 ast/go_stmt.go
  71. +46 −0 ast/html_end_tag_comment.go
  72. +18 −0 ast/html_end_tag_comment_test.go
  73. +46 −0 ast/html_start_tag_comment.go
  74. +18 −0 ast/html_start_tag_comment_test.go
  75. +4 −1 ast/if_stmt.go
  76. +6 −0 ast/if_stmt_test.go
  77. +20 −13 ast/implicit_cast_expr.go
  78. +16 −0 ast/implicit_cast_expr_test.go
  79. +7 −5 ast/implicit_value_init_expr.go
  80. +1 −0 ast/incomplete_array_type.go
  81. +2 −1 ast/indirect_field_decl.go
  82. +1 −0 ast/init_list_expr.go
  83. +46 −0 ast/inline_command_comment.go
  84. +18 −0 ast/inline_command_comment_test.go
  85. +1 −0 ast/integer_literal.go
  86. +1 −0 ast/label_stmt.go
  87. +2 −0 ast/malloc_attr.go
  88. +2 −0 ast/max_field_alignment_attr.go
  89. +26 −22 ast/member_expr.go
  90. +25 −0 ast/member_expr_test.go
  91. +2 −0 ast/mode_attr.go
  92. +44 −0 ast/no_alias_attr.go
  93. +17 −0 ast/no_alias_attr_test.go
  94. +2 −0 ast/no_inline_attr.go
  95. +10 −1 ast/no_throw_attr.go
  96. +23 −0 ast/no_throw_attr_test.go
  97. +27 −2 ast/non_null_attr.go
  98. +52 −0 ast/non_null_attr_test.go
  99. +45 −0 ast/not_tail_called_attr.go
  100. +17 −0 ast/not_tail_called_attr_test.go
  101. +1 −0 ast/offset_of_expr.go
  102. +2 −0 ast/packed_attr.go
  103. +44 −0 ast/paragraph_comment.go
  104. +17 −0 ast/paragraph_comment_test.go
  105. +46 −0 ast/param_command_comment.go
  106. +18 −0 ast/param_command_comment_test.go
  107. +7 −1 ast/paren_expr.go
  108. +13 −0 ast/paren_expr_test.go
  109. +1 −0 ast/paren_type.go
  110. +6 −1 ast/parm_var_decl.go
  111. +19 −0 ast/parm_var_decl_test.go
  112. +1 −0 ast/pointer_type.go
  113. +64 −10 ast/position.go
  114. +54 −12 ast/position_test.go
  115. +1 −0 ast/predefined_expr.go
  116. +2 −0 ast/pure_attr.go
  117. +1 −0 ast/qual_type.go
  118. +1 −0 ast/record.go
  119. +1 −0 ast/record_decl.go
  120. +1 −0 ast/record_type.go
  121. +2 −0 ast/restrict_attr.go
  122. +1 −0 ast/return_stmt.go
  123. +10 −1 ast/returns_twice_attr.go
  124. +9 −0 ast/returns_twice_attr_test.go
  125. +60 −0 ast/sentinel_attr.go
  126. +19 −0 ast/sentinel_attr_test.go
  127. +1 −0 ast/stmt_expr.go
  128. +3 −2 ast/string_literal.go
  129. +16 −0 ast/string_literal_test.go
  130. +1 −0 ast/switch_stmt.go
  131. +46 −0 ast/text_comment.go
  132. +18 −0 ast/text_comment_test.go
  133. +2 −1 ast/translation_unit_decl.go
  134. +2 −0 ast/transparent_union_attr.go
  135. +1 −0 ast/typedef.go
  136. +1 −0 ast/typedef_decl.go
  137. +11 −0 ast/typedef_decl_test.go
  138. +1 −0 ast/typedef_type.go
  139. +6 −1 ast/unary_expr_or_type_trait_expr.go
  140. +20 −0 ast/unary_expr_or_type_trait_expr_test.go
  141. +22 −16 ast/unary_operator.go
  142. +24 −0 ast/unary_operator_test.go
  143. +5 −1 ast/unused_attr.go
  144. +7 −0 ast/unused_attr_test.go
  145. +9 −3 ast/util.go
  146. +1 −0 ast/va_arg_expr.go
  147. +15 −1 ast/var_decl.go
  148. +108 −0 ast/var_decl_test.go
  149. +50 −0 ast/verbatim_block_comment.go
  150. +19 −0 ast/verbatim_block_comment_test.go
  151. +46 −0 ast/verbatim_block_line_comment.go
  152. +18 −0 ast/verbatim_block_line_comment_test.go
  153. +46 −0 ast/verbatim_line_comment.go
  154. +18 −0 ast/verbatim_line_comment_test.go
  155. +54 −0 ast/visibility_attr.go
  156. +36 −0 ast/visibility_attr_test.go
  157. +5 −1 ast/warn_unused_result_attr.go
  158. +14 −0 ast/warn_unused_result_attr_test.go
  159. +3 −1 ast/weak_attr.go
  160. +7 −0 ast/weak_attr_test.go
  161. +1 −0 ast/while_stmt.go
  162. +5 −3 cc/preprocessor.go
  163. +8 −8 cli_test.go
  164. +4 −4 darwin/assert.go
  165. +15 −11 darwin/ctype.go
  166. +1 −1 darwin/math.go
  167. +23 −0 darwin/stdio.go
  168. +42 −0 darwin/string.go
  169. +3 −0 go.mod
  170. +2 −0 go.sum
  171. +2 −2 linux/assert.go
  172. +16 −8 linux/ctype.go
  173. +3 −3 linux/math.go
  174. +30 −21 main.go
  175. +196 −36 main_test.go
  176. +325 −0 noarch/errno.go
  177. +10 −4 noarch/math.go
  178. +28 −1 noarch/noarch.go
  179. +6 −0 noarch/stdarg.go
  180. +363 −120 noarch/stdio.go
  181. +70 −34 noarch/stdlib.go
  182. +182 −2 noarch/string.go
  183. +26 −0 noarch/string_test.go
  184. +75 −0 noarch/syslog.go
  185. +25 −0 noarch/syslog_nop.go
  186. +97 −10 noarch/time.go
  187. +127 −13 noarch/util.go
  188. +4 −6 noarch/util_test.go
  189. +201 −0 preprocessor/parse_comments_test.go
  190. +211 −32 preprocessor/preprocessor.go
  191. +291 −200 program/function_definition.go
  192. +1 −1 program/import.go
  193. +210 −12 program/program.go
  194. +58 −4 program/struct.go
  195. +8 −0 program/version.go
  196. +7 −4 program/warnings.go
  197. +635 −1 tests/array.c
  198. +276 −2 tests/cast.c
  199. +16 −0 tests/code_quality/for.c
  200. +33 −0 tests/code_quality/for.expected.c
  201. +26 −0 tests/code_quality/generate.sh
  202. +17 −0 tests/code_quality/if.c
  203. +25 −0 tests/code_quality/if.expected.c
  204. +5 −0 tests/code_quality/operators.c
  205. +22 −0 tests/code_quality/operators.expected.c
  206. +32 −0 tests/code_quality/switch.c
  207. +46 −0 tests/code_quality/switch.expected.c
  208. +51 −0 tests/comment/main.c
  209. +19 −0 tests/ctype.c
  210. +14 −1 tests/do.c
  211. +22 −2 tests/enum.c
  212. +74 −2 tests/for.c
  213. +170 −3 tests/function.c
  214. +65 −1 tests/if.c
  215. +11 −0 tests/multi-struct/main.c
  216. +17 −0 tests/multi-struct/types.c
  217. +15 −0 tests/multi-struct/types.h
  218. +5 −0 tests/multi/err.h
  219. +9 −0 tests/multi/main1.c
  220. +416 −9 tests/operators.c
  221. +34 −1 tests/sizeof.c
  222. +130 −0 tests/stdarg.c
  223. +55 −1 tests/stdbool.c
  224. +200 −4 tests/stdio.c
  225. +66 −2 tests/stdlib.c
  226. +330 −0 tests/string.c
  227. +562 −1 tests/struct.c
  228. +272 −2 tests/switch.c
  229. +16 −0 tests/syslog.c
  230. +12 −1 tests/ternary.c
  231. +10 −25 tests/tests.h
  232. +57 −5 tests/time.c
  233. +223 −7 tests/union.c
  234. +84 −1 tests/while.c
  235. +256 −114 transpiler/binary.go
  236. +279 −42 transpiler/branch.go
  237. +273 −46 transpiler/call.go
  238. +182 −0 transpiler/cast.go
  239. +432 −137 transpiler/declarations.go
  240. +72 −10 transpiler/enum.go
  241. +166 −35 transpiler/functions.go
  242. +62 −10 transpiler/literals.go
  243. +761 −84 transpiler/operators.go
  244. +5 −0 transpiler/scope.go
  245. +391 −30 transpiler/switch.go
  246. +156 −0 transpiler/translation_unit.go
  247. +204 −111 transpiler/transpiler.go
  248. +578 −87 transpiler/unary.go
  249. +94 −281 transpiler/union.go
  250. +67 −2 transpiler/util.go
  251. +266 −171 transpiler/variables.go
  252. 0 travis/lint.sh
  253. +17 −2 travis/test.sh
  254. +307 −19 types/cast.go
  255. +0 −9 types/cast_test.go
  256. +13 −1 types/dereference.go
  257. +476 −73 types/resolve.go
  258. +113 −19 types/resolve_test.go
  259. +42 −36 types/sizeof.go
  260. +4 −1 types/sizeof_test.go
  261. +95 −0 util/evaluate.go
  262. +219 −93 util/goast.go
  263. +5 −1 util/util.go
10 changes: 5 additions & 5 deletions .snapshots/c2go-TestCLI-func1-AstHelpFlag
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
([]string) (len=3) {
(string) (len=22) "Usage: test ast file.c",
(string) (len=27) " -h\tprint help information",
(string) ""
}
(*bytes.Buffer)(Usage: test ast file.c
-clang-flag value
Pass arguments to clang. You may provide multiple -clang-flag items.
-h print help information
)
10 changes: 5 additions & 5 deletions .snapshots/c2go-TestCLI-func1-AstNoFilesHelp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
([]string) (len=3) {
(string) (len=22) "Usage: test ast file.c",
(string) (len=27) " -h\tprint help information",
(string) ""
}
(*bytes.Buffer)(Usage: test ast file.c
-clang-flag value
Pass arguments to clang. You may provide multiple -clang-flag items.
-h print help information
)
22 changes: 10 additions & 12 deletions .snapshots/c2go-TestCLI-func1-TranspileHelpFlag
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
([]string) (len=10) {
(string) (len=64) "Usage: test transpile [-V] [-o file.go] [-p package] file1.c ...",
(string) (len=31) " -V\tprint progress as comments",
(string) (len=19) " -clang-flag value",
(string) (len=73) " \tPass arguments to clang. You may provide multiple -clang-flag items.",
(string) (len=27) " -h\tprint help information",
(string) (len=11) " -o string",
(string) (len=51) " \toutput Go generated code to the specified file",
(string) (len=11) " -p string",
(string) (len=59) " \tset the name of the generated package (default \"main\")",
(string) ""
}
(*bytes.Buffer)(Usage: test transpile [-V] [-o file.go] [-p package] file1.c ...
-V print progress as comments
-clang-flag value
Pass arguments to clang. You may provide multiple -clang-flag items.
-h print help information
-o string
output Go generated code to the specified file
-p string
set the name of the generated package (default "main")
)
22 changes: 10 additions & 12 deletions .snapshots/c2go-TestCLI-func1-TranspileNoFilesHelp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
([]string) (len=10) {
(string) (len=64) "Usage: test transpile [-V] [-o file.go] [-p package] file1.c ...",
(string) (len=31) " -V\tprint progress as comments",
(string) (len=19) " -clang-flag value",
(string) (len=73) " \tPass arguments to clang. You may provide multiple -clang-flag items.",
(string) (len=27) " -h\tprint help information",
(string) (len=11) " -o string",
(string) (len=51) " \toutput Go generated code to the specified file",
(string) (len=11) " -p string",
(string) (len=59) " \tset the name of the generated package (default \"main\")",
(string) ""
}
(*bytes.Buffer)(Usage: test transpile [-V] [-o file.go] [-p package] file1.c ...
-V print progress as comments
-clang-flag value
Pass arguments to clang. You may provide multiple -clang-flag items.
-h print help information
-o string
output Go generated code to the specified file
-p string
set the name of the generated package (default "main")
)
20 changes: 13 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: go

go:
- "1.9.x"

os:
- linux
- osx
@@ -14,12 +17,16 @@ matrix:
include:
- env: SCRIPT=test CLANG=3.4
os: linux
- env: SCRIPT=test CLANG=3.5
os: linux
- env: SCRIPT=test CLANG=3.6
os: linux
- env: SCRIPT=test CLANG=3.7
os: linux
- env: SCRIPT=test CLANG=3.8
os: linux
- env: SCRIPT=test CLANG=5.0
os: linux
- env: SCRIPT=lint CLANG=3.9
os: linux

@@ -28,20 +35,19 @@ before_install:
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-add-repository "deb http://apt.llvm.org/precise/ llvm-toolchain-precise-$CLANG main"
sudo apt-add-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-$CLANG main"
sudo apt-get update
sudo apt-cache search clang
sudo apt-get install -f -y --force-yes clang-$CLANG lldb-$CLANG
fi
- |
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
rvm get head
fi
# gocovmerge is used to merge all the separate unit/integration test coverage
# profiles.
- go get -u github.com/wadey/gocovmerge
- go get -u -v github.com/wadey/gocovmerge

# install gometalinter
- go get -u github.com/alecthomas/gometalinter
- gometalinter --install

script:
- . ./travis/$SCRIPT.sh
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Elliot Chance
Copyright (c) 2017 Elliot Chance, Izyumov Konstantin and Christophe Kamphaus.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[![Build Status](https://travis-ci.org/elliotchance/c2go.svg?branch=master)](https://travis-ci.org/elliotchance/c2go)
[![GitHub version](https://badge.fury.io/gh/elliotchance%2Fc2go.svg)](https://badge.fury.io/gh/elliotchance%2Fc2go)
[![Go Report Card](https://goreportcard.com/badge/github.com/elliotchance/c2go)](https://goreportcard.com/report/github.com/elliotchance/c2go)
[![codecov](https://codecov.io/gh/elliotchance/c2go/branch/master/graph/badge.svg)](https://codecov.io/gh/elliotchance/c2go)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/elliotchance/c2go/master/LICENSE)
[![Join the chat at https://gitter.im/c2goproject](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/c2goproject?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Twitter](https://img.shields.io/twitter/url/https/github.com/elliotchance/c2go.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D)
[![GoDoc](https://godoc.org/github.com/elliotchance/c2go?status.svg)](https://godoc.org/github.com/elliotchance/c2go)

A tool for converting C to Go.

@@ -21,6 +23,8 @@ without modification. This will be the 1.0.0 release.

# Installation

`c2go` requires Go 1.9 or newer.

```bash
go get -u github.com/elliotchance/c2go
```
@@ -122,17 +126,12 @@ func __init() {
}
```

# What Is Supported?

See the
[Project Progress](https://github.com/elliotchance/c2go/wiki/Project-Progress).

# How It Works

This is the process:

1. The C code is preprocessed with clang. This generates a larger file (`pp.c`),
but removes all the platform specific directives and macros.
but removes all the platform-specific directives and macros.

2. `pp.c` is parsed with the clang AST and dumps it in a colourful text format
that
@@ -143,7 +142,7 @@ that the code must compile successfully under clang for the AST to also be
usable.

3. Since we have all the types in the AST it's just a matter of traversing the
tree is a semi-intelligent way and producing Go. Easy, right!?
tree in a semi-intelligent way and producing Go. Easy, right!?

# Testing

@@ -171,7 +170,7 @@ Contributing is done with pull requests. There is no help that is too small! :)

If you're looking for where to start I can suggest
[finding a simple C program](http://www.programmingsimplified.com/c-program-examples)
(like the other examples) that do not successfully translate into Go.
(like the other examples) that does not successfully translate into Go.

Or, if you don't want to do that you can submit it as an issue so that it can be
picked up by someone else.
1 change: 1 addition & 0 deletions ast/array_filler.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ast

// ArrayFiller is type of array filler
type ArrayFiller struct {
ChildNodes []Node
}
10 changes: 7 additions & 3 deletions ast/array_subscript_expr.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package ast

// ArraySubscriptExpr is expression.
type ArraySubscriptExpr struct {
Addr Address
Pos Position
Type string
Kind string
Type2 string
IsLvalue bool
ChildNodes []Node
}

func parseArraySubscriptExpr(line string) *ArraySubscriptExpr {
groups := groupsFromRegex(
"<(?P<position>.*)> '(?P<type>.*?)' (?P<kind>.*)",
`<(?P<position>.*)> '(?P<type>.*?)'(:'(?P<type2>.*?)')?
(?P<lvalue> lvalue)?`,
line,
)

return &ArraySubscriptExpr{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Type: groups["type"],
Kind: groups["kind"],
Type2: groups["type2"],
IsLvalue: len(groups["lvalue"]) > 0,
ChildNodes: []Node{},
}
}
19 changes: 18 additions & 1 deletion ast/array_subscript_expr_test.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,24 @@ func TestArraySubscriptExpr(t *testing.T) {
Addr: 0x7fe35b85d180,
Pos: NewPositionFromString("col:63, col:69"),
Type: "char *",
Kind: "lvalue",
Type2: "",
IsLvalue: true,
ChildNodes: []Node{},
},
`0x2416660 <col:2, col:5> 'u32':'unsigned int' lvalue`: &ArraySubscriptExpr{
Addr: 0x2416660,
Pos: NewPositionFromString("col:2, col:5"),
Type: "u32",
Type2: "unsigned int",
IsLvalue: true,
ChildNodes: []Node{},
},
`0x3f147c0 <col:39, col:55> 'extCoord':'extCoord' lvalue`: &ArraySubscriptExpr{
Addr: 0x3f147c0,
Pos: NewPositionFromString("col:39, col:55"),
Type: "extCoord",
Type2: "extCoord",
IsLvalue: true,
ChildNodes: []Node{},
},
}
26 changes: 15 additions & 11 deletions ast/asm_label_attr.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
package ast

// AsmLabelAttr is a type of attribute for assembler label
type AsmLabelAttr struct {
Addr Address
Pos Position
Inherited bool
FunctionName string
ChildNodes []Node
Addr Address
Pos Position
Inherited bool
FunctionName string
ChildNodes []Node
IsLiteralLabel bool
}

func parseAsmLabelAttr(line string) *AsmLabelAttr {
groups := groupsFromRegex(
`<(?P<position>.*)>
(?P<inherited> Inherited)?
"(?P<function>.+)"`,
"(?P<function>.+)"
(?P<literal> IsLiteralLabel)?`,
line,
)

return &AsmLabelAttr{
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Inherited: len(groups["inherited"]) > 0,
FunctionName: groups["function"],
ChildNodes: []Node{},
Addr: ParseAddress(groups["address"]),
Pos: NewPositionFromString(groups["position"]),
Inherited: len(groups["inherited"]) > 0,
FunctionName: groups["function"],
ChildNodes: []Node{},
IsLiteralLabel: len(groups["literal"]) > 0,
}
}

30 changes: 20 additions & 10 deletions ast/asm_label_attr_test.go
Original file line number Diff line number Diff line change
@@ -7,18 +7,28 @@ import (
func TestAsmLabelAttr(t *testing.T) {
nodes := map[string]Node{
`0x7ff26d8224e8 </usr/include/sys/cdefs.h:569:36> "_fopen"`: &AsmLabelAttr{
Addr: 0x7ff26d8224e8,
Pos: NewPositionFromString("/usr/include/sys/cdefs.h:569:36"),
Inherited: false,
FunctionName: "_fopen",
ChildNodes: []Node{},
Addr: 0x7ff26d8224e8,
Pos: NewPositionFromString("/usr/include/sys/cdefs.h:569:36"),
Inherited: false,
FunctionName: "_fopen",
ChildNodes: []Node{},
IsLiteralLabel: false,
},
`0x7fd55a169318 </usr/include/stdio.h:325:47> Inherited "_popen"`: &AsmLabelAttr{
Addr: 0x7fd55a169318,
Pos: NewPositionFromString("/usr/include/stdio.h:325:47"),
Inherited: true,
FunctionName: "_popen",
ChildNodes: []Node{},
Addr: 0x7fd55a169318,
Pos: NewPositionFromString("/usr/include/stdio.h:325:47"),
Inherited: true,
FunctionName: "_popen",
ChildNodes: []Node{},
IsLiteralLabel: false,
},
`0x559fea32f5f0 <line:407:94> "__isoc99_fscanf" IsLiteralLabel`: &AsmLabelAttr{
Addr: 0x559fea32f5f0,
Pos: NewPositionFromString("line:407:94"),
Inherited: false,
FunctionName: "__isoc99_fscanf",
ChildNodes: []Node{},
IsLiteralLabel: true,
},
}

Loading