Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/OneScript.Core/Contexts/ClassBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ private static bool MarkedAsContextMethod(MemberInfo member, bool includeDepreca
.Any(x => includeDeprecations || (x as ContextMethodAttribute)?.IsDeprecated == false);
}

private static bool MarkedAsContextProperty(MemberInfo member, bool includeDeprecations = false)
private static bool MarkedAsContextProperty(PropertyInfo member, bool includeDeprecations = false)
{
return member.GetCustomAttributes(typeof(ContextPropertyAttribute), false).Any();
return member.GetCustomAttributes(typeof(ContextPropertyAttribute), false)
.Any(x => includeDeprecations || (x as ContextPropertyAttribute)?.IsDeprecated == false);
}

public ClassBuilder ExportConstructor(MethodInfo info)
Expand Down
2 changes: 1 addition & 1 deletion src/OneScript.Language/SyntaxAnalysis/BslSyntaxWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ protected virtual void VisitTernaryOperation(BslSyntaxNode node)

protected virtual void VisitModuleBody(BslSyntaxNode codeBlock)
{
if(codeBlock.Children.Count > 0)
if(codeBlock.Children.Count != 0)
VisitCodeBlock(codeBlock.Children[0]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private void MarkAsSolved()

private void PopBlock()
{
if (_blocks.Count > 0)
if (_blocks.Count != 0)
_blocks.Pop();
else
AddError(LocalizedErrors.DirectiveIsMissing("Если"));
Expand Down
4 changes: 2 additions & 2 deletions src/OneScript.Language/SyntaxAnalysis/DefaultBslParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void ParseModuleAnnotation()
.Cast<ModuleAnnotationDirectiveHandler>()
.ToList();

if (!annotationParser.Any())
if (annotationParser.Count == 0)
return;

while (_lastExtractedLexem.Type == LexemType.PreprocessorDirective)
Expand Down Expand Up @@ -1650,7 +1650,7 @@ private void AddError(CodeError err, bool doFastForward = true)

if (doFastForward)
{
if (_tokenStack.Count > 0)
if (_tokenStack.Count != 0)
SkipToNextStatement(_tokenStack.Peek());
else
SkipToNextStatement();
Expand Down
10 changes: 5 additions & 5 deletions src/OneScript.Native/Compiler/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ protected override void VisitIfNode(ConditionNode node)
{
stack.Push(elif);
}
else if (stack.Count > 0)
else if (stack.Count != 0)
{
var cond = stack.Pop();

Expand All @@ -726,7 +726,7 @@ protected override void VisitIfNode(ConditionNode node)
}
}

while (stack.Count > 0)
while (stack.Count != 0)
{
var elseIfNode = stack.Pop();
VisitElseIfNode(elseIfNode);
Expand Down Expand Up @@ -1147,7 +1147,7 @@ protected override void VisitObjectProcedureCall(BslSyntaxNode node)
private IEnumerable<Expression> PrepareDynamicCallArguments(BslSyntaxNode argList)
{
return argList.Children.Select(passedArg =>
passedArg.Children.Count > 0
passedArg.Children.Count != 0
? ConvertToExpressionTree(passedArg.Children[0])
: Expression.Constant(BslSkippedParameterValue.Instance));
}
Expand Down Expand Up @@ -1414,7 +1414,7 @@ private List<Expression> PrepareCallArguments(BslSyntaxNode argList, ParameterIn
}

var parameters = argList.Children.Select(passedArg =>
passedArg.Children.Count > 0
passedArg.Children.Count != 0
? ConvertToExpressionTree(passedArg.Children[0])
: null).ToArray();

Expand Down Expand Up @@ -1523,7 +1523,7 @@ protected override void VisitNewObjectCreation(NewObjectNode node)
if (node.ConstructorArguments != default)
{
parameters = node.ConstructorArguments.Children.Select(passedArg =>
passedArg.Children.Count > 0 ?
passedArg.Children.Count != 0 ?
ConvertToExpressionTree(passedArg.Children[0]) :
Expression.Default(typeof(BslValue))).ToArray();
}
Expand Down
2 changes: 1 addition & 1 deletion src/OneScript.Native/Compiler/StatementBlocksWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class StatementBlocksWriter

public void EnterBlock(JumpInformationRecord newJumpStates)
{
var current = _blocks.Count > 0 ? GetCurrentBlock() : null;
var current = _blocks.Count != 0 ? GetCurrentBlock() : null;
if (current != null)
{
newJumpStates.MethodReturn ??= current.MethodReturn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public CollectionIndex(IIndexCollectionSource source, IEnumerable<IValue> fields

internal bool CanBeUsedFor(IEnumerable<IValue> searchFields)
{
return _fields.Count > 0 && _fields.All(f => searchFields.Contains(f));
return _fields.Count != 0 && _fields.All(f => searchFields.Contains(f));
}

private CollectionIndexKey IndexKey(PropertyNameIndexAccessor source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public int Read ()
_buffer.Dequeue ();
UpdateCharQueue ();

if (_buffer.Count > 0 && _buffer.Peek () == '\n') {
if (_buffer.Count != 0 && _buffer.Peek () == '\n') {
_buffer.Dequeue ();
UpdateCharQueue ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void WaitCompletionOfTasks()
var failedTasks = _tasks.Where(x => x.State == TaskStateEnum.CompletedWithErrors)
.ToList();

if (failedTasks.Any())
if (failedTasks.Count != 0)
{
throw new ParametrizedRuntimeException(
Locale.NStr("ru = 'Задания завершились с ошибками';en = 'Tasks are completed with errors'"),
Expand Down
7 changes: 7 additions & 0 deletions src/ScriptEngine/Compiler/ModuleDumpWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ private void WriteImage(TextWriter output, StackRuntimeModule module)
output.WriteLine(
$"{i,-3}:type: {item.SystemType.Alias}, val: {item}");
}
output.WriteLine(".identifiers");
for (int i = 0; i < module.Identifiers.Count; i++)
{
var item = module.Identifiers[i];
output.WriteLine(
$"{i,-3}: {item}");
}
output.WriteLine(".code");
for (int i = 0; i < module.Code.Count; i++)
{
Expand Down
78 changes: 40 additions & 38 deletions src/ScriptEngine/Compiler/StackMachineCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ This Source Code Form is subject to the terms of the
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using OneScript.Compilation;
using OneScript.Compilation.Binding;
using OneScript.Contexts;
Expand Down Expand Up @@ -126,7 +125,7 @@ private void HandleImportClause(AnnotationNode node)

private void CheckForwardedDeclarations()
{
if (_forwardedMethods.Count > 0)
if (_forwardedMethods.Count != 0)
{
foreach (var item in _forwardedMethods)
{
Expand Down Expand Up @@ -477,7 +476,7 @@ protected override void VisitContinueNode(LineMarkerNode node)

protected override void VisitReturnNode(BslSyntaxNode node)
{
if (node.Children.Count > 0)
if (node.Children.Count != 0)
{
VisitExpression(node.Children[0]);
AddCommand(OperationCode.MakeRawValue);
Expand All @@ -489,7 +488,7 @@ protected override void VisitReturnNode(BslSyntaxNode node)
protected override void VisitRaiseNode(BslSyntaxNode node)
{
int arg = -1;
if (node.Children.Any())
if (node.Children.Count != 0)
{
VisitExpression(node.Children[0]);
arg = 0;
Expand Down Expand Up @@ -728,24 +727,17 @@ private void ResolveObjectMethod(BslSyntaxNode callNode, bool asFunction)

PushCallArguments(args);

var cDef = new ConstDefinition();
cDef.Type = DataType.String;
cDef.Presentation = name.GetIdentifier();
int lastIdentifierConst = GetConstNumber(cDef);
int lastIdentifierIndex = GetIdentNumber(name.GetIdentifier());

if (asFunction)
AddCommand(OperationCode.ResolveMethodFunc, lastIdentifierConst);
AddCommand(OperationCode.ResolveMethodFunc, lastIdentifierIndex);
else
AddCommand(OperationCode.ResolveMethodProc, lastIdentifierConst);
AddCommand(OperationCode.ResolveMethodProc, lastIdentifierIndex);
}

private void ResolveProperty(string identifier)
{
var cDef = new ConstDefinition();
cDef.Type = DataType.String;
cDef.Presentation = identifier;
var identifierConstIndex = GetConstNumber(cDef);
AddCommand(OperationCode.ResolveProp, identifierConstIndex);
AddCommand(OperationCode.ResolveProp, GetIdentNumber(identifier));
}

private int PushVariable(TerminalNode node)
Expand Down Expand Up @@ -863,11 +855,13 @@ private void GlobalCall(CallNode call, bool asFunction)
else
{
// can be defined later
var forwarded = new ForwardedMethodDecl();
forwarded.identifier = identifier;
forwarded.asFunction = asFunction;
forwarded.location = identifierNode.Location;
forwarded.factArguments = argList;
var forwarded = new ForwardedMethodDecl
{
identifier = identifier,
asFunction = asFunction,
location = identifierNode.Location,
factArguments = argList
};

PushCallArguments(call.ArgumentList);

Expand All @@ -885,17 +879,17 @@ private void PushCallArguments(BslSyntaxNode argList)

private void PushArgumentsList(BslSyntaxNode argList)
{
for (int i = 0; i < argList.Children.Count; i++)
var arguments = argList.Children;
for (int i = 0; i < arguments.Count; i++)
{
var passedArg = argList.Children[i];
VisitCallArgument(passedArg);
VisitCallArgument(arguments[i]);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void VisitCallArgument(BslSyntaxNode passedArg)
{
if (passedArg.Children.Count > 0)
if (passedArg.Children.Count != 0)
{
VisitExpression(passedArg.Children[0]);
}
Expand Down Expand Up @@ -1056,7 +1050,7 @@ private void MakeNewObjectDynamic(NewObjectNode node)
var argsPassed = node.ConstructorArguments.Children.Count;
if (argsPassed == 1)
{
PushArgumentsList(node.ConstructorArguments);
VisitCallArgument(node.ConstructorArguments.Children[0]); ;
}
else if (argsPassed > 1)
{
Expand All @@ -1068,21 +1062,17 @@ private void MakeNewObjectDynamic(NewObjectNode node)

private void MakeNewObjectStatic(NewObjectNode node)
{
var cDef = new ConstDefinition()
{
Type = DataType.String,
Presentation = node.TypeNameNode.GetIdentifier()
};
AddCommand(OperationCode.PushConst, GetConstNumber(cDef));

var callArgs = 0;
if (node.ConstructorArguments != default)
{
PushArgumentsList(node.ConstructorArguments);
callArgs = node.ConstructorArguments.Children.Count;
PushCallArguments(node.ConstructorArguments);
}
else
{
AddCommand(OperationCode.ArgNum, 0);
}

AddCommand(OperationCode.NewInstance, callArgs);
var idNum = GetIdentNumber(node.TypeNameNode.GetIdentifier());
AddCommand(OperationCode.NewInstance, idNum);
}

private void ExitTryBlocks()
Expand All @@ -1094,15 +1084,15 @@ private void ExitTryBlocks()

private void PushTryNesting()
{
if (_nestedLoops.Count > 0)
if (_nestedLoops.Count != 0)
{
_nestedLoops.Peek().tryNesting++;
}
}

private void PopTryNesting()
{
if (_nestedLoops.Count > 0)
if (_nestedLoops.Count != 0)
{
_nestedLoops.Peek().tryNesting--;
}
Expand Down Expand Up @@ -1328,6 +1318,18 @@ private int GetConstNumber(in ConstDefinition cDef)
return idx;
}

private int GetIdentNumber(string ident)
{
var idx = _module.Identifiers.IndexOf(ident);
if (idx < 0)
{
idx = _module.Identifiers.Count;
_module.Identifiers.Add(ident);
}
return idx;
}


private int GetMethodRefNumber(in SymbolBinding methodBinding)
{
var descriptor = _ctx.GetBinding(methodBinding.ScopeNumber);
Expand Down
Loading