internal static IEnumerable <StatementSyntax> RemoveComponent(this IEntityManipulationTranslator entityManipulationTranslator, TranslationContext context, ExpressionSyntax entity, Type componentType) { return(entityManipulationTranslator.RemoveComponent(context, entity, componentType.ToTypeSyntax())); }
internal static IEnumerable <SyntaxNode> AddComponent(this IEntityManipulationTranslator entityManipulationTranslator, TranslationContext context, ExpressionSyntax entity, Type componentType, ExpressionSyntax componentDeclaration) { return(entityManipulationTranslator.AddComponent(context, entity, componentDeclaration, componentType.ToTypeSyntax(), typeof(ISharedComponentData).IsAssignableFrom(componentType))); }
static MemberAccessExpressionSyntax GetLeftValueFromCriterion(IEntityManipulationTranslator self, TranslationContext context, Stencil stencil, ExpressionSyntax entity, Criterion criterion) { var componentType = criterion.ObjectType.Resolve(stencil); var componentExpression = self.GetComponent(context, entity, componentType).Single(); var access = RoslynBuilder.MemberReference(componentExpression, criterion.Member.Path[0]); for (var i = 1; i < criterion.Member.Path.Count; i++) { access = RoslynBuilder.MemberReference(access, criterion.Member.Path[i]); } return(access); }
public override IEntityManipulationTranslator GetEntityManipulationTranslator() { return(m_EntityTranslator ?? (m_EntityTranslator = new JobEntityManipulationTranslator(false))); }
internal static void BuildCriteria(this IEntityManipulationTranslator self, RoslynEcsTranslator translator, TranslationContext context, ExpressionSyntax entity, IEnumerable <CriteriaModel> criteriaModels, StatementSyntax conditionBreak) { var criteriaList = criteriaModels.ToList(); if (!criteriaList.Any()) { return; } ExpressionSyntax ifExpressionSyntax = null; foreach (var model in criteriaList) { ExpressionSyntax finalExpression = null; foreach (var criterion in model.Criteria) { if (!(criterion is Criterion componentCriterion)) { continue; } var rightValue = componentCriterion.Value is ConstantNodeModel constantNodeModel ? translator.Constant(constantNodeModel.ObjectValue, translator.Stencil, constantNodeModel.Type) : IdentifierName(componentCriterion.Value.DeclarationModel.VariableName); var expression = BinaryExpression( componentCriterion.Operator.ToSyntaxKind(), GetLeftValueFromCriterion(self, context, translator.Stencil, entity, componentCriterion), rightValue) as ExpressionSyntax; // TODO : Temporary. Once Unity.Mathematics have IComparable interface, remove this // and use IComparable and IEquatable methods instead of operators var rightValueType = GetRightValueType(componentCriterion, translator.Stencil); if (rightValueType.Namespace != null && rightValueType.Namespace.StartsWith("Unity.Mathematics")) { expression = RoslynBuilder.MethodInvocation( nameof(math.all), typeof(math).ToTypeSyntax(), new[] { Argument(expression) }, Enumerable.Empty <TypeSyntax>()); } finalExpression = finalExpression == null ? expression : BinaryExpression(SyntaxKind.LogicalAndExpression, finalExpression, expression); } if (finalExpression == null) { continue; } context.AddStatement(RoslynBuilder.DeclareLocalVariable( typeof(bool), model.Name, finalExpression, RoslynBuilder.VariableDeclarationType.InferredType)); var unaryExpression = PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, IdentifierName(model.Name)); if (model != criteriaList.First()) { ifExpressionSyntax = BinaryExpression( SyntaxKind.LogicalAndExpression, ifExpressionSyntax, unaryExpression); } else { ifExpressionSyntax = unaryExpression; } } if (ifExpressionSyntax != null) { BlockSyntax statementSyntax; if ((translator.Options & CompilationOptions.Tracing) != 0 && context is JobContext jobContext) { statementSyntax = Block(List <SyntaxNode>() .Add(jobContext.MakeTracingEndForEachIndexStatement()) .Add(conditionBreak)); } else { statementSyntax = Block(SingletonList(conditionBreak)); } context.AddStatement(IfStatement(ifExpressionSyntax, statementSyntax)); } }