Skip to content

Commit

Permalink
Рефлектор возвращает приватные поля и методы
Browse files Browse the repository at this point in the history
Так же исправил ошибку #1248
  • Loading branch information
Absolemus committed Jan 11, 2023
1 parent e44fbc8 commit 4c1aab6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
22 changes: 21 additions & 1 deletion src/NUnitTests/CompilerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -532,5 +532,25 @@ Если Ложь Тогда
}
Assert.IsTrue(exceptionThrown, "Отсутствует точка с запятой между операторами!");
}
}

[Test]
public void TestLocalExportVar()
{
var moduleSource = host.Engine.Loader.FromString(
@"Процедура Проц1()
Перем Переменная Экспорт;
КонецПроцедуры");

bool exceptionThrown = false;
try
{
_ = host.Engine.GetCompilerService().Compile(moduleSource);
}
catch (CompilerException)
{
exceptionThrown = true;
}
Assert.IsTrue(exceptionThrown, "В теле процедуры или функции не может быть объявлена экспортная переменная!");
}
}
}
17 changes: 9 additions & 8 deletions src/ScriptEngine/Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,18 @@ private void BuildVariableDefinitions()
var symbolicName = _lastExtractedLexem.Content;
var annotations = ExtractAnnotations();
var definition = _ctx.DefineVariable(symbolicName);
var variableInfo = new VariableInfo();
NextToken();
if (_inMethodScope)
{
if (_isStatementsDefined)
{
throw CompilerException.LateVarDefinition();
}

if(_lastExtractedLexem.Token == Token.Export)
{
throw CompilerException.LocalExportVar();
}
}
else
{
Expand All @@ -341,29 +346,25 @@ private void BuildVariableDefinitions()
}

_module.VariableRefs.Add(definition);
variableInfo = new VariableInfo()
_module.Variables.Add(new VariableInfo()
{
Identifier = symbolicName,
Annotations = annotations,
CanGet = true,
CanSet = true,
Index = definition.CodeIndex,
IsExport = false
};
IsExport = _lastExtractedLexem.Token == Token.Export
});
}
NextToken();
if (_lastExtractedLexem.Token == Token.Export)
{
_module.ExportedProperties.Add(new ExportedSymbol()
{
SymbolicName = symbolicName,
Index = definition.CodeIndex
});
variableInfo.IsExport = true;
NextToken();
}
if(variableInfo.Identifier != null)
_module.Variables.Add(variableInfo);
if (_lastExtractedLexem.Token == Token.Comma)
{
NextToken();
Expand Down
6 changes: 6 additions & 0 deletions src/ScriptEngine/Compiler/CompilerExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ internal static CompilerException LateVarDefinition()
+ "en='Variable declarations must be placed at beginning of module, procedure, or function'"));
}

internal static CompilerException LocalExportVar()
{
return new CompilerException(Locale.NStr("ru='В теле процедуры или функции не может быть объявлена экспортная переменная';"
+ "en='An export variable cannot be declared in the body of a procedure or function'"));
}

internal static CompilerException TokenExpected(params Token[] expected)
{
var names = expected.Select(x => Enum.GetName(typeof(Token), x));
Expand Down

0 comments on commit 4c1aab6

Please sign in to comment.