daedalus-core 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/daedalus/dependency_grapher.rb +21 -13
- data/lib/daedalus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 327e0c902f3cd052f4b41bf0255f058148960209
|
4
|
+
data.tar.gz: f21877accdf61bc6f2acb276ae56d27bd254ac21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f57c705d430a28e8d08f394cfb9c371c441a6357211069c5e50db5e1d4d1aa9d6284c924bb454a21f1f1db53c5bec32088931b1e0ea2df8b63071f3ed1a120c5
|
7
|
+
data.tar.gz: 6bc6725d615cdd22c8daa82f8580d6da50d98c2d1b22322209c75a0cc508f067a10a24de7ee2c55e29cc9ece83fd9cece112df3401bb20cfe18e4aa44f0268f4
|
@@ -25,24 +25,31 @@ class DependencyGrapher
|
|
25
25
|
|
26
26
|
class ExpressionEvaluator
|
27
27
|
def initialize(expression)
|
28
|
-
@expression = expression
|
28
|
+
@expression = expression
|
29
29
|
end
|
30
30
|
|
31
31
|
def evaluate(defines)
|
32
|
+
# Stage0: eliminate comments
|
33
|
+
@expression.gsub!(/(\/\/.*)$/, "")
|
34
|
+
@expression.gsub!(/(\/\*.*\*\/)/, "")
|
35
|
+
|
32
36
|
# Stage1: find 'defined's and evaluate
|
33
37
|
# replace defined with boolean evaluation value
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
re = /((!|\s*)?defined((\(|\s+)(\s*[^) ]+)(\)|\s|$)))/o
|
39
|
+
@expression.gsub!(re) do |expr|
|
40
|
+
m = expr.match(re)
|
41
|
+
negate = m[2] == "!"
|
42
|
+
key = m[5].strip
|
43
|
+
|
44
|
+
value = defines.include? key
|
45
|
+
value = !value if negate
|
46
|
+
value ? "true" : "false"
|
47
|
+
end
|
48
|
+
|
42
49
|
# Stage2: scan macro-defined keywords
|
43
50
|
# replace with actual value (true or false)
|
44
51
|
# this covers patterns like __clang__ and __x86_64__
|
45
|
-
@expression.gsub!(/__[A-Za-z0-9_]+__/)
|
52
|
+
@expression.gsub!(/__[A-Za-z0-9_]+__/) do |expr|
|
46
53
|
if defines.include?(expr)
|
47
54
|
defines[expr].to_s
|
48
55
|
elsif integer?(expr)
|
@@ -50,10 +57,10 @@ class DependencyGrapher
|
|
50
57
|
else
|
51
58
|
'0'
|
52
59
|
end
|
53
|
-
|
60
|
+
end
|
54
61
|
|
55
62
|
# this covers other patters.
|
56
|
-
@expression.gsub!(/[A-Z0-9_]{4,}/)
|
63
|
+
@expression.gsub!(/[A-Z0-9_]{4,}/) do |expr|
|
57
64
|
if defines.include?(expr)
|
58
65
|
defines[expr].to_s
|
59
66
|
elsif integer?(expr)
|
@@ -61,7 +68,8 @@ class DependencyGrapher
|
|
61
68
|
else
|
62
69
|
'0'
|
63
70
|
end
|
64
|
-
|
71
|
+
end
|
72
|
+
|
65
73
|
# Stage3: Evaluate with ruby eval()
|
66
74
|
eval(@expression)
|
67
75
|
end
|
data/lib/daedalus/version.rb
CHANGED