cstub 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cstub.rb +40 -2
  3. data/lib/cstub/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 809848477047017f310cfa958061f70a7c53a80d
4
- data.tar.gz: f56bf9ba507e41c77c2bc500a9af03084410e747
3
+ metadata.gz: 80be5fe7a16e56b0cf39576008d00cbf50a7ffb7
4
+ data.tar.gz: 42e72ed1f2bb2fb83099028d55e627af0d8dc925
5
5
  SHA512:
6
- metadata.gz: d0aab08aa3d3618755955af13aa5d9f9bed41be9300a79b9dc2d77a9ba2f98f1a5c2a10adee6b3af24ffa8130ef7c8400b9b3eb8f6ea5de5c042be5b88b8c977
7
- data.tar.gz: f0f16dcd7ddc28c023116b05f63a1339d9cde58589a44fa8a49b2ff2068cea3706bb77585d982ab39004a931cc4e020fb0b5b0145e679b6a0da1b287067b85ca
6
+ metadata.gz: 6deca73beb0e0c3960063eafda0dc601f171cbacfdcf2e8c57f685d28d14c6620fb3b9196bb6544c94ba05978dd9d711399c455d2d3b64f67de643d6aad30e54
7
+ data.tar.gz: 227e1bdcc0a5c79a0a29ef967136646fe4af3bee217e8777194d24f6a7250df000a1a0e9a43b784008e0dd57768d8b5bff579b3b25bd706622e021bf06d88d00
@@ -3,6 +3,34 @@ require "cstub/version"
3
3
  require 'cast'
4
4
  require 'optparse'
5
5
 
6
+ # monkey patch to cast
7
+ module C
8
+ class Preprocessor
9
+ def preprocess(text)
10
+ filename = nil
11
+ Tempfile.open(['cast-preprocessor-input.', '.c'], File.expand_path(pwd || '.')) do |file|
12
+ filename = file.path
13
+ file.puts text
14
+ end
15
+ output = `#{full_command(filename)}`
16
+ if $? == 0
17
+ return output
18
+ else
19
+ raise Error, output
20
+ end
21
+ end
22
+ def shellquote(arg)
23
+ if arg !~ /[\"\'\\$&<>|\s()]/
24
+ return arg
25
+ else
26
+ arg.gsub!(/([\"\\$&<>|])/, '\\\\\\1')
27
+ return "\"#{arg}\""
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+
6
34
  module Cstub
7
35
  def self.collect_types(ast)
8
36
  typelist = {}
@@ -126,8 +154,18 @@ module Cstub
126
154
  C::Preprocessor.command = cpp_command
127
155
  end
128
156
  source = cpp.preprocess(code)
129
- source.gsub!(/^#.*/,'')
130
- C.parse(source)
157
+ orig_source = source
158
+ source = source.gsub(/^#.*/,'')
159
+ begin
160
+ C.parse(source)
161
+ rescue => exc
162
+ line = exc.to_s.to_i
163
+ sa = orig_source.split("\n")
164
+ puts " " + sa[line-2] if 0 <= line-2
165
+ puts "> " + sa[line-1]
166
+ puts " " + sa[line] if line < sa.length
167
+ raise
168
+ end
131
169
  end
132
170
 
133
171
  def self.make_stubs(files, cpp_command, include_path, macros)
@@ -1,3 +1,3 @@
1
1
  module Cstub
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cstub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kunigaku
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-07 00:00:00.000000000 Z
11
+ date: 2014-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cast