ffi-clang 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Njk3ODJkZDU2YzlmODI2YTQ2ZmJiYzI5ZjE2OWY5MWEyZDAwNWM5Ng==
4
+ MDE1NGQxNDVlMTM4Mjk5YTMyOGM5MmI2MjY1YWI4ODQ0NTc1YjZmYw==
5
5
  data.tar.gz: !binary |-
6
- NDEzNjk5MzM0NmJjY2M4NDVjMjBlNjc3Y2M5Y2QwOTdiZGRiMGRiOA==
6
+ NjYwNTIxYTcwYjc0M2I1NjE5NTU3YWRkYTAwMmQxMTg5N2NiZmE0Nw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NmViOGUxYWIwNDJmMWEyMTk1ZDkzODA3NmQwNTEyMmRkODI5YmM0ZmNhYWM2
10
- OWI2NjdkMGMwMTU0MGNkOWJiYTA4YzVhZGEzNjZhMjExMjU3ZGE4Yjg0ZTI3
11
- MWJiOWFiZWY4NWQ3NTE4NjQ3NTAyMThmOWFjNzFiZjI0NDk2OGQ=
9
+ MGVjMjcwMTg2NDU5MGRmYjgxMzNiYzU5MjY5NzY4OTI1ZDBkZTU0ZDBlNmEx
10
+ N2RjYzg5NjdjM2E1YWRhNTdiMzk1ZTAzNTAzOTU4MTc3YmRhYmM3YzUwMWFm
11
+ ZTA2OWQ4ODU3Y2JlMzdmNzQ1ZmM4NWRiNmIwNzIwNDE5Y2NkYjU=
12
12
  data.tar.gz: !binary |-
13
- ZDQyZWRiYzhiYjcxYmYyYjc2OGNiNDM1MTMyNWVkMmRjMjgwMDgyNDNiNmNj
14
- OTU2YWU5NWVkNzgzMjBmM2YzMDQ4ZjU4ZDkxOWIwMTI2ODNiNmI2MjY3ZTIw
15
- YTI4MDM2MzZlNzUxNmQ4MTEyNmZlMzMxYzIzNTI0ZmNiOWE1YWE=
13
+ MzlhMDM1OGViZmZmOGRkNTMzODA5ZjM2OTdlZDBlMmMyNjQyOTg2NGE0MWRj
14
+ MjY1ZDQyMTBjMzM0YjA3OTg3Yjg5OTdmNzdiODg5YmFkMDExOWY0MGU1M2Vh
15
+ NGRiNGFhY2QwNTE3NDlmZjM1MDQ4MGU3NWM0MWQ4YzliNWIzMDc=
@@ -0,0 +1,135 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright, 2013, by Carlos Martín Nieto <cmn@dwim.me>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+
22
+ require 'ffi/clang/lib/cursor'
23
+ require 'ffi/clang/lib/comment'
24
+ require 'ffi/clang/source_location'
25
+
26
+ module FFI
27
+ module Clang
28
+
29
+ class Comment
30
+ include Enumerable
31
+
32
+ def self.build_from(comment)
33
+ kind = Lib.comment_get_kind(comment)
34
+ case kind
35
+ when :comment_full
36
+ FullComment.new comment
37
+ when :comment_paragraph
38
+ ParagraphComment.new comment
39
+ when :comment_text
40
+ TextComment.new comment
41
+ when :comment_block_command
42
+ BlockCommandComment.new comment
43
+ when :comment_param_command
44
+ ParamCommandComment.new comment
45
+ when :comment_null
46
+ Comment.new comment
47
+ else
48
+ raise NotImplementedError, kind
49
+ end
50
+ end
51
+
52
+ def initialize(comment)
53
+ @comment = comment
54
+ end
55
+
56
+ def kind
57
+ Lib.comment_get_kind(@comment)
58
+ end
59
+
60
+ def num_children
61
+ Lib.comment_get_num_children(@comment)
62
+ end
63
+
64
+ def child(n = 0)
65
+ Comment.build_from Lib.comment_get_child(@comment, n)
66
+ end
67
+
68
+ def each(&block)
69
+ (0..num_children-1).map do |i|
70
+ block.call(child(i))
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ class ParagraphComment < Comment
77
+ def text
78
+ self.map(&:text).join("\n")
79
+ end
80
+ end
81
+
82
+ class TextComment < Comment
83
+ def text
84
+ Lib.extract_string Lib.text_comment_get_text(@comment)
85
+ end
86
+ end
87
+
88
+ class BlockCommandComment < Comment
89
+ def name
90
+ Lib.extract_string Lib.block_command_comment_get_command_name(@comment)
91
+ end
92
+
93
+ def paragraph
94
+ Comment.build_from Lib.block_command_comment_get_paragraph(@comment)
95
+ end
96
+
97
+ def comment
98
+ self.paragraph.text
99
+ end
100
+
101
+ def num_args
102
+ Lib.block_command_comment_get_num_args(@comment)
103
+ end
104
+ end
105
+
106
+ class ParamCommandComment < Comment
107
+ def name
108
+ Lib.extract_string Lib.param_command_comment_get_param_name(@comment)
109
+ end
110
+
111
+ def comment
112
+ self.child.text
113
+ end
114
+
115
+ def valid_index?
116
+ Lib.param_command_comment_is_param_index_valid(@comment) != 0
117
+ end
118
+
119
+ def index
120
+ Lib.param_command_comment_get_param_index(@comment)
121
+ end
122
+ end
123
+
124
+ class FullComment < Comment
125
+ def to_html
126
+ Lib.extract_string Lib.full_comment_get_as_html(@comment)
127
+ end
128
+
129
+ def to_xml
130
+ Lib.extract_string Lib.full_comment_get_as_xml(@comment)
131
+ end
132
+ end
133
+
134
+ end
135
+ end
@@ -21,6 +21,7 @@
21
21
 
22
22
  require 'ffi/clang/lib/cursor'
23
23
  require 'ffi/clang/source_location'
24
+ require 'ffi/clang/comment'
24
25
 
25
26
  module FFI
26
27
  module Clang
@@ -37,6 +38,14 @@ module FFI
37
38
  Lib.cursor_is_null(@cursor) != 0
38
39
  end
39
40
 
41
+ def raw_comment_text
42
+ Lib.extract_string Lib.cursor_get_raw_comment_text(@cursor)
43
+ end
44
+
45
+ def comment
46
+ Comment.build_from Lib.cursor_get_parsed_comment(@cursor)
47
+ end
48
+
40
49
  def declaration?
41
50
  Lib.is_declaration(kind) != 0
42
51
  end
@@ -0,0 +1,56 @@
1
+ # Copyright, 2010-2012 by Jari Bakken.
2
+ # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+
22
+ require 'ffi/clang/lib/index'
23
+
24
+ module FFI
25
+ module Clang
26
+ module Lib
27
+ class CXComment < FFI::Struct
28
+ layout(
29
+ :ast_node, :pointer,
30
+ :translation_unit, :pointer
31
+ )
32
+ end
33
+
34
+ enum :kind, [:comment_null, 0,
35
+ :comment_text, 1,
36
+ :comment_paragraph, 5,
37
+ :comment_block_command,6 ,
38
+ :comment_param_command, 7,
39
+ :comment_full, 12]
40
+
41
+ attach_function :comment_get_kind, :clang_Comment_getKind, [CXComment.by_value], :kind
42
+ attach_function :comment_get_num_children, :clang_Comment_getNumChildren, [CXComment.by_value], :uint
43
+ attach_function :comment_get_child, :clang_Comment_getChild, [CXComment.by_value, :uint], CXComment.by_value
44
+ attach_function :text_comment_get_text, :clang_TextComment_getText, [CXComment.by_value], CXString.by_value
45
+ attach_function :block_command_comment_get_paragraph, :clang_BlockCommandComment_getParagraph, [CXComment.by_value], CXComment.by_value
46
+ attach_function :full_comment_get_as_html, :clang_FullComment_getAsHTML, [CXComment.by_value], CXString.by_value
47
+ attach_function :full_comment_get_as_xml, :clang_FullComment_getAsXML, [CXComment.by_value], CXString.by_value
48
+
49
+ attach_function :param_command_comment_get_param_name, :clang_ParamCommandComment_getParamName, [CXComment.by_value], CXString.by_value
50
+ attach_function :param_command_comment_is_param_index_valid, :clang_ParamCommandComment_isParamIndexValid, [CXComment.by_value], :uint
51
+ attach_function :param_command_comment_get_param_index, :clang_ParamCommandComment_getParamIndex, [CXComment.by_value], :uint
52
+ attach_function :block_command_comment_get_command_name, :clang_BlockCommandComment_getCommandName, [CXComment.by_value], CXString.by_value
53
+ attach_function :block_command_comment_get_num_args, :clang_BlockCommandComment_getNumArgs, [CXComment.by_value], :uint
54
+ end
55
+ end
56
+ end
@@ -22,12 +22,17 @@
22
22
 
23
23
  require 'ffi/clang/lib/translation_unit'
24
24
  require 'ffi/clang/lib/diagnostic'
25
+ require 'ffi/clang/lib/comment'
25
26
 
26
27
  module FFI
27
28
  module Clang
28
29
  module Lib
29
30
  enum :kind, [:cursor_struct, 2,
31
+ :cursor_enum_decl, 5,
32
+ :cursor_enum_constant_decl, 7,
30
33
  :cursor_function, 8,
34
+ :cursor_parm_decl, 10,
35
+ :cursor_typedef_decl, 20,
31
36
  :cursor_invalid_file, 70,
32
37
  :cursor_translation_unit, 300]
33
38
 
@@ -45,6 +50,9 @@ module FFI
45
50
 
46
51
  attach_function :cursor_is_null, :clang_Cursor_isNull, [CXCursor.by_value], :int
47
52
 
53
+ attach_function :cursor_get_raw_comment_text, :clang_Cursor_getRawCommentText, [CXCursor.by_value], CXString.by_value
54
+ attach_function :cursor_get_parsed_comment, :clang_Cursor_getParsedComment, [CXCursor.by_value], CXComment.by_value
55
+
48
56
  attach_function :get_cursor_location, :clang_getCursorLocation, [CXCursor.by_value], CXSourceLocation.by_value
49
57
  attach_function :get_cursor_extent, :clang_getCursorExtent, [CXCursor.by_value], CXSourceRange.by_value
50
58
  attach_function :get_cursor_display_name, :clang_getCursorDisplayName, [CXCursor.by_value], CXString.by_value
@@ -21,6 +21,6 @@
21
21
 
22
22
  module FFI
23
23
  module Clang
24
- VERSION = "0.1.1"
24
+ VERSION = "0.1.2"
25
25
  end
26
26
  end
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright, 2013, by Carlos Martín Nieto <cmn@dwim.me>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+
22
+ require 'spec_helper'
23
+
24
+ describe Comment do
25
+ let(:cursor) { Index.new.parse_translation_unit(fixture_path("docs.h")).cursor }
26
+ let (:comment) { find_first(cursor, :cursor_function).comment }
27
+
28
+ it "can be obtained from a cursor" do
29
+ comment.should be_kind_of(Comment)
30
+ comment.should be_kind_of(FullComment)
31
+ comment.kind.should equal(:comment_full)
32
+ end
33
+
34
+ it "can parse the brief description" do
35
+ para = comment.child
36
+ para.kind.should equal(:comment_paragraph)
37
+ para.should be_kind_of(ParagraphComment)
38
+ text = para.child
39
+ text.kind.should equal(:comment_text)
40
+ text.should be_kind_of(TextComment)
41
+ text.text.strip.should eq("Short explanation")
42
+ end
43
+
44
+ it "can parse the longer description" do
45
+ para = comment.child(1)
46
+ para.kind.should equal(:comment_paragraph)
47
+ para.num_children.should equal(2)
48
+ text = para.child
49
+
50
+ lines = (0..para.num_children-1).map do |i|
51
+ para.child(i).text
52
+ end
53
+
54
+ lines.should eq([" This is a longer explanation",
55
+ " that spans multiple lines"])
56
+ end
57
+
58
+ it "has working helpers" do
59
+ comment.num_children.should equal(6)
60
+
61
+ para = comment.child(1)
62
+ para.text.should eq(" This is a longer explanation\n that spans multiple lines")
63
+ end
64
+
65
+ it "understands params" do
66
+ param = comment.child(3)
67
+ param.should be_kind_of(ParamCommandComment)
68
+
69
+ param.valid_index?.should == true
70
+ param.index.should equal(0)
71
+ param.name.should eq("input")
72
+ arg = " some input\n "
73
+ param.child.text.should eq(arg)
74
+ param.comment.should eq(arg)
75
+ end
76
+
77
+ it "understands blocks" do
78
+ block = comment.child(5)
79
+ block.should be_kind_of(BlockCommandComment)
80
+ block.name.should eq("return")
81
+ block.comment.should eq(" a random value\n ")
82
+ end
83
+
84
+ end
@@ -22,21 +22,6 @@
22
22
 
23
23
  require 'spec_helper'
24
24
 
25
- def find_first(cursor, kind)
26
- first = nil
27
-
28
- cursor.visit_children do |cursor, parent|
29
- if (cursor.kind == kind)
30
- first = cursor
31
- :break
32
- else
33
- :recurse
34
- end
35
- end
36
-
37
- first
38
- end
39
-
40
25
  describe Cursor do
41
26
  let(:cursor) { Index.new.parse_translation_unit(fixture_path("list.c")).cursor }
42
27
 
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Short explanation
3
+ *
4
+ * This is a longer explanation
5
+ * that spans multiple lines
6
+ *
7
+ * @param input some input
8
+ * @param flags some flags
9
+ * @return a random value
10
+ */
11
+ int a_function(char *input, int flags);
@@ -7,6 +7,21 @@ module ClangSpecHelper
7
7
  def fixture_path(path)
8
8
  File.join File.expand_path("../fixtures", __FILE__), path
9
9
  end
10
+
11
+ def find_first(cursor, kind)
12
+ first = nil
13
+
14
+ cursor.visit_children do |cursor, parent|
15
+ if (cursor.kind == kind)
16
+ first = cursor
17
+ :break
18
+ else
19
+ :recurse
20
+ end
21
+ end
22
+
23
+ first
24
+ end
10
25
  end
11
26
 
12
27
  RSpec.configure do |c|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-clang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-28 00:00:00.000000000 Z
12
+ date: 2013-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -83,10 +83,12 @@ files:
83
83
  - Rakefile
84
84
  - ffi-clang.gemspec
85
85
  - lib/ffi/clang.rb
86
+ - lib/ffi/clang/comment.rb
86
87
  - lib/ffi/clang/cursor.rb
87
88
  - lib/ffi/clang/diagnostic.rb
88
89
  - lib/ffi/clang/index.rb
89
90
  - lib/ffi/clang/lib.rb
91
+ - lib/ffi/clang/lib/comment.rb
90
92
  - lib/ffi/clang/lib/cursor.rb
91
93
  - lib/ffi/clang/lib/diagnostic.rb
92
94
  - lib/ffi/clang/lib/file.rb
@@ -100,12 +102,14 @@ files:
100
102
  - lib/ffi/clang/translation_unit.rb
101
103
  - lib/ffi/clang/unsaved_file.rb
102
104
  - lib/ffi/clang/version.rb
105
+ - spec/clang/comment_spec.rb
103
106
  - spec/clang/cursor_spec.rb
104
107
  - spec/clang/diagnostic_spec.rb
105
108
  - spec/clang/index_spec.rb
106
109
  - spec/clang/source_location_spec.rb
107
110
  - spec/clang/translation_unit_spec.rb
108
111
  - spec/fixtures/a.c
112
+ - spec/fixtures/docs.h
109
113
  - spec/fixtures/list.c
110
114
  - spec/spec_helper.rb
111
115
  homepage: ''
@@ -133,11 +137,13 @@ signing_key:
133
137
  specification_version: 4
134
138
  summary: Ruby FFI bindings for libclang C interface.
135
139
  test_files:
140
+ - spec/clang/comment_spec.rb
136
141
  - spec/clang/cursor_spec.rb
137
142
  - spec/clang/diagnostic_spec.rb
138
143
  - spec/clang/index_spec.rb
139
144
  - spec/clang/source_location_spec.rb
140
145
  - spec/clang/translation_unit_spec.rb
141
146
  - spec/fixtures/a.c
147
+ - spec/fixtures/docs.h
142
148
  - spec/fixtures/list.c
143
149
  - spec/spec_helper.rb