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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9fb9aedfd46997dffea225f86e7d01a57a80d14
4
- data.tar.gz: cf5164dc1ec954d9ac2606730e8cc4bcff027e51
3
+ metadata.gz: 327e0c902f3cd052f4b41bf0255f058148960209
4
+ data.tar.gz: f21877accdf61bc6f2acb276ae56d27bd254ac21
5
5
  SHA512:
6
- metadata.gz: 58c034b22f6ddd91e56b2af56ed804807fe5c2f6b892de09660fd33a61abecc7aaea412abdff7d529e4ded1d1a1988f3432912a60f904d65d2a84450b5a48c67
7
- data.tar.gz: 521380e15f3bdbb28a54f6e2ca453d08a32cde03d7597a6348f61507241f2f75600ce8fdff1fddbcd5352bad643a4fe8740f705391b3221118794b4cb68dc422
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.strip
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
- @expression.gsub!(/(defined\(.+?\))/) { |expr|
35
- defkey = expr.match(/\((.+?)\)/)[1]
36
- if defines.include?(defkey)
37
- 'true'
38
- else
39
- 'false'
40
- end
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_]+__/) { |expr|
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,}/) { |expr|
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
@@ -1,3 +1,3 @@
1
1
  module Daedalus
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daedalus-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Shirai