Skip to content

Commit a2fa4ea

Browse files
committed
Убрана завязка на константы образа.
1 parent eb5fe02 commit a2fa4ea

File tree

8 files changed

+33
-69
lines changed

8 files changed

+33
-69
lines changed

src/OneScript.Core/Contexts/BslAnnotationAttribute.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,5 @@ public BslAnnotationParameter(string name, BslPrimitiveValue value = null)
4747

4848
public BslPrimitiveValue Value { get; }
4949

50-
public int ConstantValueIndex { get; set; } = -1;
5150
}
5251
}

src/OneScript.Core/Values/BslAnnotationValue.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ public override string ToString()
4747
foreach (var parameter in Parameters)
4848
{
4949
sb.Append(prefix);
50+
sb.Append(parameter);
5051
prefix = ",";
51-
sb.Append(parameter.Name);
52-
sb.Append("=");
53-
sb.Append(parameter.ConstantValueIndex);
5452
}
5553
sb.Append(")");
5654
}

src/ScriptEngine/Compiler/StackMachineCodeGenerator.cs

Lines changed: 19 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,73 +1171,44 @@ private IEnumerable<BslAnnotationParameter> GetAnnotationParameters(AnnotationNo
11711171

11721172
private BslAnnotationParameter MakeAnnotationParameter(AnnotationParameterNode param)
11731173
{
1174-
var constValue = MakeAnnotationParameterValueConstant(param);
1175-
return new BslAnnotationParameter(param.Name, constValue.runtimeValue) { ConstantValueIndex = constValue.constNumber };
1174+
var runtimeValue = MakeAnnotationParameterValueConstant(param);
1175+
return new BslAnnotationParameter(param.Name, runtimeValue);
11761176
}
11771177

1178-
private (BslPrimitiveValue runtimeValue, int constNumber) MakeAnnotationParameterValueConstant(AnnotationParameterNode param)
1178+
private BslPrimitiveValue MakeAnnotationParameterValueConstant(AnnotationParameterNode param)
11791179
{
11801180
if (param.AnnotationNode != null)
11811181
{
1182-
var constNumber = CreateAnnotationConstDefinition(param.AnnotationNode);
1183-
var runtimeValue = _module.Constants[constNumber];
1184-
return (runtimeValue, constNumber);
1182+
var runtimeValue = new BslAnnotationValue(param.AnnotationNode.Name);
1183+
foreach (var child in param.AnnotationNode.Children)
1184+
{
1185+
var parameter = (AnnotationParameterNode)child;
1186+
var parameterValue = MakeAnnotationParameterValueConstant(parameter);
1187+
runtimeValue.Parameters.Add(new BslAnnotationParameter(parameter.Name, parameterValue));
1188+
}
1189+
var constNumber = CreateAnnotationConstDefinition(runtimeValue);
1190+
return runtimeValue;
11851191
}
11861192
else
11871193
if (param.Value.Type != LexemType.NotALexem)
11881194
{
11891195
var constDef = CreateConstDefinition(param.Value);
11901196
var constNumber = GetConstNumber(constDef);
11911197
var runtimeValue = _module.Constants[constNumber];
1192-
return (runtimeValue, constNumber);
1198+
return runtimeValue;
11931199
}
11941200
else
11951201
{
1196-
return (null, -1);
1202+
return null;
11971203
}
11981204
}
11991205

1200-
private int CreateAnnotationConstDefinition(AnnotationNode annotationNode)
1206+
private int CreateAnnotationConstDefinition(BslAnnotationValue runtimeValue)
12011207
{
1202-
var runtimeValue = new BslAnnotationValue(annotationNode.Name);
1203-
var presentation = AnnotationConstPresentation(annotationNode, runtimeValue);
1204-
ConstDefinition cDef = new ConstDefinition() {
1205-
Type = DataType.Annotation,
1206-
Presentation = presentation
1207-
};
1208-
var result = RegisterAnnotationConst(cDef, runtimeValue);
1208+
var result = RegisterAnnotationConst(runtimeValue);
12091209
return result;
12101210
}
12111211

1212-
private string AnnotationConstPresentation(AnnotationNode annotationNode, BslAnnotationValue annotationRuntimeValue)
1213-
{
1214-
var sb = new StringBuilder("&");
1215-
sb.Append(annotationNode.Name);
1216-
if (annotationNode.Children.Count > 0)
1217-
{
1218-
var prefix = "(";
1219-
foreach (var child in annotationNode.Children)
1220-
{
1221-
sb.Append(prefix);
1222-
prefix = ",";
1223-
1224-
var parameter = (AnnotationParameterNode)child;
1225-
var constValue = MakeAnnotationParameterValueConstant(parameter);
1226-
sb.Append(parameter.Name);
1227-
sb.Append("=");
1228-
sb.Append(constValue.constNumber);
1229-
1230-
var parameterValue = constValue.constNumber != -1
1231-
? new BslAnnotationParameter(parameter.Name, _module.Constants[constValue.constNumber]) { ConstantValueIndex = constValue.constNumber }
1232-
: new BslAnnotationParameter(parameter.Name);
1233-
annotationRuntimeValue.Parameters.Add(parameterValue);
1234-
}
1235-
sb.Append(")");
1236-
}
1237-
1238-
return sb.ToString();
1239-
}
1240-
12411212
private IEnumerable<BslAnnotationAttribute> GetAnnotations(AnnotatableNode parent)
12421213
{
12431214
return parent.Annotations.Select(a =>
@@ -1297,11 +1268,10 @@ private int GetConstNumber(in ConstDefinition cDef)
12971268
return idx;
12981269
}
12991270

1300-
private int RegisterAnnotationConst(in ConstDefinition cDef, BslAnnotationValue value)
1271+
private int RegisterAnnotationConst(BslAnnotationValue value)
13011272
{
1302-
var idx = _constMap.Count;
1303-
_constMap.Add(cDef);
1304-
_module.Constants.Add(value);
1273+
var idx = _module.AnnotationValues.Count;
1274+
_module.AnnotationValues.Add(value);
13051275
return idx;
13061276
}
13071277

src/ScriptEngine/Machine/AnnotationParameter.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,33 @@ This Source Code Form is subject to the terms of the
55
at http://mozilla.org/MPL/2.0/.
66
----------------------------------------------------------*/
77
using System;
8+
using System.Collections.Generic;
89

910
namespace ScriptEngine.Machine
1011
{
1112
[Serializable]
1213
public struct AnnotationParameter
1314
{
1415
public string Name;
15-
public int ValueIndex;
1616

1717
[NonSerialized]
1818
public IValue RuntimeValue;
1919

2020
public const int UNDEFINED_VALUE_INDEX = -1;
2121

22+
2223
public override string ToString()
2324
{
24-
if (string.IsNullOrEmpty(Name))
25+
var list = new List<string>();
26+
if (!string.IsNullOrEmpty(Name))
2527
{
26-
return string.Format("[{0}]", ValueIndex);
28+
list.Add(Name);
2729
}
28-
if (ValueIndex == UNDEFINED_VALUE_INDEX && RuntimeValue == null)
30+
if (RuntimeValue != null)
2931
{
30-
return Name;
32+
list.Add(RuntimeValue.ToString());
3133
}
32-
return string.Format("{0}=[{1}]", Name, RuntimeValue.ToString());
34+
return string.Join("=", list);
3335
}
3436
}
3537
}

src/ScriptEngine/Machine/Core.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ public enum DataType
161161
Number,
162162
Date,
163163
Boolean,
164-
Null,
165-
Annotation
164+
Null
166165
}
167166

168167
[Serializable]

src/ScriptEngine/Machine/StackRuntimeAdoptionExtensions.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public static AnnotationParameter ToMachineDefinition(this BslAnnotationParamete
5252
return new AnnotationParameter
5353
{
5454
Name = parameter.Name,
55-
ValueIndex = parameter.ConstantValueIndex,
5655
RuntimeValue = parameter.Value,
5756
};
5857
}
@@ -82,10 +81,7 @@ public static BslAnnotationAttribute MakeBslAttribute(this in AnnotationDefiniti
8281
if (annotation.ParamCount > 0)
8382
{
8483
attribute.SetParameters(annotation.Parameters.Select(p =>
85-
new BslAnnotationParameter(p.Name, (BslPrimitiveValue) p.RuntimeValue)
86-
{
87-
ConstantValueIndex = p.ValueIndex
88-
}));
84+
new BslAnnotationParameter(p.Name, (BslPrimitiveValue) p.RuntimeValue)));
8985
}
9086

9187
return attribute;

src/ScriptEngine/Machine/StackRuntimeModule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public StackRuntimeModule(Type ownerType)
3131
internal IList<SymbolBinding> VariableRefs { get; } = new List<SymbolBinding>();
3232

3333
internal IList<SymbolBinding> MethodRefs { get; } = new List<SymbolBinding>();
34+
35+
internal IList<BslAnnotationValue> AnnotationValues { get; } = new List<BslAnnotationValue>();
3436

3537
#region IExecutableModule members
3638

src/Tests/OneScript.Core.Tests/CodeGenerationTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ Процедура Процедура1() Экспорт
6464
КонецПроцедуры";
6565
var image = BuildModule(code, Mock.Of<IBslProcess>());
6666
image.Should().NotBeNull();
67-
// В константах будет только значение первого уровня: &ТожеАннотация.
68-
// Внутри нее уже будет сериализованное значение
69-
image.Constants.Should().HaveCount(3);
67+
image.Constants.Should().HaveCount(0);
7068
image.Methods.Should().HaveCount(1);
7169
image.Fields.Should().BeEmpty();
7270

0 commit comments

Comments
 (0)