ffi-clang 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +4 -0
  3. data/ext/rakefile.rb +4 -0
  4. data/ext/teapot.rb +4 -3
  5. data/lib/ffi/clang/clang_version.rb +9 -19
  6. data/lib/ffi/clang/code_completion.rb +4 -18
  7. data/lib/ffi/clang/comment.rb +7 -19
  8. data/lib/ffi/clang/compilation_database.rb +4 -18
  9. data/lib/ffi/clang/cursor.rb +70 -25
  10. data/lib/ffi/clang/diagnostic.rb +8 -21
  11. data/lib/ffi/clang/file.rb +4 -18
  12. data/lib/ffi/clang/index.rb +9 -20
  13. data/lib/ffi/clang/lib/clang_version.rb +5 -19
  14. data/lib/ffi/clang/lib/code_completion.rb +4 -18
  15. data/lib/ffi/clang/lib/comment.rb +7 -20
  16. data/lib/ffi/clang/lib/compilation_database.rb +4 -18
  17. data/lib/ffi/clang/lib/cursor.rb +34 -23
  18. data/lib/ffi/clang/lib/diagnostic.rb +7 -20
  19. data/lib/ffi/clang/lib/file.rb +5 -20
  20. data/lib/ffi/clang/lib/inclusions.rb +5 -19
  21. data/lib/ffi/clang/lib/index.rb +6 -20
  22. data/lib/ffi/clang/lib/source_location.rb +5 -20
  23. data/lib/ffi/clang/lib/source_range.rb +5 -22
  24. data/lib/ffi/clang/lib/string.rb +6 -20
  25. data/lib/ffi/clang/lib/token.rb +4 -18
  26. data/lib/ffi/clang/lib/translation_unit.rb +6 -20
  27. data/lib/ffi/clang/lib/type.rb +8 -20
  28. data/lib/ffi/clang/lib.rb +15 -20
  29. data/lib/ffi/clang/source_location.rb +7 -20
  30. data/lib/ffi/clang/source_range.rb +7 -22
  31. data/lib/ffi/clang/token.rb +4 -18
  32. data/lib/ffi/clang/translation_unit.rb +10 -20
  33. data/lib/ffi/clang/type.rb +7 -19
  34. data/lib/ffi/clang/unsaved_file.rb +6 -20
  35. data/lib/ffi/clang/version.rb +7 -21
  36. data/lib/ffi/clang.rb +9 -20
  37. data/license.md +38 -0
  38. data/readme.md +46 -0
  39. data.tar.gz.sig +0 -0
  40. metadata +71 -73
  41. metadata.gz.sig +2 -0
  42. data/.editorconfig +0 -23
  43. data/.gitignore +0 -19
  44. data/.rspec +0 -5
  45. data/.travis.yml +0 -30
  46. data/Gemfile +0 -12
  47. data/README.md +0 -74
  48. data/Rakefile +0 -12
  49. data/examples/docs.cpp +0 -25
  50. data/examples/docs.rb +0 -31
  51. data/ffi-clang.gemspec +0 -25
  52. data/spec/ffi/clang/code_completion_spec.rb +0 -181
  53. data/spec/ffi/clang/comment_spec.rb +0 -453
  54. data/spec/ffi/clang/compilation_database_spec.rb +0 -180
  55. data/spec/ffi/clang/cursor_spec.rb +0 -741
  56. data/spec/ffi/clang/diagnostic_spec.rb +0 -89
  57. data/spec/ffi/clang/file_spec.rb +0 -82
  58. data/spec/ffi/clang/fixtures/a.c +0 -7
  59. data/spec/ffi/clang/fixtures/canonical.c +0 -5
  60. data/spec/ffi/clang/fixtures/class.cpp +0 -8
  61. data/spec/ffi/clang/fixtures/compile_commands.json +0 -17
  62. data/spec/ffi/clang/fixtures/completion.cxx +0 -8
  63. data/spec/ffi/clang/fixtures/docs.c +0 -1
  64. data/spec/ffi/clang/fixtures/docs.cc +0 -1
  65. data/spec/ffi/clang/fixtures/docs.h +0 -54
  66. data/spec/ffi/clang/fixtures/list.c +0 -11
  67. data/spec/ffi/clang/fixtures/location1.c +0 -7
  68. data/spec/ffi/clang/fixtures/simple.ast +0 -0
  69. data/spec/ffi/clang/fixtures/simple.c +0 -3
  70. data/spec/ffi/clang/fixtures/test.cxx +0 -62
  71. data/spec/ffi/clang/index_spec.rb +0 -90
  72. data/spec/ffi/clang/source_location_spec.rb +0 -138
  73. data/spec/ffi/clang/source_range_spec.rb +0 -74
  74. data/spec/ffi/clang/token_spec.rb +0 -82
  75. data/spec/ffi/clang/translation_unit_spec.rb +0 -220
  76. data/spec/ffi/clang/type_spec.rb +0 -273
  77. data/spec/ffi/clang/version_spec.rb +0 -28
  78. data/spec/spec_helper.rb +0 -51
@@ -1,89 +0,0 @@
1
-
2
- describe Diagnostic do
3
- let(:diagnostics) { Index.new.parse_translation_unit(fixture_path("list.c")).diagnostics }
4
- let(:diagnostic) { diagnostics.first }
5
-
6
- it "returns a string representation of the diagnostic" do
7
- str = diagnostic.format
8
- expect(str).to be_kind_of(String)
9
- expect(str).to match(/does not match previous/)
10
- end
11
-
12
- it "returns a string representation according to the given opts" do
13
- expect(diagnostic.format(:source_location => true)).to include("list.c:5")
14
- end
15
-
16
- it "returns the text of the diagnostic" do
17
- expect(diagnostic.spelling).to be_kind_of(String)
18
- end
19
-
20
- it "returns the severity of the diagnostic" do
21
- expect(diagnostic.severity).to eq(:error)
22
- end
23
-
24
- it "returns the ranges of the diagnostic" do
25
- rs = diagnostics[1].ranges
26
- expect(rs).to be_kind_of(Array)
27
- expect(rs).not_to be_empty
28
- expect(rs.first).to be_kind_of(SourceRange)
29
- end
30
-
31
- it "calls dispose_diagnostic on GC" do
32
- diagnostic.autorelease = false
33
- # expect(Lib).to receive(:dispose_diagnostic).with(diagnostic).once
34
- expect{diagnostic.free}.not_to raise_error
35
- end
36
-
37
- context "#self.default_display_opts" do
38
- it "returns the set of display options" do
39
- expect(FFI::Clang::Diagnostic.default_display_opts).to be_kind_of(Hash)
40
- expect(FFI::Clang::Diagnostic.default_display_opts.keys.map(&:class).uniq).to eq([Symbol])
41
- expect(FFI::Clang::Diagnostic.default_display_opts.values.uniq).to eq([true])
42
- end
43
- end
44
-
45
- context "#fixits" do
46
- it "returns the replacement information by Array of Hash" do
47
- expect(diagnostic.fixits).to be_kind_of(Array)
48
- expect(diagnostic.fixits.first).to be_kind_of(Hash)
49
- expect(diagnostic.fixits.first[:text]).to eq('struct')
50
- expect(diagnostic.fixits.first[:range]).to be_kind_of(SourceRange)
51
- end
52
- end
53
-
54
- context "#children" do
55
- it "returns child diagnostics by Array" do
56
- expect(diagnostic.children).to be_kind_of(Array)
57
- expect(diagnostic.children.first).to be_kind_of(Diagnostic)
58
- expect(diagnostic.children.first.severity).to eq(:note)
59
- end
60
- end
61
-
62
- context "#enable_option" do
63
- it "returns the name of the command-line option that enabled this diagnostic" do
64
- expect(diagnostics[3].enable_option).to be_kind_of(String)
65
- expect(diagnostics[3].enable_option).to eq('-Wempty-body')
66
- end
67
- end
68
-
69
- context "#disable_option" do
70
- it "returns the name of the command-line option that disables this diagnostic" do
71
- expect(diagnostics[3].disable_option).to be_kind_of(String)
72
- expect(diagnostics[3].disable_option).to eq('-Wno-empty-body')
73
- end
74
- end
75
-
76
- context "#category" do
77
- it "returns the diagnostic category text" do
78
- expect(diagnostic.category).to be_kind_of(String)
79
- expect(diagnostic.category).to eq('Semantic Issue')
80
- end
81
- end
82
-
83
- context "#category_id" do
84
- it "returns the category number" do
85
- expect(diagnostic.category_id).to be_kind_of(Integer)
86
- expect(diagnostic.category_id).to eq(2)
87
- end
88
- end
89
- end
@@ -1,82 +0,0 @@
1
- # Copyright, 2014, by Masahiro Sano.
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- describe File do
22
- let(:file_list) { Index.new.parse_translation_unit(fixture_path("list.c")).file(fixture_path("list.c")) }
23
- let(:file_docs) { Index.new.parse_translation_unit(fixture_path("docs.c")).file(fixture_path("docs.h")) }
24
-
25
- it "can be obtained from a translation unit" do
26
- expect(file_list).to be_kind_of(FFI::Clang::File)
27
- end
28
-
29
- describe "#name" do
30
- let(:name) { file_list.name }
31
-
32
- it 'returns its file name' do
33
- expect(name).to be_kind_of(String)
34
- expect(name).to eq(fixture_path("list.c"))
35
- end
36
- end
37
-
38
- describe "#to_s" do
39
- let(:name) { file_list.to_s }
40
-
41
- it 'returns its file name' do
42
- expect(name).to be_kind_of(String)
43
- expect(name).to eq(fixture_path("list.c"))
44
- end
45
- end
46
-
47
- describe "#time" do
48
- let(:time) { file_list.time }
49
-
50
- it 'returns file time' do
51
- expect(time).to be_kind_of(Time)
52
- end
53
- end
54
-
55
- describe "#include_guarded?" do
56
- it 'returns false if included file is notguarded' do
57
- expect(file_list.include_guarded?).to be false
58
- end
59
-
60
- it 'returns true if included file is guarded' do
61
- expect(file_docs.include_guarded?).to be true
62
- end
63
- end
64
-
65
- describe "#device" do
66
- it 'returns device from CXFileUniqueID' do
67
- expect(file_list.device).to be_kind_of(Integer)
68
- end
69
- end
70
-
71
- describe "#inode" do
72
- it 'returns inode from CXFileUniqueID' do
73
- expect(file_list.inode).to be_kind_of(Integer)
74
- end
75
- end
76
-
77
- describe "#modification" do
78
- it 'returns modification time as Time from CXFileUniqueID' do
79
- expect(file_list.modification).to be_kind_of(Time)
80
- end
81
- end
82
- end
@@ -1,7 +0,0 @@
1
- int main(int argc, char const *argv)
2
- {
3
- return 0;
4
- }
5
-
6
- int * volatile volatile_int_ptr;
7
- int * restrict restrict_int_ptr;
@@ -1,5 +0,0 @@
1
- struct X;
2
- struct X;
3
- struct X {
4
- int a;
5
- };
@@ -1,8 +0,0 @@
1
- struct Factory {
2
- void create();
3
- };
4
-
5
- void Factory::create()
6
- {
7
- this->create();
8
- }
@@ -1,17 +0,0 @@
1
- [
2
- {
3
- "directory": "/home/xxxxx/src/build-trunk/lib/Support",
4
- "command": "/opt/llvm/3.4/bin/clang++ -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -fno-rtti -ffunction-sections -fdata-sections -O3 -I/home/xxxxx/src/build-trunk/lib/Support -I/home/xxxxx/src/llvm-trunk/lib/Support -I/home/xxxxx/src/build-trunk/include -I/home/xxxxx/src/llvm-trunk/include -UNDEBUG -fno-exceptions -o CMakeFiles/LLVMSupport.dir/APFloat.cpp.o -c /home/xxxxx/src/llvm-trunk/lib/Support/APFloat.cpp",
5
- "file": "/home/xxxxx/src/llvm-trunk/lib/Support/APFloat.cpp"
6
- },
7
- {
8
- "directory": "/home/xxxxx/src/build-trunk/lib/Support",
9
- "command": "/opt/llvm/3.4/bin/clang++ -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -fno-rtti -ffunction-sections -fdata-sections -O3 -I/home/xxxxx/src/build-trunk/lib/Support -I/home/xxxxx/src/llvm-trunk/lib/Support -I/home/xxxxx/src/build-trunk/include -I/home/xxxxx/src/llvm-trunk/include -UNDEBUG -fno-exceptions -o CMakeFiles/LLVMSupport.dir/APInt.cpp.o -c /home/xxxxx/src/llvm-trunk/lib/Support/APInt.cpp",
10
- "file": "/home/xxxxx/src/llvm-trunk/lib/Support/APInt.cpp"
11
- },
12
- {
13
- "directory": "/home/xxxxx/src/build-trunk/lib/Support",
14
- "command": "/opt/llvm/3.4/bin/clang++ -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -fno-rtti -ffunction-sections -fdata-sections -O3 -I/home/xxxxx/src/build-trunk/lib/Support -I/home/xxxxx/src/llvm-trunk/lib/Support -I/home/xxxxx/src/build-trunk/include -I/home/xxxxx/src/llvm-trunk/include -UNDEBUG -fno-exceptions -o CMakeFiles/LLVMSupport.dir/APSInt.cpp.o -c /home/xxxxx/src/llvm-trunk/lib/Support/APSInt.cpp",
15
- "file": "/home/xxxxx/src/llvm-trunk/lib/Support/APSInt.cpp"
16
- }
17
- ]
@@ -1,8 +0,0 @@
1
- #include <vector>
2
-
3
- std::vector<int> v1;
4
- std::vector<> v2;
5
-
6
- int main(void) {
7
- v1.
8
- }
@@ -1 +0,0 @@
1
- #include "docs.h"
@@ -1 +0,0 @@
1
- #include "docs.h"
@@ -1,54 +0,0 @@
1
- #ifndef DOCS_H
2
- #define DOCS_H
3
-
4
- /**
5
- * Short explanation
6
- *
7
- * This is a longer explanation
8
- * that spans multiple lines
9
- *
10
- * @param[in] input some input
11
- * @param[out] flags some flags
12
- * @param[in,out] buf some input and output buffer
13
- * @param option some option
14
- * @return a random value
15
- */
16
- int a_function(char *input, int *flags, char *buf, int option);
17
-
18
- int no_comment_function(void);
19
-
20
- /**
21
- * <br />
22
- * <a href="http://example.org/">
23
- * </a>
24
- */
25
- void b_function(void);
26
-
27
- /**
28
- * @tparam T1 some type of foo
29
- * @tparam T2 some type of bar
30
- * @tparam T3 some type of baz
31
- */
32
- template<typename T1, template<typename T2> class T3>
33
- void c_function(T3<int> xxx);
34
-
35
- /**
36
- * abc \em foo \b bar
37
- */
38
- void d_function(void);
39
-
40
- /**
41
- * \verbatim
42
- * foo bar
43
- * baz
44
- * \endverbatim
45
- */
46
- void e_function(void);
47
-
48
- /**
49
- * \brief this is a function.
50
- */
51
- int f_function(void);
52
-
53
-
54
- #endif
@@ -1,11 +0,0 @@
1
- struct List {
2
- int Data;
3
- struct List *Next;
4
- };
5
- int sum(union List *L) { return 1; };
6
-
7
- main(int argc, char const *argv)
8
- {
9
- if (0 == 1);
10
- return 0;
11
- }
@@ -1,7 +0,0 @@
1
- #123 "dummy.c" 1
2
-
3
- static int func(void)
4
- {
5
- return 0;
6
- }
7
-
Binary file
@@ -1,3 +0,0 @@
1
- int main(void) {
2
- return 0;
3
- }
@@ -1,62 +0,0 @@
1
- struct A {
2
- virtual int func_a() = 0;
3
- int int_member_a;
4
- };
5
-
6
- struct B : public virtual A {
7
- int func_a() { return 0; }
8
-
9
- static int func_b() { return 11; }
10
- };
11
-
12
- struct C : public virtual A {
13
- int func_a() { return 1; }
14
-
15
- enum { EnumC = 100 };
16
- };
17
-
18
- struct D : public B, public C {
19
- private:
20
- int func_a() { return B::func_a(); }
21
- void func_d();
22
-
23
- int private_member_int;
24
- public:
25
- int public_member_int;
26
- protected:
27
- int protected_member_int;
28
- };
29
-
30
- void D::func_d() {};
31
- f_dynamic_call(A *a) { a->func_a(); };
32
-
33
- void f_variadic(int a, ...);
34
- void f_non_variadic(int a, char b, long c);
35
-
36
- typedef int const* const_int_ptr;
37
- int int_array[8];
38
-
39
- struct RefQualifier {
40
- void func_lvalue_ref() &;
41
- void func_rvalue_ref() &&;
42
- void func_none();
43
- };
44
-
45
- int A::*member_pointer = &A::int_member_a;
46
-
47
- struct BitField {
48
- int bit_field_a : 2;
49
- int bit_field_b : 6;
50
- int non_bit_field_c;
51
- };
52
-
53
- enum normal_enum {
54
- normal_enum_a
55
- };
56
-
57
- template <typename T> T func_overloaded(T a) { return a;};
58
- template <typename T> T func_overloaded() { return 100;};
59
- template <typename T> T use_func_overloaded() { return func_overloaded<T>(); };
60
- int use_overloaded_int_a = func_overloaded<int>();
61
-
62
- void availability_func(void) __attribute__((availability(macosx,introduced=10.4.1,deprecated=10.6,obsoleted=10.7)));
@@ -1,90 +0,0 @@
1
- # Copyright, 2014, by Masahiro Sano.
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- describe Index do
22
- before :all do
23
- FileUtils.mkdir_p TMP_DIR
24
- end
25
-
26
- after :all do
27
- # FileUtils.rm_rf TMP_DIR
28
- end
29
-
30
- let(:index) { Index.new }
31
-
32
- it "calls dispose_index on GC" do
33
- index.autorelease = false
34
- # It's possible for this to be called multiple times if there are other Index instances created during test
35
- # expect(Lib).to receive(:dispose_index).with(index).once
36
- expect{index.free}.not_to raise_error
37
- end
38
-
39
- describe '#parse_translation_unit' do
40
- it "can parse a source file" do
41
- translation_unit = index.parse_translation_unit fixture_path("a.c")
42
- expect(translation_unit).to be_kind_of(TranslationUnit)
43
- end
44
-
45
- it "raises error when file is not found" do
46
- expect { index.parse_translation_unit fixture_path("xxxxxxxxx.c") }.to raise_error(FFI::Clang::Error)
47
- end
48
-
49
- it "can handle command line options" do
50
- expect{index.parse_translation_unit(fixture_path("a.c"), ["-std=c++11"])}.not_to raise_error
51
- end
52
-
53
- it 'can handle translation unit options' do
54
- expect{index.parse_translation_unit(fixture_path("a.c"), [], [], [:incomplete, :single_file_parse, :cache_completion_results])}.not_to raise_error
55
- end
56
-
57
- it 'can handle missing translation options' do
58
- expect{index.parse_translation_unit(fixture_path("a.c"), [], [], [])}.not_to raise_error
59
- end
60
-
61
- it 'can handle translation options with random values' do
62
- expect{index.parse_translation_unit(fixture_path("a.c"), [], [], {:incomplete => 654, :single_file_parse => 8, :cache_completion_results => 93})}.not_to raise_error
63
- end
64
-
65
- it "raises error when one of the translation options is invalid" do
66
- expect{index.parse_translation_unit(fixture_path("a.c"), [], [], [:incomplete, :random_option, :cache_completion_results])}.to raise_error(FFI::Clang::Error)
67
- end
68
- end
69
-
70
- describe '#create_translation_unit' do
71
- let(:simple_ast_path) {"#{TMP_DIR}/simple.ast"}
72
-
73
- before :each do
74
- translation_unit = index.parse_translation_unit fixture_path("simple.c")
75
-
76
- translation_unit.save(simple_ast_path)
77
- end
78
-
79
- it "can create translation unit from a ast file" do
80
- expect(FileTest.exist?("#{TMP_DIR}/simple.ast")).to be true
81
- translation_unit = index.create_translation_unit "#{TMP_DIR}/simple.ast"
82
- expect(translation_unit).to be_kind_of(TranslationUnit)
83
- end
84
-
85
- it "raises error when file is not found" do
86
- expect(FileTest.exist?('not_found.ast')).to be false
87
- expect { index.create_translation_unit 'not_found.ast' }.to raise_error(FFI::Clang::Error)
88
- end
89
- end
90
- end
@@ -1,138 +0,0 @@
1
- # Copyright, 2010-2012 by Jari Bakken.
2
- # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
- # Copyright, 2013, by Garry C. Marshall. <http://www.meaningfulname.net>
4
- # Copyright, 2014, by Masahiro Sano.
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
-
24
- describe SourceLocation do
25
- let(:translation_unit) { Index.new.parse_translation_unit(fixture_path("list.c")) }
26
- let(:translation_unit_location) { translation_unit.cursor.location }
27
- let(:diagnostic_location) { translation_unit.diagnostics.first.location }
28
- let(:loc1_translation_unit) { Index.new.parse_translation_unit(fixture_path("location1.c")) }
29
- let(:loc1_cursor) { find_first(loc1_translation_unit.cursor, :cursor_function) }
30
- let(:docs_cursor) { Index.new.parse_translation_unit(fixture_path("docs.c")).cursor }
31
-
32
- it "should have a nil File if the SourceLocation is for a Translation Unit" do
33
- expect(translation_unit_location.file).to be_nil
34
- end
35
-
36
- it "should provide a File, line and column for a Diagnostic" do
37
- expect(diagnostic_location.file).to eq(fixture_path("list.c"))
38
- expect(diagnostic_location.line).to equal(5)
39
- expect(diagnostic_location.column).to equal(9)
40
- end
41
-
42
- it "should be ExpansionLocation" do
43
- expect(translation_unit_location).to be_kind_of(SourceLocation)
44
- expect(translation_unit_location).to be_kind_of(ExpansionLocation)
45
- end
46
-
47
- describe "Null Location" do
48
- let(:null_location) { SourceLocation.null_location }
49
- it "can be a null location" do
50
- expect(null_location).to be_kind_of(SourceLocation)
51
- expect(null_location.file).to be_nil
52
- expect(null_location.line).to eq(0)
53
- expect(null_location.column).to eq(0)
54
- expect(null_location.offset).to eq(0)
55
- end
56
-
57
- it "is null?" do
58
- expect(null_location.null?).to equal(true)
59
- end
60
-
61
- it "compares as equal to another null location instance" do
62
- expect(null_location).to eq(SourceLocation.null_location)
63
- end
64
- end
65
-
66
- describe "#from_main_file?" do
67
- it "returns true if the cursor location is in main file" do
68
- expect(loc1_cursor.location.from_main_file?).to be true
69
- end
70
-
71
- it "returns false if the cursor location is not in main file" do
72
- expect(docs_cursor.location.from_main_file?).to be false
73
- end
74
- end
75
-
76
- describe "#in_system_header?" do
77
- it "returns false if the cursor location is not in system header" do
78
- expect(loc1_cursor.location.in_system_header?).to be false
79
- end
80
- end
81
-
82
- describe "#expansion_location" do
83
- let (:expansion_location) { loc1_cursor.location.expansion_location }
84
-
85
- it "should be ExpansionLocaion" do
86
- expect(expansion_location).to be_kind_of(SourceLocation)
87
- expect(expansion_location).to be_kind_of(ExpansionLocation)
88
- end
89
-
90
- it "returns source location that does not care a # line directive" do
91
- expect(expansion_location.line).to eq(3)
92
- end
93
- end
94
-
95
- describe "#presumed_location" do
96
- let (:presumed_location) { loc1_cursor.location.presumed_location }
97
-
98
- it "should be FileLocaion" do
99
- expect(presumed_location).to be_kind_of(SourceLocation)
100
- expect(presumed_location).to be_kind_of(PresumedLocation)
101
- end
102
-
103
- it "returns preprocessed filename" do
104
- expect(presumed_location.filename).to eq("dummy.c")
105
- end
106
-
107
- it "returns source location specified by a # line directive" do
108
- expect(presumed_location.line).to eq(124)
109
- end
110
- end
111
-
112
- describe "#file_location" do
113
- let (:file_location) { loc1_cursor.location.file_location }
114
-
115
- it "should be FileLocaion" do
116
- expect(file_location).to be_kind_of(SourceLocation)
117
- expect(file_location).to be_kind_of(FileLocation)
118
- end
119
-
120
- it "returns source location that does not care a # line directive" do
121
- expect(file_location.line).to eq(3)
122
- end
123
- end
124
-
125
- describe "#spelling_location" do
126
- let (:spelling_location) { loc1_cursor.location.spelling_location }
127
-
128
- it "should be SpellingLocaion" do
129
- expect(spelling_location).to be_kind_of(SourceLocation)
130
- expect(spelling_location).to be_kind_of(SpellingLocation)
131
- end
132
-
133
- it "returns source location that does not care a # line directive" do
134
- expect(spelling_location.line).to eq(3)
135
- end
136
- end
137
-
138
- end
@@ -1,74 +0,0 @@
1
- # Copyright, 2014, by Masahiro Sano.
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- describe SourceRange do
22
- let(:translation_unit) { Index.new.parse_translation_unit(fixture_path("list.c")) }
23
- let(:translation_unit_range) { translation_unit.cursor.extent }
24
-
25
- it "can be obtained from a cursor" do
26
- expect(translation_unit_range).to be_kind_of(SourceRange)
27
- expect(translation_unit_range.null?).to be false
28
- end
29
-
30
- it "has start and end source location" do
31
- expect(translation_unit_range.start).to be_kind_of(SourceLocation)
32
- expect(translation_unit_range.start.null?).to be false
33
- expect(translation_unit_range.end).to be_kind_of(SourceLocation)
34
- expect(translation_unit_range.end.null?).to be false
35
- end
36
-
37
- describe "Null Range" do
38
- let(:null_range) { SourceRange.null_range }
39
- it "can be a null range" do
40
- expect(null_range).to be_kind_of(SourceRange)
41
- end
42
-
43
- it "is null?" do
44
- expect(null_range.null?).to equal(true)
45
- end
46
-
47
- it "has null locations" do
48
- expect(null_range.start.null?).to be true
49
- expect(null_range.end.null?).to be true
50
- end
51
-
52
- it "compares as equal to another null range instance" do
53
- expect(null_range).to eq(SourceRange.null_range)
54
- end
55
- end
56
-
57
- describe "Get Range" do
58
- let(:range) { SourceRange.new(translation_unit_range.start, translation_unit_range.end) }
59
-
60
- it "can be obtained from two source locations" do
61
- expect(range).to be_kind_of(SourceRange)
62
- expect(range.null?).to be false
63
- end
64
-
65
- it "is same to original source range" do
66
- expect(range).to eq(translation_unit_range)
67
- end
68
-
69
- it "is same to original source range's locations" do
70
- expect(range.start).to eq(translation_unit_range.start)
71
- expect(range.end).to eq(translation_unit_range.end)
72
- end
73
- end
74
- end