예제 #1
0
            internal override bool Matches(MessageContentsNode c)
            {
                bool ok =
                    assertEquals("not an ArgNode",
                                 MessageContentsNode.NodeType.Arg, c.Type);

                if (!ok)
                {
                    return(ok);
                }
                ArgNode arg = (ArgNode)c;

                ok &= assertEquals("unexpected ArgNode argType",
                                   argType, arg.ArgType);
                ok &= assertEquals("unexpected ArgNode arg name",
                                   name, arg.Name);
                ok &= assertEquals("unexpected ArgNode arg number",
                                   number, arg.Number);
                ok &= assertEquals("unexpected ArgNode arg type name",
                                   type, arg.TypeName);
                ok &= assertEquals("unexpected ArgNode arg style",
                                   style, arg.SimpleStyle);
                if (argType == MessagePatternArgType.None || argType == MessagePatternArgType.Simple)
                {
                    ok &= assertNull("unexpected non-null complex style", arg.ComplexStyle);
                }
                return(ok);
            }
예제 #2
0
        private static PythonNode Wrap(Arg arg, PythonNode parent)
        {
            var result = new ArgNode(arg)
            {
                Parent = parent, Value = arg.Name
            };

            result.AddChild(Wrap(arg.Expression, result));
            return(result);
        }
예제 #3
0
        private static ArgNode BuildArgNode(MessagePattern pattern, int start, int limit)
        {
            ArgNode               node    = ArgNode.CreateArgNode();
            MessagePatternPart    part    = pattern.GetPart(start);
            MessagePatternArgType argType = node.ArgType = part.ArgType;

            part      = pattern.GetPart(++start); // ARG_NAME or ARG_NUMBER
            node.Name = pattern.GetSubstring(part);
            if (part.Type == MessagePatternPartType.ArgNumber)
            {
                node.Number = part.Value;
            }
            ++start;
            switch (argType)
            {
            case MessagePatternArgType.Simple:
                // ARG_TYPE
                node.TypeName = pattern.GetSubstring(pattern.GetPart(start++));
                if (start < limit)
                {
                    // ARG_STYLE
                    node.SimpleStyle = pattern.GetSubstring(pattern.GetPart(start));
                }
                break;

            case MessagePatternArgType.Choice:
                node.TypeName     = "choice";
                node.ComplexStyle = BuildChoiceStyleNode(pattern, start, limit);
                break;

            case MessagePatternArgType.Plural:
                node.TypeName     = "plural";
                node.ComplexStyle = BuildPluralStyleNode(pattern, start, limit, argType);
                break;

            case MessagePatternArgType.Select:
                node.TypeName     = "select";
                node.ComplexStyle = BuildSelectStyleNode(pattern, start, limit);
                break;

            case MessagePatternArgType.SelectOrdinal:
                node.TypeName     = "selectordinal";
                node.ComplexStyle = BuildPluralStyleNode(pattern, start, limit, argType);
                break;

            default:
                // NONE type, nothing else to do
                break;
            }
            return(node);
        }
예제 #4
0
            internal override bool Matches(MessageContentsNode c)
            {
                bool ok = base.Matches(c);

                if (!ok)
                {
                    return(ok);
                }
                ArgNode             arg          = (ArgNode)c;
                ComplexArgStyleNode complexStyle = arg.ComplexStyle;

                ok &= assertNotNull("unexpected null complex style", complexStyle);
                if (!ok)
                {
                    return(ok);
                }
                ok &= assertEquals("unexpected complex-style argType",
                                   argType, complexStyle.ArgType);
                ok &= assertEquals("unexpected complex-style hasExplicitOffset()",
                                   explicitOffset, complexStyle.HasExplicitOffset);
                ok &= assertEquals("unexpected complex-style offset",
                                   offset, complexStyle.Offset);
                IList <VariantNode> complexVariants = complexStyle.Variants;

                ok &= assertEquals("different number of variants",
                                   variants.Count, complexVariants.Count);
                if (!ok)
                {
                    return(ok);
                }
                //Iterator<VariantNode> complexIter = complexVariants.iterator();
                using (var complexIter = complexVariants.GetEnumerator())
                    foreach (ExpectVariantNode variant in variants)
                    {
                        complexIter.MoveNext();
                        ok &= variant.Matches(complexIter.Current);
                    }
                return(ok);
            }
예제 #5
0
        public virtual string GetFunctionShaderCode()
        {
            if (OutputNode == null)
            {
                return("");
            }

            string otherCalls = "";
            string frag       = "";

            List <Node> ordered = OrderNodesForShader();

            //this is in case this function references
            //other functions
            int count = calls.Count;

            for (int i = 0; i < count; i++)
            {
                CallNode m = calls[i];

                //no need to recreate the function
                //if it is a recursive function!
                if (m.selectedFunction == this)
                {
                    continue;
                }

                string s = m.GetFunctionShaderCode();

                if (string.IsNullOrEmpty(s))
                {
                    return("");
                }

                if (otherCalls.IndexOf(s) == -1)
                {
                    otherCalls += s;
                }
            }

            NodeType?outtype = GetOutputType();

            if (outtype == null)
            {
                return("");
            }

            if (outtype.Value == NodeType.Float4 ||
                outtype.Value == NodeType.Color ||
                outtype.Value == NodeType.Gray)
            {
                frag += "vec4 ";
            }
            else if (outtype.Value == NodeType.Float3)
            {
                frag += "vec3 ";
            }
            else if (outtype.Value == NodeType.Float2)
            {
                frag += "vec2 ";
            }
            else if (outtype.Value == NodeType.Float)
            {
                frag += "float ";
            }
            else if (outtype.Value == NodeType.Bool)
            {
                frag += "bool ";
            }
            else if (outtype.Value == NodeType.Matrix)
            {
                frag += "mat4 ";
            }
            else
            {
                return("");
            }

            frag += Name.Replace(" ", "").Replace("-", "_") + "(";

            count = args.Count;
            for (int i = 0; i < count; i++)
            {
                ArgNode a = args[i];

                if (a.InputType == NodeType.Float)
                {
                    frag += "float " + a.InputName + ",";
                }
                else if (a.InputType == NodeType.Float2)
                {
                    frag += "vec2 " + a.InputName + ",";
                }
                else if (a.InputType == NodeType.Float3)
                {
                    frag += "vec3 " + a.InputName + ",";
                }
                else if (a.InputType == NodeType.Float4 || a.InputType == NodeType.Color || a.InputType == NodeType.Gray)
                {
                    frag += "vec4 " + a.InputName + ",";
                }
                else if (a.InputType == NodeType.Bool)
                {
                    frag += "bool " + a.InputName + ",";
                }
                else if (a.InputType == NodeType.Matrix)
                {
                    frag += "mat4 " + a.InputName + ",";
                }
            }

            if (args.Count > 0)
            {
                frag = frag.Substring(0, frag.Length - 1) + ") {\r\n";
            }
            else
            {
                frag += ") {\r\n";
            }

            string intern = GetInternalShaderCode(ordered, frag, true);

            if (string.IsNullOrEmpty(intern))
            {
                return("");
            }

            frag = intern + "}\r\n\r\n";

            return(otherCalls + frag);
        }
예제 #6
0
 private void Write(ArgNode arg)
 {
     Write(arg.Children[0]);
 }