cast 0.2.1 → 0.3.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.
- checksums.yaml +7 -0
- data/CHANGELOG +6 -1
- data/Gemfile +8 -1
- data/README.markdown +144 -168
- data/Rakefile +2 -2
- data/cast.gemspec +0 -3
- data/ext/yylex.re +19 -3
- data/lib/cast/c_nodes.rb +1 -0
- data/lib/cast/node_list.rb +9 -9
- data/lib/cast/preprocessor.rb +7 -20
- data/lib/cast/to_s.rb +38 -2
- data/lib/cast/version.rb +1 -1
- data/test/c_nodes_test.rb +2 -2
- data/test/lexer_test.rb +20 -8
- data/test/node_list_test.rb +18 -18
- data/test/node_test.rb +44 -44
- data/test/parse_test.rb +634 -634
- data/test/parser_test.rb +31 -31
- data/test/preprocessor_test.rb +13 -15
- data/test/render_test.rb +34 -4
- data/test/test_helper.rb +8 -5
- metadata +11 -51
data/test/parser_test.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
require 'test_helper'
|
8
8
|
|
9
|
-
class ParserTest < Test
|
9
|
+
class ParserTest < Minitest::Test
|
10
10
|
def check(s)
|
11
11
|
check_ast(s){|inp| @parser.parse(inp)}
|
12
12
|
end
|
@@ -95,8 +95,8 @@ TranslationUnit
|
|
95
95
|
- Declarator
|
96
96
|
name: "i"
|
97
97
|
EOS
|
98
|
-
|
99
|
-
|
98
|
+
assert_raises(C::ParseError){C::Parser.new.parse("")}
|
99
|
+
assert_raises(C::ParseError){C::Parser.new.parse(";")}
|
100
100
|
end
|
101
101
|
|
102
102
|
def test_external_declaration
|
@@ -151,31 +151,31 @@ TranslationUnit
|
|
151
151
|
name: "main"
|
152
152
|
EOS
|
153
153
|
# non-function type
|
154
|
-
|
154
|
+
assert_raises(C::ParseError){C::Parser.new.parse("int f {}")}
|
155
155
|
|
156
156
|
# both prototype and declist
|
157
|
-
|
158
|
-
|
157
|
+
assert_raises(C::ParseError){C::Parser.new.parse("void f(int argc, int argv) int argc, argv; {}")}
|
158
|
+
assert_raises(C::ParseError){C::Parser.new.parse("void f(int argc, argv) int argv; {}")}
|
159
159
|
|
160
160
|
# bad param name
|
161
|
-
|
162
|
-
|
161
|
+
assert_raises(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc; {}")}
|
162
|
+
assert_raises(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc, argv; {}")}
|
163
163
|
|
164
164
|
# type missing
|
165
|
-
|
165
|
+
assert_raises(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argc; {}")}
|
166
166
|
|
167
167
|
# bad storage
|
168
|
-
|
169
|
-
|
170
|
-
|
168
|
+
assert_raises(C::ParseError){C::Parser.new.parse("typedef void f(argc, argv) int argc; {}")}
|
169
|
+
assert_raises(C::ParseError){C::Parser.new.parse("auto void f(argc, argv) int argc; {}")}
|
170
|
+
assert_raises(C::ParseError){C::Parser.new.parse("register void f(argc, argv) int argc; {}")}
|
171
171
|
|
172
172
|
# duplicate storages
|
173
|
-
|
174
|
-
|
175
|
-
|
173
|
+
assert_raises(C::ParseError){C::Parser.new.parse("static auto int i;")}
|
174
|
+
assert_raises(C::ParseError){C::Parser.new.parse("static extern int i;")}
|
175
|
+
assert_raises(C::ParseError){C::Parser.new.parse("typedef register int i;")}
|
176
176
|
|
177
177
|
# `inline' can be repeated
|
178
|
-
|
178
|
+
C::Parser.new.parse("inline inline int i() {}") # no error
|
179
179
|
end
|
180
180
|
|
181
181
|
def test_declaration_list
|
@@ -846,12 +846,12 @@ TranslationUnit
|
|
846
846
|
name: "j"
|
847
847
|
EOS
|
848
848
|
# duplicate storages
|
849
|
-
|
850
|
-
|
851
|
-
|
849
|
+
assert_raises(C::ParseError){C::Parser.new.parse("static auto int ;")}
|
850
|
+
assert_raises(C::ParseError){C::Parser.new.parse("static extern int i ;")}
|
851
|
+
assert_raises(C::ParseError){C::Parser.new.parse("typedef register int i, j;")}
|
852
852
|
|
853
853
|
# `inline' can be repeated
|
854
|
-
|
854
|
+
C::Parser.new.parse("inline inline int f();") # no error
|
855
855
|
end
|
856
856
|
|
857
857
|
def test_declaration_specifiers
|
@@ -1163,15 +1163,15 @@ TranslationUnit
|
|
1163
1163
|
name: "I"
|
1164
1164
|
EOS
|
1165
1165
|
# some illegal combos
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1166
|
+
assert_raises(C::ParseError){C::Parser.new.parse("int float;")}
|
1167
|
+
assert_raises(C::ParseError){C::Parser.new.parse("struct s {} int;")}
|
1168
|
+
assert_raises(C::ParseError){C::Parser.new.parse("_Complex;")}
|
1169
|
+
assert_raises(C::ParseError){C::Parser.new.parse("_Complex _Imaginary float;")}
|
1170
|
+
assert_raises(C::ParseError){C::Parser.new.parse("short long;")}
|
1171
|
+
assert_raises(C::ParseError){C::Parser.new.parse("signed unsigned char;")}
|
1172
|
+
assert_raises(C::ParseError){C::Parser.new.parse("int int;")}
|
1173
|
+
assert_raises(C::ParseError){C::Parser.new.parse("long char;")}
|
1174
|
+
assert_raises(C::ParseError){C::Parser.new.parse("long long long;")}
|
1175
1175
|
end
|
1176
1176
|
|
1177
1177
|
def test_struct_or_union_specifier
|
@@ -1313,7 +1313,7 @@ TranslationUnit
|
|
1313
1313
|
expr: Int (const)
|
1314
1314
|
EOS
|
1315
1315
|
# quals can be repeated
|
1316
|
-
|
1316
|
+
C::Parser.new.parse("void f() {sizeof(const const int);}") # no error
|
1317
1317
|
end
|
1318
1318
|
|
1319
1319
|
def test_struct_declarator_list
|
@@ -2087,7 +2087,7 @@ void f() {
|
|
2087
2087
|
({;});
|
2088
2088
|
}
|
2089
2089
|
EOS
|
2090
|
-
|
2090
|
+
assert_raises(C::ParseError){@parser.parse(src)}
|
2091
2091
|
|
2092
2092
|
@parser.enable_block_expressions
|
2093
2093
|
check <<EOS
|
data/test/preprocessor_test.rb
CHANGED
@@ -8,12 +8,12 @@ require 'test_helper'
|
|
8
8
|
|
9
9
|
# publicize the private methods so we can test them easily
|
10
10
|
class C::Preprocessor
|
11
|
-
public :
|
11
|
+
public :full_command
|
12
12
|
end
|
13
|
-
class PreprocessorTest < Test
|
13
|
+
class PreprocessorTest < Minitest::Test
|
14
14
|
attr_accessor :cpp
|
15
15
|
def setup
|
16
|
-
@cpp = C::Preprocessor.new
|
16
|
+
@cpp = C::Preprocessor.new(quiet: true)
|
17
17
|
@cpp.include_path << 'dir1' << 'dir 2'
|
18
18
|
@cpp.macros['V'] = nil
|
19
19
|
@cpp.macros['I'] = 5
|
@@ -25,21 +25,15 @@ class PreprocessorTest < Test::Unit::TestCase
|
|
25
25
|
def teardown
|
26
26
|
FileUtils.rm_rf(TEST_DIR)
|
27
27
|
end
|
28
|
-
def test_shellquote
|
29
|
-
assert_equal('a', cpp.shellquote('a'))
|
30
|
-
assert_equal("'a b'", cpp.shellquote('a b'))
|
31
|
-
assert_equal("'a$b'", cpp.shellquote('a$b'))
|
32
|
-
assert_equal("'a\"b'", cpp.shellquote("a\"b"))
|
33
|
-
assert_equal("'\\'", cpp.shellquote("\\"))
|
34
|
-
assert_equal("\"a'b\"", cpp.shellquote("a'b"))
|
35
|
-
assert_equal("\"a\\\\\\$\\\"'\"", cpp.shellquote("a\\$\"'"))
|
36
|
-
end
|
37
28
|
def test_full_command
|
38
29
|
original_command = C::Preprocessor.command
|
39
30
|
C::Preprocessor.command = 'COMMAND'
|
40
|
-
assert_equal(
|
41
|
-
|
42
|
-
|
31
|
+
assert_equal([
|
32
|
+
'COMMAND',
|
33
|
+
'-Idir1', '-Idir 2',
|
34
|
+
'-DI=5', '-DS="blah"', '-DSWAP(a,b)=a ^= b ^= a ^= b', '-DV',
|
35
|
+
'a file.c',
|
36
|
+
], cpp.full_command('a file.c').shellsplit)
|
43
37
|
ensure
|
44
38
|
C::Preprocessor.command = original_command
|
45
39
|
end
|
@@ -84,4 +78,8 @@ EOS
|
|
84
78
|
assert_match(/int two = 2;/, output)
|
85
79
|
assert_match(/int three = 3;/, output)
|
86
80
|
end
|
81
|
+
def test_proprocess_warning
|
82
|
+
output = cpp.preprocess("#warning warning!")
|
83
|
+
refute_match /warning!/, output
|
84
|
+
end
|
87
85
|
end
|
data/test/render_test.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
require 'test_helper'
|
8
8
|
|
9
|
-
class RenderTest < Test
|
9
|
+
class RenderTest < Minitest::Test
|
10
10
|
def setup
|
11
11
|
@parser = C::Parser.new
|
12
12
|
@parser.type_names << 'T'
|
@@ -629,7 +629,7 @@ class RenderTest < Test::Unit::TestCase
|
|
629
629
|
# ------------------------------------------------------------------
|
630
630
|
# PlainLabel
|
631
631
|
# ------------------------------------------------------------------
|
632
|
-
|
632
|
+
|
633
633
|
def test_plain_label
|
634
634
|
check(C::PlainLabel, <<-EOS)
|
635
635
|
|one:
|
@@ -659,7 +659,7 @@ class RenderTest < Test::Unit::TestCase
|
|
659
659
|
# ------------------------------------------------------------------
|
660
660
|
# Comma
|
661
661
|
# ------------------------------------------------------------------
|
662
|
-
|
662
|
+
|
663
663
|
def test_comma_two_expressions
|
664
664
|
check(C::Comma, <<-EOS)
|
665
665
|
|1, 2
|
@@ -843,7 +843,7 @@ class RenderTest < Test::Unit::TestCase
|
|
843
843
|
# ------------------------------------------------------------------
|
844
844
|
# Cast
|
845
845
|
# ------------------------------------------------------------------
|
846
|
-
|
846
|
+
|
847
847
|
def test_cast
|
848
848
|
check(C::Cast, <<-EOS)
|
849
849
|
|(int)a
|
@@ -1711,6 +1711,21 @@ class RenderTest < Test::Unit::TestCase
|
|
1711
1711
|
|1
|
1712
1712
|
EOS
|
1713
1713
|
end
|
1714
|
+
def test_int_literal_oct
|
1715
|
+
check(C::IntLiteral, <<-EOS)
|
1716
|
+
|010
|
1717
|
+
EOS
|
1718
|
+
end
|
1719
|
+
def test_int_literal_hex
|
1720
|
+
check(C::IntLiteral, <<-EOS)
|
1721
|
+
|0x10
|
1722
|
+
EOS
|
1723
|
+
end
|
1724
|
+
def test_int_literal_suffix
|
1725
|
+
check(C::IntLiteral, <<-EOS)
|
1726
|
+
|1L
|
1727
|
+
EOS
|
1728
|
+
end
|
1714
1729
|
# TODO: handle big ints -- this test fails
|
1715
1730
|
def xtest_int_literal_big
|
1716
1731
|
check(C::IntLiteral, <<-EOS)
|
@@ -1729,6 +1744,21 @@ class RenderTest < Test::Unit::TestCase
|
|
1729
1744
|
|1.0
|
1730
1745
|
EOS
|
1731
1746
|
end
|
1747
|
+
def test_float_literal_exponent
|
1748
|
+
check(C::FloatLiteral, <<-EOS)
|
1749
|
+
|1.23e45
|
1750
|
+
EOS
|
1751
|
+
end
|
1752
|
+
def test_float_literal_suffix
|
1753
|
+
check(C::FloatLiteral, <<-EOS)
|
1754
|
+
|1.0f
|
1755
|
+
EOS
|
1756
|
+
end
|
1757
|
+
def test_float_literal_hex_exponent
|
1758
|
+
check(C::FloatLiteral, <<-EOS)
|
1759
|
+
|0x12.abp3
|
1760
|
+
EOS
|
1761
|
+
end
|
1732
1762
|
def test_float_literal_precise
|
1733
1763
|
check(C::FloatLiteral, <<-EOS)
|
1734
1764
|
|1.0000000001
|
data/test/test_helper.rb
CHANGED
@@ -3,7 +3,10 @@
|
|
3
3
|
ROOT = File.expand_path('..', File.dirname(__FILE__))
|
4
4
|
$:.unshift "#{ROOT}/lib"
|
5
5
|
|
6
|
-
require '
|
6
|
+
require 'minitest'
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'minitest/focus'
|
9
|
+
require 'pry'
|
7
10
|
require 'stringio'
|
8
11
|
require 'fileutils'
|
9
12
|
require 'cast'
|
@@ -36,7 +39,7 @@ class Integer
|
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
39
|
-
module
|
42
|
+
module Minitest::Assertions
|
40
43
|
INDENT = ' '
|
41
44
|
#
|
42
45
|
# Assert that the given string is parsed as expected. The given
|
@@ -71,7 +74,7 @@ module Test::Unit::Assertions
|
|
71
74
|
|
72
75
|
# compare
|
73
76
|
msg = "Debug strings unequal:\n#{juxtapose('Expected', exp, 'Output', out)}"
|
74
|
-
|
77
|
+
assert(out == exp, msg)
|
75
78
|
end
|
76
79
|
#
|
77
80
|
# Return a string of `s1' and `s2' side by side with a dividing line
|
@@ -108,7 +111,7 @@ module Test::Unit::Assertions
|
|
108
111
|
#
|
109
112
|
def assert_error(klass, re)
|
110
113
|
ex = nil
|
111
|
-
|
114
|
+
assert_raises(klass) do
|
112
115
|
begin
|
113
116
|
yield
|
114
117
|
rescue Exception => ex
|
@@ -183,7 +186,7 @@ module Test::Unit::Assertions
|
|
183
186
|
# copy).
|
184
187
|
#
|
185
188
|
def assert_copy(exp, out)
|
186
|
-
|
189
|
+
refute_same exp, out
|
187
190
|
assert_equal exp, out
|
188
191
|
end
|
189
192
|
#
|
metadata
CHANGED
@@ -1,48 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- George Ogata
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: ritual
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 0.4.0
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.4.0
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: racc
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.4.8
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.4.8
|
11
|
+
date: 2016-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
46
13
|
description:
|
47
14
|
email:
|
48
15
|
- george.ogata@gmail.com
|
@@ -51,7 +18,7 @@ extensions:
|
|
51
18
|
- ext/extconf.rb
|
52
19
|
extra_rdoc_files: []
|
53
20
|
files:
|
54
|
-
- .gitignore
|
21
|
+
- ".gitignore"
|
55
22
|
- CHANGELOG
|
56
23
|
- Gemfile
|
57
24
|
- LICENSE
|
@@ -62,8 +29,10 @@ files:
|
|
62
29
|
- ext/cast.h
|
63
30
|
- ext/extconf.rb
|
64
31
|
- ext/parser.c
|
32
|
+
- ext/yylex.c
|
65
33
|
- ext/yylex.re
|
66
34
|
- lib/cast.rb
|
35
|
+
- lib/cast/c.tab.rb
|
67
36
|
- lib/cast/c.y
|
68
37
|
- lib/cast/c_nodes.rb
|
69
38
|
- lib/cast/inspect.rb
|
@@ -83,38 +52,29 @@ files:
|
|
83
52
|
- test/preprocessor_test.rb
|
84
53
|
- test/render_test.rb
|
85
54
|
- test/test_helper.rb
|
86
|
-
- ext/yylex.c
|
87
|
-
- lib/cast/c.tab.rb
|
88
55
|
homepage: http://github.com/oggy/cast
|
89
56
|
licenses:
|
90
57
|
- MIT
|
58
|
+
metadata: {}
|
91
59
|
post_install_message:
|
92
60
|
rdoc_options: []
|
93
61
|
require_paths:
|
94
62
|
- lib
|
95
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
64
|
requirements:
|
98
|
-
- -
|
65
|
+
- - ">="
|
99
66
|
- !ruby/object:Gem::Version
|
100
67
|
version: '0'
|
101
|
-
segments:
|
102
|
-
- 0
|
103
|
-
hash: 2706144592644454068
|
104
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
69
|
requirements:
|
107
|
-
- -
|
70
|
+
- - ">="
|
108
71
|
- !ruby/object:Gem::Version
|
109
72
|
version: '0'
|
110
|
-
segments:
|
111
|
-
- 0
|
112
|
-
hash: 2706144592644454068
|
113
73
|
requirements: []
|
114
74
|
rubyforge_project:
|
115
|
-
rubygems_version:
|
75
|
+
rubygems_version: 2.4.8
|
116
76
|
signing_key:
|
117
|
-
specification_version:
|
77
|
+
specification_version: 4
|
118
78
|
summary: C parser and AST constructor.
|
119
79
|
test_files:
|
120
80
|
- test/c_nodes_test.rb
|