예제 #1
0
        // Build an interface method declaration.
        public static void BuildInterfaceMethod(IronyParser parser, Root root, Expression parentExpression, ParseTreeNode currentNode)
        {
            var method = new MethodDeclaration(parentExpression, currentNode.Token.Convert());

            parentExpression.ChildExpressions.Add(method);

            // Build the return type of the interface method.
            method.ReturnTypeName = parser.CheckAlias(currentNode.ChildNodes[0].ChildNodes[0].FindTokenAndGetText());

            // The name of the interface method.
            method.Name = currentNode.ChildNodes[0].ChildNodes[1].FindTokenAndGetText();

            // Build the list of generic type names.
            if (currentNode.ChildNodes[1].ChildNodes.Count > 0)
            {
                var generics = currentNode.ChildNodes[1].ChildNodes[0].ChildNodes[1];
                foreach (string s in IronyParser.InterpretList(generics))
                {
                    method.GenericTypeNames.Add(parser.CheckAlias(s));
                }
            }

            // Build the arguments of the method
            if (currentNode.ChildNodes[2].ChildNodes.Count > 0)
            {
                foreach (var n in currentNode.ChildNodes[2].ChildNodes)
                {
                    MethodDeclarationBuilder.BuildArgument(parser, method, n.ChildNodes[0]);
                }
            }
        }
예제 #2
0
        // Build an interface expression.
        public static void BuildInterface(IronyParser parser, Root root, Expression parentExpression, ParseTreeNode currentNode)
        {
            var inter = new Interface(parentExpression, currentNode.Token.Convert());

            parentExpression.ChildExpressions.Add(inter);

            int i = 0;

            // Find modifiers for the declaration
            InterpretModifiers(root, inter, currentNode.ChildNodes[i]);

            i++;

            i++;

            // get interface name
            inter.UnqualifiedName = currentNode.ChildNodes[i].FindTokenAndGetText();

            i++;

            // Build the generic type list
            if (currentNode.ChildNodes[i].ChildNodes.Count > 0)
            {
                var generics = currentNode.ChildNodes[i].ChildNodes[0].ChildNodes[1];
                foreach (string s in IronyParser.InterpretList(generics))
                {
                    inter.GenericTypeNames.Add(s);
                }
            }

            i++;

            // Build the base type list.
            if (currentNode.ChildNodes[i].ChildNodes.Count > 0)
            {
                var baseTypes = currentNode.ChildNodes[i].ChildNodes[0].ChildNodes[0];
                foreach (string s in IronyParser.InterpretList(baseTypes))
                {
                    inter.BaseTypeNames.Add(s);
                }
            }

            i += 1;

            // Build the children of the interface
            parser.ConsumeParseTree(root, inter, currentNode.ChildNodes[i]);
        }
예제 #3
0
        // Build a method declaration expression
        public static void BuildMethodDeclaration(IronyParser parser, Root root, Expression parentExpression, ParseTreeNode currentNode)
        {
            MethodDeclaration e = new MethodDeclaration(parentExpression, currentNode.FindToken().Convert());

            parentExpression.ChildExpressions.Add(e);

            int i = 0;

            // Set default modifiers
            var c = parentExpression as Class;

            if (c.IsModule) // If the parent is a module, set the method to shared.
            {
                e.IsShared = true;
            }

            // Interpret the modifiers for the method declaration
            InterpretModifiers(root, e, currentNode.ChildNodes[0].ChildNodes[0]);

            if (e.IsShared && (e.IsFinal || e.IsOverride))
            {
                root.CompilerErrors.Add(new IncompatibleModifiersCompilerError("", currentNode.FindToken().Location.Line,
                                                                               currentNode.FindToken().Location.Position));
            }

            i += 1; // skip the def

            // Interpret the return type name: check if it's an array, generic, or simple type name
            if (currentNode.ChildNodes[0].ChildNodes[1].ChildNodes[0].ChildNodes[0].Term.ToString() == "array")
            {
                e.Name           = currentNode.ChildNodes[0].ChildNodes[1].ChildNodes[1].FindTokenAndGetText();
                e.ReturnTypeName = parser.CheckAlias(currentNode.ChildNodes[0].ChildNodes[1].ChildNodes[0].ChildNodes[0].FindTokenAndGetText()) + "[]";
            }
            else if (currentNode.ChildNodes[0].ChildNodes[1].ChildNodes[0].ChildNodes[0].Term.ToString() == "generic_identifier")
            {
                var genericNode = currentNode.ChildNodes[0].ChildNodes[1].ChildNodes[0].ChildNodes[0];
                e.Name           = parser.CheckAlias(currentNode.ChildNodes[0].ChildNodes[1].ChildNodes[1].FindTokenAndGetText());
                e.ReturnTypeName = parser.CheckAlias(genericNode.ChildNodes[0].FindTokenAndGetText()) + "<";
                for (int n = 0; n < genericNode.ChildNodes[2].ChildNodes.Count; n++)
                {
                    e.ReturnTypeName += parser.CheckAlias(genericNode.ChildNodes[2].ChildNodes[n].FindTokenAndGetText());
                    if (n < genericNode.ChildNodes[2].ChildNodes.Count - 1)
                    {
                        e.ReturnTypeName += ",";
                    }
                }
                e.ReturnTypeName += ">";
            }
            else
            {
                e.Name           = currentNode.ChildNodes[0].ChildNodes[1].ChildNodes[1].FindTokenAndGetText();
                e.ReturnTypeName = parser.CheckAlias(currentNode.ChildNodes[0].ChildNodes[1].ChildNodes[0].FindTokenAndGetText());
            }

            i++;

            i++;

            // Add the generic type names for the method declaration
            if (currentNode.ChildNodes[1].ChildNodes.Count > 0)
            {
                var generics = currentNode.ChildNodes[1].ChildNodes[0].ChildNodes[1];
                foreach (string s in IronyParser.InterpretList(generics))
                {
                    e.GenericTypeNames.Add(s);
                }
            }

            i += 1;

            // add the arguments for the method declaration
            if (currentNode.ChildNodes[2].ChildNodes.Count > 0)
            {
                foreach (var n in currentNode.ChildNodes[2].ChildNodes)
                {
                    BuildArgument(parser, e, n.ChildNodes[0]);
                }
            }

            // Build the body of statements in the method declaration
            parser.ConsumeParseTree(root, e, currentNode.ChildNodes[3]);
        }
예제 #4
0
        // Builds a "class" expression: really could be a class, struct, or module.
        public static void BuildClass(IronyParser parser, Root root, Expression parentExpression, ParseTreeNode currentNode)
        {
            Class c = new Class(parentExpression, currentNode.FindToken().Convert());

            parentExpression.ChildExpressions.Add(c);

            int i = 0;

            // Interpret the declaration modifiers (abstract, public, internal, etc).
            InterpretClassModifiers(root, c, currentNode.ChildNodes[i]);

            i++;

            // Determine if it's a class, module, or struct.
            switch (currentNode.ChildNodes[i].Term.ToString())
            {
            case "module":
                c.IsModule  = true;
                c.IsFinal   = true;
                c.IsPartial = true;
                break;

            case "struct":
                c.IsStruct = true;
                c.IsModule = false;
                break;

            default:
                c.IsStruct = false;
                c.IsModule = false;
                break;
            }

            i++;

            // Class name
            c.UnqualifiedName = currentNode.ChildNodes[i].FindTokenAndGetText();

            i++;

            // Get the generic type list.
            if (currentNode.ChildNodes[i].ChildNodes.Count > 0)
            {
                var generics = currentNode.ChildNodes[i].ChildNodes[0].ChildNodes[1];
                foreach (string s in IronyParser.InterpretList(generics))
                {
                    c.GenericTypeNames.Add(s);
                }
            }

            i++;

            // Get the base type list.
            if (currentNode.ChildNodes[i].ChildNodes.Count > 0)
            {
                var baseTypes = currentNode.ChildNodes[i].ChildNodes[0].ChildNodes[0];
                foreach (string s in IronyParser.InterpretList(baseTypes))
                {
                    c.BaseTypeNames.Add(s);
                }
            }

            i += 1;

            // Build the child expressions of the class.
            parser.ConsumeParseTree(root, c, currentNode.ChildNodes[i]);
        }