xdry 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -55,6 +55,19 @@ module XDry
55
55
  end
56
56
  end
57
57
 
58
+ module UNKNOWN
59
+ def self.retain expr
60
+ "[#{expr} retain]"
61
+ end
62
+
63
+ def self.release out, expr
64
+ out << "[#{expr} release]";
65
+ end
66
+
67
+ def self.release_and_clear out, var_name
68
+ end
69
+ end
70
+
58
71
  end
59
72
 
60
73
  module Boxing
@@ -203,6 +216,8 @@ module XDry
203
216
  when PointerVarType then RetainPolicy::RETAIN
204
217
  when IdVarType then RetainPolicy::ASSIGN_REF
205
218
  when SimpleVarType then RetainPolicy::ASSIGN_VALUE
219
+ when UnknownVarType then RetainPolicy::UNKNOWN
220
+ when PointerPointerVarType then RetainPolicy::RETAIN
206
221
  end
207
222
  end
208
223
  end
@@ -14,6 +14,9 @@ module Generators
14
14
  id "dealloc"
15
15
 
16
16
  def process_class oclass
17
+ # avoid generation of empty deallocs
18
+ lines = generate_release_calls_if(oclass) { true }
19
+ return if lines.empty?
17
20
 
18
21
  MethodPatcher.new(patcher, oclass, 'dealloc', ImplementationStartIP.new(oclass), DEALLOC_CODE) do |dealloc_method|
19
22
  impl = dealloc_method.impl
@@ -1,4 +1,9 @@
1
- require 'generator'
1
+ begin
2
+ require 'generator'
3
+ rescue LoadError
4
+ Generator = Enumerator
5
+ end
6
+
2
7
  require 'stringio'
3
8
 
4
9
  module XDry
@@ -47,8 +52,8 @@ module XDry
47
52
  def parse_data_in_scopes gen, scopes
48
53
  scope_stack = ScopeStack.new(scopes)
49
54
  scope_stack.verbose = @verbose
50
- while gen.next?
51
- orig_line, line, pos, eol_comments, indent = gen.next
55
+ while data = gen.next
56
+ orig_line, line, pos, eol_comments, indent = data
52
57
  puts " #{pos} #{orig_line}" if @verbose
53
58
  pos.scope_before = scope_stack.current_scope
54
59
  scope_stack.parse_line line, eol_comments, indent do |scope, child|
@@ -66,6 +71,8 @@ module XDry
66
71
  end
67
72
  pos.scope_after = scope_stack.current_scope
68
73
  end
74
+ rescue EOFError, StopIteration
75
+ #
69
76
  end
70
77
 
71
78
  def new_lines_generator g, file_ref, io
@@ -71,15 +71,9 @@ module XDry
71
71
  @tags << 'persistent'
72
72
  when ''
73
73
  @tags.clear
74
- when /^(\w+)\s+(\w+)\s*;/
75
- type_name, field_name = $1, $2
76
- yield process_type_hint(NFieldDef.new(field_name, SimpleVarType.new(type_name)), eol_comments)
77
- when /^(\w+)\s*\*\s*(\w+)\s*;/
78
- type_name, field_name = $1, $2
79
- yield process_type_hint(NFieldDef.new(field_name, PointerVarType.new(type_name)), eol_comments)
80
- when /^id<(\w+)>\s+(\w+)\s*;/
81
- type_name, field_name = $1, $2
82
- yield process_type_hint(NFieldDef.new(field_name, IdVarType.new()), eol_comments)
74
+ when /^(.*[\s\W])(\w+)\s*;/
75
+ type_name, field_name = $1.strip, $2
76
+ yield process_type_hint(NFieldDef.new(field_name, VarType.parse(type_name)), eol_comments)
83
77
  end
84
78
  end
85
79
 
@@ -1,3 +1,4 @@
1
+ require 'strscan'
1
2
 
2
3
  module XDry
3
4
 
@@ -8,15 +9,32 @@ module XDry
8
9
  if string =~ /^\w+$/
9
10
  SimpleSelectorDef.new(string)
10
11
  else
11
- comps = string.split(/\s+(?!\*)/).collect do |component_string|
12
- if component_string =~ /^(\w+:)\s*(?:\(([^)]+)\)\s*)?(\w*)$/
13
- keyword, type_decl, arg_name = $1, $2, $3
14
- type = if type_decl then VarType.parse(type_decl) else nil end
15
- SelectorComponent.new(keyword, arg_name, type)
12
+ ss = StringScanner.new(string)
13
+ comps = []
14
+ while not ss.eos?
15
+ keyword = ss.scan(/\w+\s*:/) or raise(StandardError, "Cannot parse selector '#{string}': keyword expected at '#{ss.rest}'")
16
+ keyword = keyword.gsub(/\s/, '')
17
+
18
+ ss.skip(/\s+/)
19
+ if ss.skip(/\(/)
20
+ res = ss.scan_until(/\)/) or raise(StandardError, "Cannot parse selector '#{string}': missing closing paren at '#{ss.rest}'")
21
+ type_decl = res[0..-2].strip
16
22
  else
17
- raise StandardError, "Cannot parse selector component '#{component_string}' for selector '#{string}'"
23
+ type_decl = nil
18
24
  end
25
+
26
+ ss.skip(/\s+/)
27
+ unless ss.match?(/\w+\s*:/)
28
+ arg_name = ss.scan(/\w+/)
29
+ else
30
+ arg_name = nil
31
+ end
32
+ ss.skip(/\s+/)
33
+
34
+ type = if type_decl then VarType.parse(type_decl) else nil end
35
+ comps << SelectorComponent.new(keyword, arg_name, type)
19
36
  end
37
+
20
38
  CompoundSelectorDef.new(comps)
21
39
  end
22
40
  end
@@ -7,13 +7,19 @@ module XDry
7
7
  case type_decl
8
8
  when /^id$/
9
9
  IdVarType.new
10
+ when /^id\s*<\s*(\w+)\s*>$/
11
+ IdVarType.new($1)
10
12
  when /^(?:unsigned\s+|signed\s+|long\s+)?\w+$/
11
13
  SimpleVarType.new(type_decl.gsub(/\s+/, ' '))
12
14
  when /^(\w+)\s*\*$/
13
15
  class_name = $1
14
16
  PointerVarType.new(class_name)
17
+ when /^(\w+)\s*\*\s*\*$/
18
+ class_name = $1
19
+ PointerPointerVarType.new(class_name)
15
20
  else
16
- raise StandardError, "Cannot parse Obj-C type: '#{type_decl}'"
21
+ puts "!! Cannot parse Obj-C type: '#{type_decl}'"
22
+ return UnknownVarType.new(type_decl)
17
23
  end
18
24
  end
19
25
 
@@ -25,8 +31,18 @@ module XDry
25
31
  end
26
32
 
27
33
  class IdVarType < VarType
34
+ attr_reader :protocol
35
+
36
+ def initialize protocol=nil
37
+ @protocol = protocol
38
+ end
39
+
28
40
  def to_s
29
- "id"
41
+ if @protocol.nil?
42
+ "id"
43
+ else
44
+ "id<#{@protocol}>"
45
+ end
30
46
  end
31
47
 
32
48
  def default_property_retainment_policy; 'assign'; end
@@ -63,4 +79,38 @@ module XDry
63
79
  def default_property_retainment_policy; 'retain'; end
64
80
  end
65
81
 
82
+ class PointerPointerVarType < VarType
83
+ attr_reader :name
84
+ attr_accessor :type_hint
85
+
86
+ def initialize name
87
+ @name = name
88
+ end
89
+
90
+ def to_s
91
+ "#{@name} **"
92
+ end
93
+
94
+ def needs_space?; false; end
95
+
96
+ def default_property_retainment_policy; 'retain'; end
97
+ end
98
+
99
+ class UnknownVarType < VarType
100
+ attr_reader :name
101
+ attr_accessor :type_hint
102
+
103
+ def initialize name
104
+ @name = name
105
+ end
106
+
107
+ def to_s
108
+ @name
109
+ end
110
+
111
+ def needs_space?; true; end
112
+
113
+ def default_property_retainment_policy; 'retain'; end
114
+ end
115
+
66
116
  end
@@ -131,7 +131,7 @@ module XDry
131
131
  end
132
132
 
133
133
  def load_lines_of file_ref
134
- file_ref.read.lines.collect
134
+ file_ref.read.lines.collect.to_a
135
135
  end
136
136
 
137
137
  end
@@ -2,6 +2,18 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "dealloc support" do
4
4
 
5
+ it "shouldn't add dealloc when it is not needed" do
6
+ xdry :dealloc, <<-END
7
+ @interface Foo {
8
+ int something;
9
+ }
10
+ @end
11
+
12
+ @implementation Foo
13
+ @end
14
+ END
15
+ end
16
+
5
17
  it "should add missing release calls to dealloc" do
6
18
  xdry :dealloc, <<-END
7
19
  @interface Foo {
@@ -36,4 +36,21 @@ describe "property from field generator" do
36
36
  END
37
37
  end
38
38
 
39
+ it "should add a property for a field with unknown type" do
40
+ xdry :prop_from_field, <<-END
41
+ @interface Foo {
42
+ - Blah Blah __const __attribute((WOWWW!!!! 111 22) _something; !p
43
+ + Blah Blah __const __attribute((WOWWW!!!! 111 22) _something;
44
+ }
45
+
46
+ + @property(nonatomic, retain) Blah Blah __const __attribute((WOWWW!!!! 111 22) something;
47
+ +
48
+ @end
49
+
50
+ @implementation Foo
51
+
52
+ @end
53
+ END
54
+ end
55
+
39
56
  end
@@ -0,0 +1,88 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SelectorDef" do
4
+
5
+ it "should parse a simple selector" do
6
+ sel = XDry::SelectorDef.parse('count')
7
+ sel.class.should == XDry::SimpleSelectorDef
8
+ sel.selector.should == 'count'
9
+ end
10
+
11
+ it "should parse foo:(Foo)oof" do
12
+ sel = XDry::SelectorDef.parse('foo:(Foo)oof')
13
+ sel.components.count.should == 1
14
+ sel.components[0].keyword.should == 'foo:'
15
+ sel.components[0].arg_name.should == 'oof'
16
+ sel.components[0].type.class.should == XDry::SimpleVarType
17
+ sel.components[0].type.name.should == 'Foo'
18
+ end
19
+
20
+ it "should parse foo:" do
21
+ sel = XDry::SelectorDef.parse('foo:')
22
+ sel.components.count.should == 1
23
+ sel.components[0].keyword.should == 'foo:'
24
+ sel.components[0].arg_name.should == nil
25
+ sel.components[0].type.should == nil
26
+ end
27
+
28
+ it "should parse foo:oof" do
29
+ sel = XDry::SelectorDef.parse('foo:oof')
30
+ sel.components.count.should == 1
31
+ sel.components[0].keyword.should == 'foo:'
32
+ sel.components[0].arg_name.should == 'oof'
33
+ sel.components[0].type.should == nil
34
+ end
35
+
36
+ it "should parse foo:(Foo)oof bar:(Bar)rab" do
37
+ sel = XDry::SelectorDef.parse('foo:(Foo)oof bar:(Bar)rab')
38
+ sel.components.count.should == 2
39
+
40
+ sel.components[0].keyword.should == 'foo:'
41
+ sel.components[0].arg_name.should == 'oof'
42
+ sel.components[0].type.class.should == XDry::SimpleVarType
43
+ sel.components[0].type.name.should == 'Foo'
44
+
45
+ sel.components[1].keyword.should == 'bar:'
46
+ sel.components[1].arg_name.should == 'rab'
47
+ sel.components[1].type.class.should == XDry::SimpleVarType
48
+ sel.components[1].type.name.should == 'Bar'
49
+ end
50
+
51
+ it "should parse foo:bar:" do
52
+ sel = XDry::SelectorDef.parse('foo:bar:')
53
+ sel.components.count.should == 2
54
+
55
+ sel.components[0].keyword.should == 'foo:'
56
+ sel.components[0].arg_name.should == nil
57
+ sel.components[0].type.should == nil
58
+
59
+ sel.components[1].keyword.should == 'bar:'
60
+ sel.components[1].arg_name.should == nil
61
+ sel.components[1].type.should == nil
62
+ end
63
+
64
+ it "should parse foo:(unsigned char)oof" do
65
+ sel = XDry::SelectorDef.parse('foo:(unsigned char)oof')
66
+ sel.components.count.should == 1
67
+ sel.components[0].keyword.should == 'foo:'
68
+ sel.components[0].arg_name.should == 'oof'
69
+ sel.components[0].type.class.should == XDry::SimpleVarType
70
+ sel.components[0].type.name.should == 'unsigned char'
71
+ end
72
+
73
+ it "should parse foo : ( unsigned char ) oof bar : (long long) zzzz " do
74
+ sel = XDry::SelectorDef.parse('foo : ( unsigned char ) oof bar : (long long) zzzz ')
75
+ sel.components.count.should == 2
76
+
77
+ sel.components[0].keyword.should == 'foo:'
78
+ sel.components[0].arg_name.should == 'oof'
79
+ sel.components[0].type.class.should == XDry::SimpleVarType
80
+ sel.components[0].type.name.should == 'unsigned char'
81
+
82
+ sel.components[1].keyword.should == 'bar:'
83
+ sel.components[1].arg_name.should == 'zzzz'
84
+ sel.components[1].type.class.should == XDry::SimpleVarType
85
+ sel.components[1].type.name.should == 'long long'
86
+ end
87
+
88
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "XDry" do
4
+
5
+ it "should not choke on unknown types" do
6
+ xdry <<-END
7
+ @interface Foo {
8
+ Foo Bar Buuuzzzzza _something;
9
+ }
10
+
11
+ @end
12
+
13
+ @implementation Foo
14
+ @end
15
+ END
16
+ end
17
+
18
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "VarType" do
4
+
5
+ for simple in ['int', 'signed int', 'unsigned int', 'unsigned char', 'long long']
6
+ it "should parse #{simple}" do
7
+ sel = XDry::VarType.parse(simple)
8
+ sel.class.should == XDry::SimpleVarType
9
+ sel.to_s == simple
10
+ end
11
+ end
12
+
13
+ it "should parse NSString *" do
14
+ sel = XDry::VarType.parse('NSString *')
15
+ sel.class.should == XDry::PointerVarType
16
+ sel.name == 'NSString'
17
+ end
18
+
19
+ it "should parse NSError **" do
20
+ sel = XDry::VarType.parse('NSError **')
21
+ sel.class.should == XDry::PointerPointerVarType
22
+ sel.name == 'NSError'
23
+ end
24
+
25
+ it "should parse id" do
26
+ sel = XDry::VarType.parse('id')
27
+ sel.class.should == XDry::IdVarType
28
+ sel.protocol == nil
29
+ end
30
+
31
+ it "should parse id<Foo>" do
32
+ sel = XDry::VarType.parse('id<Foo>')
33
+ sel.class.should == XDry::IdVarType
34
+ sel.protocol == 'Foo'
35
+ end
36
+
37
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{xdry}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrey Tarantsov"]
12
- s.date = %q{2011-03-20}
12
+ s.date = %q{2011-03-22}
13
13
  s.default_executable = %q{xdry}
14
14
  s.description = %q{Autogenerates all kinds of funky stuff (like accessors) in Xcode projects}
15
15
  s.email = %q{andreyvit@gmail.com}
@@ -66,14 +66,17 @@ Gem::Specification.new do |s|
66
66
  "spec/field_from_prop_spec.rb",
67
67
  "spec/prop_from_field_spec.rb",
68
68
  "spec/readme_samples_spec.rb",
69
+ "spec/selector_parsing_spec.rb",
69
70
  "spec/spec.opts",
70
71
  "spec/spec_helper.rb",
71
72
  "spec/synthesize_spec.rb",
73
+ "spec/unknown_stuff_handling_spec.rb",
74
+ "spec/vartype_parsing_spec.rb",
72
75
  "xdry.gemspec"
73
76
  ]
74
77
  s.homepage = %q{http://andreyvit.github.com/xdry/}
75
78
  s.require_paths = ["lib"]
76
- s.rubygems_version = %q{1.3.7}
79
+ s.rubygems_version = %q{1.6.2}
77
80
  s.summary = %q{eXtra D.R.Y. for Xcode}
78
81
  s.test_files = [
79
82
  "spec/boxing_spec.rb",
@@ -83,12 +86,14 @@ Gem::Specification.new do |s|
83
86
  "spec/field_from_prop_spec.rb",
84
87
  "spec/prop_from_field_spec.rb",
85
88
  "spec/readme_samples_spec.rb",
89
+ "spec/selector_parsing_spec.rb",
86
90
  "spec/spec_helper.rb",
87
- "spec/synthesize_spec.rb"
91
+ "spec/synthesize_spec.rb",
92
+ "spec/unknown_stuff_handling_spec.rb",
93
+ "spec/vartype_parsing_spec.rb"
88
94
  ]
89
95
 
90
96
  if s.respond_to? :specification_version then
91
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
92
97
  s.specification_version = 3
93
98
 
94
99
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xdry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
4
+ prerelease:
5
+ version: 0.1.2
11
6
  platform: ruby
12
7
  authors:
13
8
  - Andrey Tarantsov
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-03-20 00:00:00 +06:00
13
+ date: 2011-03-22 00:00:00 +06:00
19
14
  default_executable: xdry
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 1
32
- - 2
33
- - 9
34
24
  version: 1.2.9
35
25
  type: :development
36
26
  version_requirements: *id001
@@ -91,9 +81,12 @@ files:
91
81
  - spec/field_from_prop_spec.rb
92
82
  - spec/prop_from_field_spec.rb
93
83
  - spec/readme_samples_spec.rb
84
+ - spec/selector_parsing_spec.rb
94
85
  - spec/spec.opts
95
86
  - spec/spec_helper.rb
96
87
  - spec/synthesize_spec.rb
88
+ - spec/unknown_stuff_handling_spec.rb
89
+ - spec/vartype_parsing_spec.rb
97
90
  - xdry.gemspec
98
91
  has_rdoc: true
99
92
  homepage: http://andreyvit.github.com/xdry/
@@ -109,23 +102,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
102
  requirements:
110
103
  - - ">="
111
104
  - !ruby/object:Gem::Version
112
- hash: 3
113
- segments:
114
- - 0
115
105
  version: "0"
116
106
  required_rubygems_version: !ruby/object:Gem::Requirement
117
107
  none: false
118
108
  requirements:
119
109
  - - ">="
120
110
  - !ruby/object:Gem::Version
121
- hash: 3
122
- segments:
123
- - 0
124
111
  version: "0"
125
112
  requirements: []
126
113
 
127
114
  rubyforge_project:
128
- rubygems_version: 1.3.7
115
+ rubygems_version: 1.6.2
129
116
  signing_key:
130
117
  specification_version: 3
131
118
  summary: eXtra D.R.Y. for Xcode
@@ -137,5 +124,8 @@ test_files:
137
124
  - spec/field_from_prop_spec.rb
138
125
  - spec/prop_from_field_spec.rb
139
126
  - spec/readme_samples_spec.rb
127
+ - spec/selector_parsing_spec.rb
140
128
  - spec/spec_helper.rb
141
129
  - spec/synthesize_spec.rb
130
+ - spec/unknown_stuff_handling_spec.rb
131
+ - spec/vartype_parsing_spec.rb