Skip to content

Commit 6287ff9

Browse files
authored
Merge pull request #255 from riscv-software-src/rename_mref
2 parents 0155d33 + 4b92f6f commit 6287ff9

File tree

9 files changed

+54
-54
lines changed

9 files changed

+54
-54
lines changed

arch/certificate_model/MockCertificateModel.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ MockCertificateModel:
3838

3939
# XXX - Remove version information since specifying priv/unpriv ISA manual should imply this.
4040
extensions:
41-
$mref:
41+
$inherits:
4242
- "../profile_release/MockProfileRelease.yaml#/MockProfileRelease/profiles/MP-U-64/extensions"
4343
- "../profile_release/MockProfileRelease.yaml#/MockProfileRelease/profiles/MP-S-64/extensions"
4444
I:

arch/inst/I/addi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ addi:
99
match: -----------------000-----0010011
1010
variables:
1111
- name: imm
12-
$mref: ../../common/inst_variable_types.yaml#/itype_imm
12+
$inherits: ../../common/inst_variable_types.yaml#/itype_imm
1313
- name: rs1
1414
location: 19-15
1515
- name: rd

arch/profile_release/MockProfileRelease.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ MockProfileRelease:
4242
4343
company: Disney
4444
extensions:
45-
$mref: "#/MockProfileRelease/profiles/MP-U-64/extensions"
45+
$inherits: "#/MockProfileRelease/profiles/MP-U-64/extensions"
4646
A:
4747
presence: mandatory
4848
S:

arch/profile_release/RVA20.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ RVA20:
4343
most important profile within application processors in
4444
terms of the amount of software that targets this profile.
4545
extensions:
46-
$mref: "RVI20.yaml#/RVI20/profiles/RVI20U64/extensions"
46+
$inherits: "RVI20.yaml#/RVI20/profiles/RVI20U64/extensions"
4747
$remove: Zifencei # Not allowed as an option for Unpriv ISA (only available in Priv ISA).
4848
A:
4949
presence: mandatory

arch/profile_release/RVA22.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ RVA22:
4343
most important profile within application processors in
4444
terms of the amount of software that targets this profile.
4545
extensions:
46-
$mref: "RVA20.yaml#/RVA20/profiles/RVA20U64/extensions"
46+
$inherits: "RVA20.yaml#/RVA20/profiles/RVA20U64/extensions"
4747
Zihpm:
4848
presence: mandatory
4949
version: "= 2.0"
@@ -167,7 +167,7 @@ RVA22:
167167
processors. RVA22S64 is based on privileged architecture version
168168
1.12.
169169
extensions:
170-
$mref: "RVA20.yaml#/RVA20/profiles/RVA20S64/extensions"
170+
$inherits: "RVA20.yaml#/RVA20/profiles/RVA20S64/extensions"
171171
S:
172172
presence: mandatory
173173
version: "= 1.12"

arch/profile_release/RVI20.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ RVI20:
8484
Implementations are strongly recommended to raise illegal-instruction
8585
exceptions on attempts to execute unimplemented opcodes.
8686
RVI20U64:
87-
$mref: "#/RVI20/profiles/RVI20U32"
87+
$inherits: "#/RVI20/profiles/RVI20U32"
8888
base: 64
8989
marketing_name: RVI20U64

lib/test/test_yaml_loader.rb

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_remove
1515
key2: value2
1616
1717
child:
18-
$mref: "#/base"
18+
$inherits: "#/base"
1919
$remove: key2
2020
key3: value3
2121
YAML
@@ -36,7 +36,7 @@ def test_multiple_remove
3636
key3: value3
3737
3838
child:
39-
$mref: "#/base"
39+
$inherits: "#/base"
4040
$remove:
4141
- key2
4242
- key3
@@ -51,20 +51,20 @@ def test_multiple_remove
5151
assert_equal({ "key1" => "value1", "key4" => "value4" }, doc["child"])
5252
end
5353

54-
def test_that_mref_with_nested_replace_works
54+
def test_that_inherits_with_nested_replace_works
5555
yaml = <<~YAML
5656
base:
5757
key1:
5858
sub_key1: value1
5959
key2: value2
6060
6161
middle:
62-
$mref: "#/base"
62+
$inherits: "#/base"
6363
key3: value3
6464
key4: value4
6565
6666
bottom:
67-
$mref:
67+
$inherits:
6868
- "#/base"
6969
- "#/middle"
7070
key1:
@@ -82,19 +82,19 @@ def test_that_mref_with_nested_replace_works
8282
assert_equal({ "key1" => {"sub_key1" => "value1", "sub_key6" => "value6"}, "key2" => "value2_new", "key3" => "value3", "key4" => "value4_new", "key5" => "value5" }, doc["bottom"])
8383
end
8484

85-
def test_that_spurious_recursive_mref_works
85+
def test_that_spurious_recursive_inherits_works
8686
yaml = <<~YAML
8787
base:
8888
key1: value1
8989
key2: value2
9090
9191
middle:
92-
$mref: "#/base"
92+
$inherits: "#/base"
9393
key3: value3
9494
key4: value4
9595
9696
bottom:
97-
$mref:
97+
$inherits:
9898
- "#/base"
9999
- "#/middle"
100100
key2: value2_new
@@ -111,19 +111,19 @@ def test_that_spurious_recursive_mref_works
111111
assert_equal({ "key1" => "value1", "key2" => "value2_new", "key3" => "value3", "key4" => "value4_new", "key5" => "value5" }, doc["bottom"])
112112
end
113113

114-
def test_that_recursive_mref_works
114+
def test_that_recursive_inherits_works
115115
yaml = <<~YAML
116116
base:
117117
key1: value1
118118
key2: value2
119119
120120
middle:
121-
$mref: "#/base"
121+
$inherits: "#/base"
122122
key3: value3
123123
key4: value4
124124
125125
bottom:
126-
$mref: "#/middle"
126+
$inherits: "#/middle"
127127
key2: value2_new
128128
key4: value4_new
129129
key5: value5
@@ -138,7 +138,7 @@ def test_that_recursive_mref_works
138138
assert_equal({ "key1" => "value1", "key2" => "value2_new", "key3" => "value3", "key4" => "value4_new", "key5" => "value5" }, doc["bottom"])
139139
end
140140

141-
def test_that_nested_mref_works
141+
def test_that_nested_inherits_works
142142
yaml = <<~YAML
143143
top:
144144
base:
@@ -148,7 +148,7 @@ def test_that_nested_mref_works
148148
149149
bottom:
150150
child:
151-
$mref: "#/top/base"
151+
$inherits: "#/top/base"
152152
key3: value3_new
153153
YAML
154154

@@ -160,15 +160,15 @@ def test_that_nested_mref_works
160160
assert_equal({ "key1" => "value1", "key2" => "value2", "key3" => "value3_new" }, doc["bottom"]["child"])
161161
end
162162

163-
def test_that_mref_doesnt_delete_keys
163+
def test_that_inherits_doesnt_delete_keys
164164
yaml = <<~YAML
165165
base:
166166
key1: value1
167167
key2: value2
168168
key3: value3
169169
170170
child:
171-
$mref: "#/base"
171+
$inherits: "#/base"
172172
key3: value3_new
173173
YAML
174174

@@ -180,7 +180,7 @@ def test_that_mref_doesnt_delete_keys
180180
assert_equal({ "key1" => "value1", "key2" => "value2", "key3" => "value3_new" }, doc["child"])
181181
end
182182

183-
def test_that_double_mref_doesnt_delete_keys
183+
def test_that_double_inherits_doesnt_delete_keys
184184
yaml = <<~YAML
185185
base1:
186186
key1: value1
@@ -193,7 +193,7 @@ def test_that_double_mref_doesnt_delete_keys
193193
key6: value6
194194
195195
child:
196-
$mref:
196+
$inherits:
197197
- "#/base1"
198198
- "#/base2"
199199
key3: value3_new
@@ -274,23 +274,23 @@ def test_refs_in_the_different_document
274274
assert_equal({ "a" => "hash" }, doc["obj3"])
275275
end
276276

277-
def test_mrefs_in_the_same_document
277+
def test_inheritss_in_the_same_document
278278
yaml = <<~YAML
279279
$defs:
280280
target1: A string
281281
target2:
282282
a: hash
283283
284284
obj1:
285-
$mref: "#/$defs/target2"
285+
$inherits: "#/$defs/target2"
286286
287287
obj2:
288-
$mref: "#/$defs/target2"
288+
$inherits: "#/$defs/target2"
289289
a: Should take precedence
290290
291291
obj3:
292292
a: Should take precedence
293-
$mref: "#/$defs/target2"
293+
$inherits: "#/$defs/target2"
294294
295295
YAML
296296

@@ -304,7 +304,7 @@ def test_mrefs_in_the_same_document
304304
assert_equal({ "a" => "Should take precedence" }, doc["obj3"])
305305
end
306306

307-
def test_mrefs_in_the_different_document
307+
def test_inheritss_in_the_different_document
308308
yaml1 = <<~YAML
309309
$defs:
310310
target1: A string
@@ -319,15 +319,15 @@ def test_mrefs_in_the_different_document
319319

320320
yaml2 = <<~YAML
321321
obj1:
322-
$mref: "#{f1_path.basename}#/$defs/target2"
322+
$inherits: "#{f1_path.basename}#/$defs/target2"
323323
324324
obj2:
325-
$mref: "#{f1_path.basename}#/$defs/target2"
325+
$inherits: "#{f1_path.basename}#/$defs/target2"
326326
a: Should take precedence
327327
328328
obj3:
329329
a: Should take precedence
330-
$mref: "#{f1_path.basename}#/$defs/target2"
330+
$inherits: "#{f1_path.basename}#/$defs/target2"
331331
YAML
332332

333333
f2 = Tempfile.new("yml")
@@ -340,7 +340,7 @@ def test_mrefs_in_the_different_document
340340
assert_equal({ "a" => "Should take precedence" }, doc["obj3"])
341341
end
342342

343-
def test_multi_mrefs_in_the_same_document
343+
def test_multi_inheritss_in_the_same_document
344344
yaml = <<~YAML
345345
$defs:
346346
target1:
@@ -349,7 +349,7 @@ def test_multi_mrefs_in_the_same_document
349349
a: hash
350350
351351
obj1:
352-
$mref:
352+
$inherits:
353353
- "#/$defs/target1"
354354
- "#/$defs/target2"
355355
@@ -363,7 +363,7 @@ def test_multi_mrefs_in_the_same_document
363363
assert_equal({ "a" => "hash", "b" => "nice" }, doc["obj1"])
364364
end
365365

366-
def test_that_invalid_mrefs_raise
366+
def test_that_invalid_inheritss_raise
367367
yaml = <<~YAML
368368
$defs:
369369
target1:
@@ -372,7 +372,7 @@ def test_that_invalid_mrefs_raise
372372
a: hash
373373
374374
obj1:
375-
$mref: "#/path/to/nowwhere"
375+
$inherits: "#/path/to/nowwhere"
376376
377377
YAML
378378

lib/yaml_loader.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require "pathname"
44
require "yaml"
55

6-
# loads a YAML file and expands any $ref/$mref references
6+
# loads a YAML file and expands any $ref/$inherits references
77
class YamlLoader
88
@cache = {}
99

@@ -46,42 +46,42 @@ def self.expand(filename, obj, yaml_opts = {})
4646

4747
ref
4848
end
49-
elsif obj.keys.include?("$mref")
50-
# we handle the mref key first so that any override will take priority
51-
mref = obj["$mref"]
52-
raise ArgumentError, "Missing reference after $mref (did you forget to put a relative reference in quotes?)" if mref.nil?
53-
mref_targets = mref.is_a?(String) ? [mref] : mref
49+
elsif obj.keys.include?("$inherits")
50+
# we handle the inherits key first so that any override will take priority
51+
inherits = obj["$inherits"]
52+
raise ArgumentError, "Missing reference after $inherits (did you forget to put a relative reference in quotes?)" if inherits.nil?
53+
inherits_targets = inherits.is_a?(String) ? [inherits] : inherits
5454

5555
new_obj = {}
5656

57-
mref_targets.each do |mref_target|
58-
relative_path = mref_target.split("#")[0]
57+
inherits_targets.each do |inherits_target|
58+
relative_path = inherits_target.split("#")[0]
5959
target_obj =
6060
if relative_path.empty?
6161
YAML.load_file(filename, **yaml_opts)
6262
else
6363
target_filename = File.realpath(File.join(filename.dirname, relative_path))
6464

6565
unless File.exist?(target_filename)
66-
raise DereferenceError, "While locating $mref in #{filename}, #{target_filename} does not exist"
66+
raise DereferenceError, "While locating $inherits in #{filename}, #{target_filename} does not exist"
6767
end
6868

6969
YamlLoader.load(target_filename, yaml_opts)
7070
end
7171

72-
mref_target_suffix = mref_target.split("#/")[1]
73-
mref_target_path = mref_target_suffix.split("/")
72+
inherits_target_suffix = inherits_target.split("#/")[1]
73+
inherits_target_path = inherits_target_suffix.split("/")
7474
begin
75-
target_obj = target_obj.dig(*mref_target_path)
75+
target_obj = target_obj.dig(*inherits_target_path)
7676
rescue TypeError => e
7777
if e.message == "no implicit conversion of String into Integer"
78-
warn "$mref: \"#{mref_target}\" found in file #{filename} references an Array but needs to reference a Hash"
78+
warn "$inherits: \"#{inherits_target}\" found in file #{filename} references an Array but needs to reference a Hash"
7979
end
8080
raise e
8181
end
8282

83-
raise DereferenceError, "JSON Path #{mref_target_suffix} in file #{filename} does not exist in #{relative_path}" if target_obj.nil?
84-
raise ArgumentError, "$mref: \"#{mref_target}\" in file #{filename} references a #{target_obj.class} but needs to reference a Hash" unless target_obj.is_a?(Hash)
83+
raise DereferenceError, "JSON Path #{inherits_target_suffix} in file #{filename} does not exist in #{relative_path}" if target_obj.nil?
84+
raise ArgumentError, "$inherits: \"#{inherits_target}\" in file #{filename} references a #{target_obj.class} but needs to reference a Hash" unless target_obj.is_a?(Hash)
8585

8686
target_obj = expand(filename, target_obj, yaml_opts)
8787
target_obj.each do |target_key, target_value|
@@ -94,7 +94,7 @@ def self.expand(filename, obj, yaml_opts = {})
9494
end
9595
end
9696

97-
obj.delete("$mref")
97+
obj.delete("$inherits")
9898
# now merge target_obj and obj
9999
keys = (obj.keys + new_obj.keys).uniq
100100
final_obj = {}
@@ -138,7 +138,7 @@ def self.expand(filename, obj, yaml_opts = {})
138138
new_obj
139139
end
140140

141-
# load a YAML file and expand any $ref/$mref references
141+
# load a YAML file and expand any $ref/$inherits references
142142
# @param filename [String,Pathname] path to the YAML file
143143
# @param yaml_opts [Hash] options to pass to YAML.load_file
144144
# @return [Object] the loaded YAML file

schemas/inst_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"name": {
6363
"type": "string"
6464
},
65-
"$mref": {
65+
"$inherits": {
6666
"type": "string",
6767
"pattern": "^(\\.\\./)+common/inst_variable_types\\.yaml#/[a-zA-Z0-9_]+",
6868
"description": "Reference to variable metadata"

0 commit comments

Comments
 (0)