cstub 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cstub.rb +40 -2
- data/lib/cstub/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80be5fe7a16e56b0cf39576008d00cbf50a7ffb7
|
4
|
+
data.tar.gz: 42e72ed1f2bb2fb83099028d55e627af0d8dc925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6deca73beb0e0c3960063eafda0dc601f171cbacfdcf2e8c57f685d28d14c6620fb3b9196bb6544c94ba05978dd9d711399c455d2d3b64f67de643d6aad30e54
|
7
|
+
data.tar.gz: 227e1bdcc0a5c79a0a29ef967136646fe4af3bee217e8777194d24f6a7250df000a1a0e9a43b784008e0dd57768d8b5bff579b3b25bd706622e021bf06d88d00
|
data/lib/cstub.rb
CHANGED
@@ -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
|
130
|
-
|
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)
|
data/lib/cstub/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2014-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cast
|