Skip to content

Commit 9c245c0

Browse files
author
Andrei Ovsyankin
committed
Merge branch 'release/v1.0.21' into develop
2 parents d9db252 + e42937f commit 9c245c0

File tree

9 files changed

+108
-27
lines changed

9 files changed

+108
-27
lines changed

src/ScriptEngine.HostedScript/Library/Http/HttpRequestContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public IValue GetBodyAsString()
113113
return _body.GetAsString();
114114
}
115115

116-
[ContextMethod("ПолучитьТелоКакПоток", "GetBodyAsString")]
116+
[ContextMethod("ПолучитьТелоКакПоток", "GetBodyAsStream")]
117117
public GenericStream GetBodyAsStream()
118118
{
119119
return new GenericStream(_body.GetDataStream());

src/ScriptEngine.HostedScript/Library/Reflector.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*----------------------------------------------------------
1+
/*----------------------------------------------------------
22
This Source Code Form is subject to the terms of the
33
Mozilla Public License, v.2.0. If a copy of the MPL
44
was not distributed with this file, You can obtain one
@@ -240,7 +240,7 @@ private static void FillMethodsTableForObject(IRuntimeContextInstance target, Va
240240
private static void FillMethodsTableForType(TypeTypeValue type, ValueTable.ValueTable result)
241241
{
242242
var clrType = GetReflectableClrType(type);
243-
var clrMethods = clrType.GetMethods();
243+
var clrMethods = clrType.GetMethods(BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public);
244244
FillMethodsTable(result, ConvertToOsMethods(clrMethods));
245245
}
246246

@@ -290,22 +290,38 @@ private static void FillPropertiesTableForType(TypeTypeValue type, ValueTable.Va
290290
PropDef = x.GetCustomAttribute<ContextPropertyAttribute>(),
291291
Prop = x
292292
})
293-
.Where(x=>x.PropDef != null)
294-
.ToArray();
293+
.Where(x=>x.PropDef != null);
295294

296-
var infos = new VariableInfo[nativeProps.Length];
297-
for (int i = 0; i < nativeProps.Length; i++)
295+
int indices = 0;
296+
var infos = new List<VariableInfo>();
297+
foreach(var prop in nativeProps)
298298
{
299-
infos[i] = new VariableInfo();
300-
infos[i].Type = SymbolType.ContextProperty;
301-
infos[i].Index = i;
302-
infos[i].Identifier = nativeProps[i].PropDef.GetName();
303-
infos[i].Annotations = GetAnnotations(nativeProps[i].Prop.GetCustomAttributes<UserAnnotationAttribute>());
299+
var info = new VariableInfo();
300+
info.Type = SymbolType.ContextProperty;
301+
info.Index = indices++;
302+
info.Identifier = prop.PropDef.GetName();
303+
info.Annotations = GetAnnotations(prop.Prop.GetCustomAttributes<UserAnnotationAttribute>());
304+
infos.Add(info);
305+
}
306+
307+
if (clrType.BaseType == typeof(ScriptDrivenObject))
308+
{
309+
var nativeFields = clrType.GetFields();
310+
foreach(var field in nativeFields)
311+
{
312+
var info = new VariableInfo();
313+
info.Type = SymbolType.ContextProperty;
314+
info.Index = indices++;
315+
info.Identifier = field.Name;
316+
info.Annotations = GetAnnotations(field.GetCustomAttributes<UserAnnotationAttribute>());
317+
infos.Add(info);
318+
}
304319
}
305320

306321
FillPropertiesTable(result, infos);
322+
307323
}
308-
324+
309325
private static void FillMethodsTable(ValueTable.ValueTable result, IEnumerable<MethodInfo> methods)
310326
{
311327
var nameColumn = result.Columns.Add("Имя", TypeDescription.StringType(), "Имя");

src/ScriptEngine.HostedScript/ScriptEngine.HostedScript.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<PackageTags>BSL 1C 1Script OneScript</PackageTags>
3333
</PropertyGroup>
3434
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)'=='Release|net452'">
35-
<DocumentationFile></DocumentationFile>
35+
<DocumentationFile>bin\Release\net452\ScriptEngine.HostedScript.xml</DocumentationFile>
3636
<NoWarn>1701;1702;1705;1591</NoWarn>
3737
</PropertyGroup>
3838

src/ScriptEngine/Compiler/Compiler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Compiler {
2828
private Parser _parser;
2929
private ICompilerContext _ctx;
3030
private ModuleImage _module;
31-
private Lexem _previousExtractedLexem;
3231
private Lexem _lastExtractedLexem;
3332
private bool _inMethodScope = false;
3433
private bool _isMethodsDefined = false;
@@ -2008,7 +2007,6 @@ private void NextToken()
20082007
{
20092008
if (_lastExtractedLexem.Token != Token.EndOfText)
20102009
{
2011-
_previousExtractedLexem = _lastExtractedLexem;
20122010
_lastExtractedLexem = _parser.NextLexem();
20132011
}
20142012
else
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*----------------------------------------------------------
2+
This Source Code Form is subject to the terms of the
3+
Mozilla Public License, v.2.0. If a copy of the MPL
4+
was not distributed with this file, You can obtain one
5+
at http://mozilla.org/MPL/2.0/.
6+
----------------------------------------------------------*/
7+
8+
using System;
9+
10+
11+
namespace ScriptEngine.Machine.Contexts
12+
{
13+
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Enum)]
14+
public class DocumenterHintAttribute : Attribute
15+
{
16+
public string Name { get; set; }
17+
18+
public string Alias { get; set; }
19+
20+
public ContextKind Kind { get; set; }
21+
}
22+
23+
public enum ContextKind
24+
{
25+
Class,
26+
GlobalContext,
27+
Enumeration
28+
}
29+
}

src/ScriptEngine/Machine/LoadedModule.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,17 @@ public LoadedModule(ModuleImage image)
3333
var def = image.Constants[i];
3434
Constants[i] = ValueFactory.Parse(def.Presentation, def.Type);
3535
}
36-
37-
// Resolve annotation constants
36+
37+
ResolveAnnotationConstants();
38+
}
39+
40+
private void ResolveAnnotationConstants()
41+
{
42+
for (int i = 0; i < Variables.Count; i++)
43+
{
44+
EvaluateAnnotationParametersValues(Variables[i].Annotations);
45+
}
46+
3847
for (int i = 0; i < Methods.Length; i++)
3948
{
4049
EvaluateAnnotationParametersValues(Methods[i].Signature.Annotations);
@@ -43,7 +52,6 @@ public LoadedModule(ModuleImage image)
4352
EvaluateAnnotationParametersValues(Methods[i].Signature.Params[j].Annotations);
4453
}
4554
}
46-
4755
}
4856

4957
private void EvaluateAnnotationParametersValues(AnnotationDefinition[] annotations)

src/ScriptEngine/Machine/Reflection/ClassBuilder.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ public IReflectedClassBuilder ExportScriptVariables()
134134
System.Diagnostics.Debug.Assert(variable.Index == exported.Index, "indices of vars and exports are equal");
135135

136136
var fieldInfo = new ReflectedFieldInfo(variable, exportFlag);
137+
if (variable.Annotations != null)
138+
{
139+
foreach (var annotation in variable.Annotations)
140+
{
141+
fieldInfo.AddAnnotation(annotation);
142+
}
143+
}
144+
137145
_fields.Add(fieldInfo);
138146
}
139147

src/ScriptEngine/Machine/Reflection/ReflectedFieldInfo.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class ReflectedFieldInfo : FieldInfo
2323
private bool _isPublic;
2424
private readonly VariableInfo _info;
2525

26+
private readonly List<UserAnnotationAttribute> _attributes = new List<UserAnnotationAttribute>();
27+
2628
public ReflectedFieldInfo(VariableInfo info, bool isPublic)
2729
{
2830
_info = info;
@@ -34,14 +36,25 @@ public void SetDeclaringType(Type declType)
3436
_declaringType = declType;
3537
}
3638

39+
private IEnumerable<UserAnnotationAttribute> GetCustomAttributesInternal(bool inherit)
40+
{
41+
return _attributes;
42+
}
43+
3744
public override object[] GetCustomAttributes(bool inherit)
3845
{
39-
return new object[0];
46+
return GetCustomAttributesInternal(inherit).ToArray();
47+
}
48+
49+
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
50+
{
51+
var attribs = GetCustomAttributesInternal(inherit);
52+
return attribs.Where(x => x.GetType() == attributeType).ToArray();
4053
}
4154

4255
public override bool IsDefined(Type attributeType, bool inherit)
4356
{
44-
return false;
57+
return GetCustomAttributes(inherit).Any(x => x.GetType() == attributeType);
4558
}
4659

4760
public override object GetValue(object obj)
@@ -92,9 +105,12 @@ public override RuntimeFieldHandle FieldHandle
92105
get { throw new NotImplementedException(); }
93106
}
94107

95-
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
108+
public void AddAnnotation(AnnotationDefinition annotation)
96109
{
97-
return GetCustomAttributes(inherit);
110+
_attributes.Add(new UserAnnotationAttribute()
111+
{
112+
Annotation = annotation
113+
});
98114
}
99115
}
100116
}

src/ScriptEngine/Machine/Reflection/ReflectedParamInfo.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ namespace ScriptEngine.Machine.Contexts
1717
{
1818
public class ReflectedParamInfo : ParameterInfo
1919
{
20-
private readonly List<object> _attributes;
20+
private readonly List<Attribute> _attributes;
2121

2222
public ReflectedParamInfo(string name, bool isByVal)
2323
{
24+
_attributes = new List<Attribute>();
2425
NameImpl = name;
2526
AttrsImpl = ParameterAttributes.In;
2627
if (!isByVal)
@@ -29,7 +30,6 @@ public ReflectedParamInfo(string name, bool isByVal)
2930
}
3031

3132
ClassImpl = typeof(IValue);
32-
_attributes = new List<object>();
3333
}
3434

3535
internal void SetOwner(MemberInfo owner)
@@ -59,14 +59,20 @@ public void SetDefaultValue(IValue val)
5959

6060
public override bool HasDefaultValue => DefaultValue != null;
6161

62+
private IEnumerable<Attribute> GetCustomAttributesInternal(bool inherit)
63+
{
64+
return _attributes;
65+
}
66+
6267
public override object[] GetCustomAttributes(bool inherit)
6368
{
64-
return _attributes.ToArray();
69+
return GetCustomAttributesInternal(inherit).ToArray();
6570
}
6671

6772
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
6873
{
69-
return GetCustomAttributes(inherit).Where(x => x.GetType() == attributeType).ToArray();
74+
var attribs = GetCustomAttributesInternal(inherit);
75+
return attribs.Where(x => x.GetType() == attributeType).ToArray();
7076
}
7177

7278
public override bool IsDefined(Type attributeType, bool inherit)

0 commit comments

Comments
 (0)