// this might be getting called too many times since im not sure im caching the result
        private void ParseContentTemplate(TemplateRootNode templateRootNode, TemplateShell shell, ProcessedType processedType)
        {
            XElement root = shell.GetElementTemplateContent(processedType.templateAttr.templateId);

            if (root == null)
            {
                throw new TemplateNotFoundException(processedType.templateAttr.filePath, processedType.templateAttr.templateId);
            }

            IXmlLineInfo xmlLineInfo = root;

            StructList <AttributeDefinition> attributes = StructList <AttributeDefinition> .Get();

            StructList <AttributeDefinition> injectedAttributes = StructList <AttributeDefinition> .Get();

            ParseAttributes(shell, "Contents", root.Attributes(), attributes, injectedAttributes, out string genericTypeResolver, out string requireType);

            if (attributes.size == 0)
            {
                StructList <AttributeDefinition> .Release(ref attributes);
            }

            if (injectedAttributes.size == 0)
            {
                StructList <AttributeDefinition> .Release(ref injectedAttributes);
            }

            templateRootNode.attributes          = ValidateRootAttributes(shell.filePath, attributes);
            templateRootNode.lineInfo            = new TemplateLineInfo(xmlLineInfo.LineNumber, xmlLineInfo.LinePosition);
            templateRootNode.genericTypeResolver = genericTypeResolver;
            templateRootNode.requireType         = requireType; // always null I think
            ParseChildren(templateRootNode, templateRootNode, root.Nodes());
        }
Exemple #2
0
        private ASTNode ParseInternal(string input)
        {
            tokenStream     = new TokenStream(ExpressionTokenizer.Tokenize(input, StructList <ExpressionToken> .Get()));
            expressionStack = expressionStack ?? StackPool <ASTNode> .Get();

            operatorStack = operatorStack ?? StackPool <OperatorNode> .Get();

            if (tokenStream.Current == ExpressionTokenType.ExpressionOpen)
            {
                tokenStream.Advance();
            }

            if (!tokenStream.HasMoreTokens)
            {
                throw new ParseException("Failed trying to parse empty expression");
            }

            if (tokenStream.Last == ExpressionTokenType.ExpressionClose)
            {
                tokenStream.Chop();
            }

            ASTNode retn = ParseLoop();

            Release();

            return(retn);
        }
Exemple #3
0
        public TypeBodyNode Parse(string input, string fileName, int lineStart)
        {
            tokenStream = new TokenStream(ExpressionTokenizer.Tokenize(input, StructList <ExpressionToken> .Get()));

            if (!tokenStream.HasMoreTokens)
            {
                throw new ParseException("Failed trying to parse empty expression");
            }

            TypeBodyNode retn = new TypeBodyNode();

            int cnt = 0;

            while (tokenStream.HasMoreTokens && cnt < 10000)
            {
                cnt++;
                ExpressionToken current = tokenStream.Current;

                ASTNode node = null;

                if (ParseDeclaration(ref node))
                {
                    retn.nodes.Add(node);
                    continue;
                }

                if (current == tokenStream.Current)
                {
                    throw new ParseException($"Failed to parse {fileName}. Got stuck on {current.value}");
                }
            }

            return(retn);
        }
Exemple #4
0
 public GridTrack(GridTrackSize size)
 {
     this.size                = size;
     this.position            = 0;
     this.outputSize          = 0;
     this.autoPlacementCursor = 0;
     this.spanningItems       = StructList <int> .Get();
 }
        public StyleAnimationKeyFrame(float key, StyleKeyFrameValue p0)
        {
            this.key        = key;
            this.properties = StructList <StyleKeyFrameValue> .Get();

            this.properties.EnsureCapacity(1);
            this.properties[0]    = p0;
            this.properties.Count = 1;
        }
Exemple #6
0
        private void AddToChangeSet(UIElement element, StyleProperty property)
        {
            if (!m_ChangeSets.TryGetValue(element.id, out ChangeSet changeSet))
            {
                changeSet = new ChangeSet(element, StructList <StyleProperty> .Get());
                m_ChangeSets[element.id] = changeSet;
            }

            changeSet.changes.Add(property);
        }
        public StyleAnimationKeyFrame(float key, StyleKeyFrameValue p0, StyleKeyFrameValue p1, StyleKeyFrameValue p2)
        {
            this.key        = key;
            this.properties = StructList <StyleKeyFrameValue> .Get();

            this.properties.EnsureCapacity(3);
            this.properties[0]    = p0;
            this.properties[1]    = p1;
            this.properties[2]    = p2;
            this.properties.Count = 3;
        }
        public StyleAnimationKeyFrame(float key, IList <StyleKeyFrameValue> properties)
        {
            this.key        = key;
            this.properties = StructList <StyleKeyFrameValue> .Get();

            this.properties.EnsureCapacity(properties.Count);
            for (int i = 0; i < properties.Count; i++)
            {
                this.properties[i] = properties[i];
            }

            this.properties.Count = properties.Count;
        }
Exemple #9
0
        public static bool TryParseTypeName(string typeName, out TypeLookup typeLookup)
        {
            StructList <ExpressionToken> list = StructList <ExpressionToken> .Get();

            ExpressionTokenizer.Tokenize(typeName, list);
            ExpressionParser parser = new ExpressionParser(new TokenStream(list));

            typeLookup = default;
            bool valid = parser.ParseTypePath(ref typeLookup);

            parser.Release();
            list.Release();
            return(valid);
        }
Exemple #10
0
        public static StructList <InputHandler> CompileInputAnnotations(Type targetType)
        {
            if (s_Cache.TryGetValue(targetType, out StructList <InputHandler> handlers))
            {
                return(handlers);
            }

            handlers = StructList <InputHandler> .Get();

            MethodInfo[] methods = ReflectionUtil.GetInstanceMethods(targetType);

            for (int i = 0; i < methods.Length; i++)
            {
                MethodInfo methodInfo = methods[i];

                object[] customAttributes = methodInfo.GetCustomAttributes(true);

                if (customAttributes.Length == 0)
                {
                    continue;
                }

                ParameterInfo[] parameters = methodInfo.GetParameters();

                GetMouseEventHandlers(methodInfo, parameters, customAttributes, handlers);

                GetKeyboardEventHandlers(methodInfo, parameters, customAttributes, handlers);

                GetDragCreators(methodInfo, parameters, customAttributes, handlers);

                GetDragHandlers(methodInfo, parameters, customAttributes, handlers);
            }

            if (handlers.size == 0)
            {
                handlers.Release();
                s_Cache[targetType] = null;
                return(null);
            }

            s_Cache[targetType] = handlers;

            return(handlers);
        }
Exemple #11
0
        public void AddSlotForward(TemplateScope parentScope, string slotName, UIElement context, int slotId)
        {
            slotInputs = slotInputs ?? StructList <SlotUsage> .Get();

            if (parentScope.slotInputs == null)
            {
                slotInputs.Add(new SlotUsage(slotName, slotId, context));
                return;
            }

            for (int i = 0; i < parentScope.slotInputs.size; i++)
            {
                if (parentScope.slotInputs.array[i].slotName == slotName)
                {
                    slotInputs.Add(parentScope.slotInputs.array[i]);
                }
            }

            slotInputs.Add(new SlotUsage(slotName, slotId, context));
        }
Exemple #12
0
        public LayoutFrameData GetResults(LayoutDirection direction, int frameId)
        {
            StructList <LayoutFrameDataEntry> historyEntries = StructList <LayoutFrameDataEntry> .Get();

            for (int i = 0; i < log.size; i++)
            {
                if (log.array[i].frameId != frameId)
                {
                    continue;
                }

                if (log.array[i].direction != direction)
                {
                    continue;
                }

                LayoutFrameDataEntry entry = new LayoutFrameDataEntry(log.array[i].reason, log.array[i].description);
                historyEntries.Add(entry);
            }

            return(new LayoutFrameData(historyEntries));
        }
Exemple #13
0
        internal static ConstructorInfo SelectEligibleConstructor(Type type, Expression[] arguments, StructList <ParameterConversion> winningConversions)
        {
            ConstructorInfo[] constructors = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public);

            if (constructors.Length == 0)
            {
                return(null);
            }

            if (constructors.Length == 1)
            {
                if (CheckCandidate(new Candidate(constructors[0].GetParametersCached()), arguments, out int unused, winningConversions))
                {
                    return(constructors[0]);
                }

                return(null);
            }

            StructList <Candidate> candidates = StructList <Candidate> .GetMinSize(constructors.Length);

            StructList <ParameterConversion> conversions = StructList <ParameterConversion> .Get();

            for (int i = 0; i < constructors.Length; i++)
            {
                candidates[i] = new Candidate(constructors[i].GetParametersCached());
            }

            int winner       = -1;
            int winnerPoints = 0;

            for (int i = 0; i < constructors.Length; i++)
            {
                int candidatePoints;
                conversions.QuickClear();

                if (!CheckCandidate(candidates[i], arguments, out candidatePoints, conversions))
                {
                    continue;
                }

                // todo -- handle the ambiguous case
                if (BestScoreSoFar(candidatePoints, winnerPoints))
                {
                    winner       = i;
                    winnerPoints = candidatePoints;
                    winningConversions.QuickClear();
                    winningConversions.AddRange(conversions);
                }
            }

            StructList <Candidate> .Release(ref candidates);

            StructList <ParameterConversion> .Release(ref conversions);

            if (winner != -1)
            {
                return(constructors[winner]);
            }

            return(null);
        }
Exemple #14
0
 public static StructList <WordInfo> BreakIntoWords(char[] buffer, int bufferSize = -1)
 {
     return(BreakIntoWords(StructList <WordInfo> .Get(), buffer, bufferSize));
 }
Exemple #15
0
        // depth buffer means our regions are locked per channel
        // 2 options: 1. each channel is its own set of draw calls, this is easy but maybe not as fast. do this as a first pass
        //            2. try to re-use regions for different channels, almost certainly leads to less throughput but faster since we don't need extra draw calls
        // probably means we have sub-sorting regions, ie large packers would have sub-packers
        // would definitely want to sort by size in that case and first try to pack larger regions into themselves
        // would likely update rect packer to be channel aware, when trying to place next item instead of moving over try colliding a different channel instead

        public void Clip(Camera camera, CommandBuffer commandBuffer)
        {
            // breaks on refresh if we don't do this :(
            this.clearMaterial.SetColor(s_Color, Color.white);
            this.clearCountMaterial.SetColor(s_Color, new Color(0, 0, 0, 0));
            requireRegionCounting = false;

            for (int i = 0; i < batchesToRender.size; i++)
            {
                batchesToRender[i].pooledMesh.Release();
                StructList <Matrix4x4> .Release(ref batchesToRender.array[i].transforms);

                StructList <Vector4> .Release(ref batchesToRender.array[i].objectData);

                StructList <Vector4> .Release(ref batchesToRender.array[i].colorData);
            }

            batchesToRender.Clear();
            Gather();

            Vector3 cameraOrigin = camera.transform.position;

            cameraOrigin.x -= 0.5f * Screen.width;
            cameraOrigin.y += (0.5f * Screen.height);
            cameraOrigin.z += 2;

            Matrix4x4 origin = Matrix4x4.TRS(cameraOrigin, Quaternion.identity, Vector3.one);

            LightList <ClipData> texturedClippers = LightList <ClipData> .Get();

            regionMesh?.Release();

            regionMesh = GetRegionMesh(out requireRegionCounting);

            clipTexture = RenderTexture.GetTemporary(Screen.width, Screen.height, 24, RenderTextureFormat.Default); // todo -- use lower resolution

#if DEBUG
            commandBuffer.BeginSample("UIFora Clip Draw");
#endif
            commandBuffer.SetRenderTarget(clipTexture);

            // probably don't need this actually, can bake it into clear. keep for debugging
            commandBuffer.ClearRenderTarget(true, true, Color.black);

            commandBuffer.DrawMesh(regionMesh.mesh, origin, clearMaterial, 0, 0);

            // todo -- handle multiple shapes from one path

            ClipBatch batch = new ClipBatch();
            batch.transforms = StructList <Matrix4x4> .Get();

            batch.colorData = StructList <Vector4> .Get();

            batch.objectData = StructList <Vector4> .Get();

            for (int i = 0; i < clippers.size; i++)
            {
                ClipData clipData = clippers[i];
                Path2D   clipPath = clipData.clipPath;

                if (clipPath == null)
                {
                    // todo if transform is not identity we need to generate a rotated or skewed rect for the clip shape
                    continue;
                }

                clipPath.UpdateGeometry(); // should early out if no update required

                if (AnyShapeUsesTextures(clipPath))
                {
                    // todo -- handle textures
                    // todo -- handle text
                    continue;
                }

                batch = DrawShapesInPath(batch, clipPath, clipData, clipData);

                for (int j = 0; j < clipData.dependents.size; j++)
                {
                    batch = DrawShapesInPath(batch, clipPath, clipData, clipData.dependents[j]);
                }
            }

            FinalizeBatch(batch, false);

            for (int i = 0; i < batchesToRender.size; i++)
            {
                ref ClipBatch clipBatch = ref batchesToRender.array[i];

                ClipPropertyBlock propertyBlock = clipMaterialPool.GetPropertyBlock(clipBatch.transforms.size);

                propertyBlock.SetData(clipBatch);

                commandBuffer.DrawMesh(clipBatch.pooledMesh.mesh, origin, clipDrawMaterial, 0, 0, propertyBlock.matBlock);
            }
Exemple #16
0
        private bool ParseDeclaration(ref ASTNode node)
        {
            AttributeNode             attrNode   = null;
            LightList <AttributeNode> attributes = LightList <AttributeNode> .Get();

            while (ParseAttribute(ref attrNode))
            {
                attributes.Add(attrNode);
                if (tokenStream.Current != ExpressionTokenType.ArrayAccessOpen)
                {
                    break;
                }
            }

            if (attributes.size == 0)
            {
                LightList <AttributeNode> .Release(ref attributes);
            }

            if (tokenStream.Current != ExpressionTokenType.Identifier)
            {
                return(false);
            }

            // modifiers? -> returnType -> name -> signature -> openBrace * closeBrace

            tokenStream.Save();

            bool isStatic = false;

            if (tokenStream.Current == "static")
            {
                isStatic = true;
                tokenStream.Advance();
            }

            ExpressionParser            parser    = new ExpressionParser(tokenStream);
            StructList <LambdaArgument> signature = null;
            TypeLookup typeLookup = default;

            if (!parser.ParseTypePath(ref typeLookup))
            {
                goto fail;
            }

            tokenStream.Set(parser.GetTokenPosition());
            parser.Release(false);

            if (tokenStream.Current != ExpressionTokenType.Identifier)
            {
                goto fail;
            }

            string name = tokenStream.Current.value;

            tokenStream.Advance();

            // if semi colon then we have a field!
            if (tokenStream.Current == ExpressionTokenType.SemiColon)
            {
                tokenStream.Advance();
                node = new FieldNode()
                {
                    name       = name,
                    isStatic   = isStatic,
                    attributes = attributes,
                    typeLookup = typeLookup
                };
                return(true);
            }

            if (tokenStream.Current != ExpressionTokenType.ParenOpen)
            {
                goto fail;
            }

            signature = StructList <LambdaArgument> .Get();

            if (tokenStream.NextTokenIs(ExpressionTokenType.ParenClose))
            {
                tokenStream.Advance(2);
            }
            else
            {
                int matchingIndex = tokenStream.FindMatchingIndex(ExpressionTokenType.ParenOpen, ExpressionTokenType.ParenClose);

                if (matchingIndex == -1)
                {
                    goto fail;
                }

                TokenStream subStream = tokenStream.AdvanceAndReturnSubStream(matchingIndex);
                subStream.Advance();
                tokenStream.Advance();
                if (!ExpressionParser.ParseSignature(subStream, signature))
                {
                    goto fail;
                }

                for (int i = 0; i < signature.size; i++)
                {
                    if (signature.array[i].type == null)
                    {
                        throw new ParseException($"When defining a method you must specify a type for all arguments. Found identifier {signature.array[i].identifier} but no type was given.");
                    }
                }
            }

            if (tokenStream.Current != ExpressionTokenType.ExpressionOpen)
            {
                goto fail;
            }

            BlockNode block = ParseBlock();

            node = new MethodNode()
            {
                body             = block,
                returnTypeLookup = typeLookup,
                attributes       = attributes,
                name             = name,
                isStatic         = isStatic,
                signatureList    = signature != null?signature.ToArray() : s_EmptySignature
            };

            StructList <LambdaArgument> .Release(ref signature);

            parser.Release(false);

            return(true);

fail:
            {
                tokenStream.Restore();
                parser.Release(false);
                typeLookup.Release();
                signature?.Release();
                return(false);
            }
        }
Exemple #17
0
        internal static MethodInfo SelectEligibleMethod(IList <MethodInfo> methodInfos, Expression[] arguments, StructList <ParameterConversion> winningConversions)
        {
            if (methodInfos.Count == 0)
            {
                return(null);
            }

            if (methodInfos.Count == 1)
            {
                if (CheckCandidate(new Candidate(methodInfos[0].GetParameters()), arguments, out int unused, winningConversions))
                {
                    return(methodInfos[0]);
                }

                return(null);
            }

            StructList <Candidate> candidates = StructList <Candidate> .GetMinSize(methodInfos.Count);

            StructList <ParameterConversion> conversions = StructList <ParameterConversion> .Get();

            int argCount = arguments.Length;

            for (int i = 0; i < methodInfos.Count; i++)
            {
                MethodInfo      methodInfo     = methodInfos[i];
                ParameterInfo[] parameterInfos = methodInfo.GetParametersCached();

                if (parameterInfos.Length == argCount)
                {
                    candidates.Add(new Candidate(methodInfo, parameterInfos));
                }
                else if (parameterInfos.Length > argCount)
                {
                    bool valid = true;
                    for (int j = 0; j < parameterInfos.Length; j++)
                    {
                        if (!parameterInfos[j].HasDefaultValue)
                        {
                            valid = false;
                            break;
                        }
                    }

                    if (valid)
                    {
                        candidates.Add(new Candidate(methodInfo, parameterInfos));
                    }
                }
            }

            int winner       = -1;
            int winnerPoints = -1;

            for (int i = 0; i < candidates.Count; i++)
            {
                int candidatePoints;
                conversions.QuickClear();

                if (!CheckCandidate(candidates[i], arguments, out candidatePoints, conversions))
                {
                    continue;
                }

                // todo -- handle the ambiguous case
                if (BestScoreSoFar(candidatePoints, winnerPoints))
                {
                    winner       = i;
                    winnerPoints = candidatePoints;

                    winningConversions.QuickClear();
                    winningConversions.AddRange(conversions);
                }
            }

            StructList <ParameterConversion> .Release(ref conversions);

            if (winner != -1)
            {
                MethodInfo retn = candidates[winner].methodInfo;
                StructList <Candidate> .Release(ref candidates);

                return(retn);
            }

            return(null);
        }
Exemple #18
0
        public BlockDefinition2()
        {
            this.variables = StructList <Parameter> .Get();

            this.statements = LightList <Expression> .Get();
        }
Exemple #19
0
        public void AddSlotOverride(string slotName, UIElement context, int slotId)
        {
            slotInputs = slotInputs ?? StructList <SlotUsage> .Get();

            slotInputs.Add(new SlotUsage(slotName, slotId, context));
        }