示例#1
0
        private FunctionDeclaration GetFunctionDeclaration(AstToken token)
        {
            var function = new FunctionDeclaration()
            {
                name = token.properties[0],
            };

            foreach (var childToken in token.children)
            {
                switch (childToken.Type)
                {
                case AstType.ParmVarDecl:
                    FunctionDeclaration.Parameter parameter = null;
                    if (childToken.properties.Length == 1)
                    {
                        parameter = new FunctionDeclaration.Parameter()
                        {
                            name = null,
                            type = childToken.properties[0],
                        };
                    }
                    else if (childToken.properties.Length == 2)
                    {
                        parameter = new FunctionDeclaration.Parameter()
                        {
                            name = childToken.properties[0],
                            type = childToken.properties[1],
                        };
                    }
                    if (token.Attributes.HasFlag(AstAttributes.CInit))
                    {
                        parameter.value = GetFunctionBody(childToken.children[0]);
                    }

                    function.parameters.Add(parameter);
                    break;

                case AstType.CompoundStmt:
                    function.body = GetFunctionBody(childToken);
                    break;

                case AstType.FullComment: break;     // ignore

                default: throw new Exception(childToken.unknownName);
                }
            }

            return(function);
        }
示例#2
0
        protected static FunctionDeclaration GetFunctionDeclaration(AstToken token)
        {
            var function = new FunctionDeclaration()
            {
                name = token.properties[0],
            };

            foreach (var childToken in token.children)
            {
                switch (childToken.name)
                {
                case "ParmVarDecl":
                    FunctionDeclaration.Parameter parameter = null;
                    if (childToken.properties.Length == 1)
                    {
                        parameter = new FunctionDeclaration.Parameter()
                        {
                            name = null,
                            type = childToken.properties[0],
                        };
                    }
                    else if (childToken.properties.Length == 2)
                    {
                        parameter = new FunctionDeclaration.Parameter()
                        {
                            name = childToken.properties[0],
                            type = childToken.properties[1],
                        };
                    }
                    if (childToken.attributes.Contains("cinit"))
                    {
                        parameter.value = GetFunctionBody(childToken.children[0]);
                    }

                    function.parameters.Add(parameter);
                    break;

                case "CompoundStmt":
                    function.body = GetFunctionBody(childToken);
                    break;

                case "FullComment": break;     // ignore

                default: throw new Exception(childToken.name);
                }
            }

            return(function);
        }