Skip to content

Commit 27a3331

Browse files
committed
Add MetaSpace to capture documentation, origins...
1 parent d5c7669 commit 27a3331

80 files changed

Lines changed: 944 additions & 873 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

key.core.wd/src/main/java/de/uka/ilkd/key/wd/WdWhileInvariantRule.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import org.jspecify.annotations.NonNull;
1919
import org.jspecify.annotations.NullMarked;
20-
import org.jspecify.annotations.Nullable;
2120

2221

2322
@NullMarked
@@ -38,11 +37,6 @@ public Name name() {
3837
return NAME;
3938
}
4039

41-
@Override
42-
public @Nullable String getOrigin() {
43-
return super.getOrigin();
44-
}
45-
4640
protected static class WdWhileInvariantRuleApplier extends WhileInvariantRuleApplier {
4741
public WdWhileInvariantRuleApplier(Goal goal, LoopInvariantBuiltInRuleApp<?> ruleApp) {
4842
super(goal, ruleApp);

key.core/src/main/antlr4/KeYParser.g4

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,18 @@ one_sort_decl
9090
:
9191
doc=DOC_COMMENT?
9292
(
93-
GENERIC sortIds=simple_ident_dots_comma_list
93+
GENERIC sortIds=simple_ident_dots_comma_list_with_docs
9494
(ONEOF sortOneOf = oneof_sorts)?
9595
(EXTENDS sortExt = extends_sorts)? SEMI
96-
| PROXY sortIds=simple_ident_dots_comma_list (EXTENDS sortExt=extends_sorts)? SEMI
97-
| ABSTRACT? (sortIds=simple_ident_dots_comma_list | parametric_sort_decl) (EXTENDS sortExt=extends_sorts)? SEMI
96+
| PROXY sortIds=simple_ident_dots_comma_list_with_docs (EXTENDS sortExt=extends_sorts)? SEMI
97+
| ABSTRACT? (sortIds=simple_ident_dots_comma_list_with_docs | parametric_sort_decl) (EXTENDS sortExt=extends_sorts)? SEMI
9898
| ALIAS simple_ident_dots EQUALS sortId SEMI
9999
)
100100
;
101101

102102
parametric_sort_decl
103103
:
104+
DOC_COMMENT?
104105
simple_ident_dots
105106
formal_sort_param_decls
106107
;
@@ -115,6 +116,13 @@ simple_ident_dots_comma_list
115116
simple_ident_dots (COMMA simple_ident_dots)*
116117
;
117118

119+
simple_ident_dots_comma_list_with_docs
120+
:
121+
simple_ident_dots_with_docs (COMMA simple_ident_dots_with_docs)*
122+
;
123+
124+
simple_ident_dots_with_docs: DOC_COMMENT? simple_ident_dots;
125+
118126

119127
extends_sorts
120128
:
@@ -139,7 +147,7 @@ prog_var_decls
139147
LBRACE
140148
(
141149
kjt = keyjavatype
142-
var_names = simple_ident_comma_list
150+
var_names = simple_ident_comma_list_with_docs
143151
SEMI
144152
)*
145153
RBRACE
@@ -161,6 +169,10 @@ simple_ident_comma_list
161169
id = simple_ident (COMMA id = simple_ident )*
162170
;
163171

172+
simple_ident_comma_list_with_docs
173+
:
174+
id+=simple_ident_with_doc (COMMA id+=simple_ident_with_doc)*
175+
;
164176

165177
schema_var_decls :
166178
SCHEMAVARIABLES LBRACE
@@ -259,6 +271,7 @@ datatype_decl:
259271
;
260272

261273
datatype_constructor:
274+
doc=DOC_COMMENT?
262275
name=simple_ident
263276
(
264277
LPAREN
@@ -341,7 +354,12 @@ where_to_bind:
341354

342355
ruleset_decls
343356
:
344-
HEURISTICSDECL LBRACE (doc+=DOC_COMMENT? id+=simple_ident SEMI)* RBRACE
357+
HEURISTICSDECL LBRACE (id+=simple_ident_with_doc SEMI)* RBRACE
358+
;
359+
360+
simple_ident_with_doc
361+
:
362+
doc=DOC_COMMENT? id=simple_ident
345363
;
346364

347365
sortId

key.core/src/main/java/de/uka/ilkd/key/java/Recoder2KeYConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,13 +762,14 @@ public DLEmbeddedExpression convert(EscapeExpression e) {
762762
sortName, e.getStartPosition()));
763763
}
764764

765-
var doc = sort.getDocumentation();
765+
var doc = namespaceSet.docs().findDocumentation(sort);
766+
var origin = namespaceSet.docs().findOrigin(sort);
766767

767768
if (doc == null) {
768769
throw new ConvertException(
769770
format("Requested to find the default value for the sort '%s', "
770771
+ "which does not have a documentary comment. The sort is defined at %s. "
771-
+ "Line/Col: %s", sortName, sort.getOrigin(), e.getStartPosition()));
772+
+ "Line/Col: %s", sortName, origin, e.getStartPosition()));
772773
}
773774

774775
int pos = doc.indexOf(DEFVALUE);
@@ -779,7 +780,7 @@ public DLEmbeddedExpression convert(EscapeExpression e) {
779780
if (closing < 0) {
780781
throw new ConvertException(format(
781782
"Forgotten closing parenthesis on @defaultValue annotation for sort '%s' in '%s'",
782-
sortName, sort.getOrigin()));
783+
sortName, origin));
783784
}
784785

785786
// set this as the function name, as the user had written \dl_XXX

key.core/src/main/java/de/uka/ilkd/key/logic/JTerm.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.key_project.util.collection.ImmutableSet;
1717

1818
import org.jspecify.annotations.NonNull;
19-
import org.jspecify.annotations.Nullable;
2019

2120
/**
2221
* In contrast to the distinction of formulas and terms as made by most of the inductive definitions
@@ -118,9 +117,4 @@ public interface JTerm
118117
* non-empty {@link JavaBlock}, {@code false} no {@link JavaBlock} available.
119118
*/
120119
boolean containsJavaBlockRecursive();
121-
122-
/**
123-
* Returns a human-readable source of this term. For example the filename with line and offset.
124-
*/
125-
default @Nullable String getOrigin() { return null; }
126120
}

key.core/src/main/java/de/uka/ilkd/key/logic/LabeledTermImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class LabeledTermImpl extends TermImpl {
5252
public LabeledTermImpl(Operator op, ImmutableArray<JTerm> subs,
5353
ImmutableArray<QuantifiableVariable> boundVars,
5454
ImmutableArray<TermLabel> labels, String origin) {
55-
super(op, subs, boundVars, origin);
55+
super(op, subs, boundVars);
5656
assert labels != null : "Term labels must not be null";
5757
assert !labels.isEmpty() : "There must be at least one term label";
5858
this.labels = labels;
@@ -69,7 +69,7 @@ public LabeledTermImpl(Operator op, ImmutableArray<JTerm> subs,
6969
public LabeledTermImpl(Operator op, ImmutableArray<JTerm> subs,
7070
ImmutableArray<QuantifiableVariable> boundVars,
7171
ImmutableArray<TermLabel> labels) {
72-
super(op, subs, boundVars, "");
72+
super(op, subs, boundVars);
7373
assert labels != null : "Term labels must not be null";
7474
assert !labels.isEmpty() : "There must be at least one term label";
7575
this.labels = labels;
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/* This file is part of KeY - https://key-project.org
2+
* KeY is licensed under the GNU General Public License Version 2
3+
* SPDX-License-Identifier: GPL-2.0-only */
4+
package de.uka.ilkd.key.logic;
5+
6+
import java.util.Map;
7+
import java.util.TreeMap;
8+
9+
import org.key_project.logic.HasMeta;
10+
11+
import org.jspecify.annotations.NullMarked;
12+
import org.jspecify.annotations.Nullable;
13+
14+
/// MetaSpace is a namespace for storing additional information
15+
///
16+
/// @author weigl
17+
@NullMarked
18+
public class MetaSpace {
19+
public static final String SPACE_PREFIX_DOC = "doc/";
20+
public static final String SPACE_PREFIX_ORIGIN = "origin/";
21+
22+
private @Nullable MetaSpace parent;
23+
private final Map<String, Object> metadata = new TreeMap<>();
24+
25+
public MetaSpace() {
26+
}
27+
28+
public MetaSpace(Map<String, Object> documentation) {
29+
this.metadata.putAll(documentation);
30+
}
31+
32+
public MetaSpace(MetaSpace parent) {
33+
this.parent = parent;
34+
}
35+
36+
private @Nullable Object findMetadata(String key) {
37+
return metadata.get(key);
38+
}
39+
40+
public @Nullable String findDocumentation(HasMeta entity) {
41+
if (entity.getDocumentation() != null) {
42+
return entity.getDocumentation();
43+
}
44+
return (String) findMetadata(SPACE_PREFIX_DOC + entity.getMetaKey());
45+
}
46+
47+
/**
48+
* Returns a human-readable source of this term. For example the filename with line and offset.
49+
*/
50+
public @Nullable String findOrigin(HasMeta entity) {
51+
return (String) findMetadata(SPACE_PREFIX_ORIGIN + entity.getMetaKey());
52+
}
53+
54+
public void add(MetaSpace space) {
55+
this.metadata.putAll(space.metadata);
56+
}
57+
58+
public @Nullable MetaSpace parent() {
59+
return parent;
60+
}
61+
62+
public void setDocumentation(HasMeta entity, @Nullable String doc) {
63+
setMetadata(SPACE_PREFIX_DOC, entity, doc);
64+
}
65+
66+
public void setOrigin(HasMeta entity, @Nullable String origin) {
67+
setMetadata(SPACE_PREFIX_ORIGIN, entity, origin);
68+
}
69+
70+
private void setMetadata(String prefix, HasMeta entity, @Nullable Object val) {
71+
var key = prefix + entity.getMetaKey();
72+
if (val == null) {
73+
metadata.remove(key);
74+
} else {
75+
metadata.put(key, val);
76+
}
77+
}
78+
79+
80+
public MetaSpace copy() {
81+
return new MetaSpace(metadata);
82+
}
83+
}

0 commit comments

Comments
 (0)