コード例 #1
0
        private Statement ProcessUsingStatement(UsingNode node)
        {
            UsingStatement statement = new UsingStatement();

            statement.AddGuard((VariableDeclarationStatement)ProcessVariableDeclarationStatement((VariableDeclarationNode)node.Guard));
            statement.AddBody(BuildStatement((StatementNode)node.Body));
            return(statement);
        }
コード例 #2
0
 protected override void VisitUsingNode(UsingNode node)
 {
     AppendIndentation();
     Append("using ");
     Append(node.NamespaceName);
     Append(";");
     AppendLineEnding();
     base.VisitUsingNode(node);
 }
コード例 #3
0
 public override void Visit(UsingNode node)
 {
     if (node.IsStatic)
     {
         helpers.Add(node.Name);
     }
     else
     {
         usings.Add(node.Name);
     }
 }
コード例 #4
0
 private void AnalyzeUsing(UsingNode usingNode)
 {
     for (NameSpaceDefinition nameSpace = Parser.RootNameSpace;
          usingNode.NextUsing != null;
          usingNode = usingNode.NextUsing)
     {
         if (!nameSpace.IsContainNameSpace(usingNode.Name))
         {
             return;                                                //TODO:报错 未找到命名空间名
         }
         usingNode.NameSpace = nameSpace.GetNameSpaceDefinition(usingNode.Name);
     }
 }
コード例 #5
0
        protected override void VisitUsingNode(UsingNode node)
        {
            if (node == null)
            {
                return;
            }

            AppendIndentation();
            Append("using ");
            Append(node.Namespace);
            AppendEndOfStatement();

            if (this.settings.BlankLine.Using)
            {
                AppendLine();
            }

            base.VisitUsingNode(node);
        }
コード例 #6
0
        private void PrepareUsings(UsingCache cache, UsingNode node)
        {
            if (node == null)
            {
                return;
            }

            if (cache.IsUsingNamespace(node))
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(node.Namespace))
            {
                return;
            }

            cache.Map[node.Namespace] = node;
        }
コード例 #7
0
ファイル: Parser.cs プロジェクト: fangxm233/Butterfly
        private void ParseUsing()
        {
            List <UsingNode> references = FilesReferences[_lexer.FileIndex];
            Token            s          = _lexer.Eat(TokenType.Identifer); //TODO:使用Match函数报错

            if (_lexer.MatchNow("="))
            {
                FilesAliases[_lexer.FileIndex].Add(s.Content, ParseDefinitionSpecifier());
                return;
            }
            references.Add(_syntaxFactory.GetUsingNode(s, null));
            UsingNode last = references.Last();

            while (_lexer.Match("."))
            {
                _lexer.MatchNext(TokenType.Identifer); //TODO:使用Match函数报错
                last.AddAfter(_lexer.Eat(TokenType.Identifer), _syntaxFactory);
                last = last.NextUsing;
            }
            _lexer.MatchNow(";"); //TODO:使用Match函数报错
        }
コード例 #8
0
ファイル: UsingNode.cs プロジェクト: menozz/lens
 protected bool Equals(UsingNode other)
 {
     return string.Equals(VariableName, other.VariableName) && Equals(Expression, other.Expression) && Equals(Body, other.Body);
 }
コード例 #9
0
 internal UsingNode GetUsingNode(Token content, UsingNode previousUsing)
 {
     return(new UsingNode(content, previousUsing));
 }
コード例 #10
0
        private static string[] GenerateCode()
        {
            Type painterInterface =
                PainterType == PAINTER_TYPE_GEOMETRY_TEXTURE ? typeof(IGTexturePainter) :
                PainterType == PAINTER_TYPE_FOLIAGE ? typeof(IGFoliagePainter) :
                PainterType == PAINTER_TYPE_OBJECT ? typeof(IGObjectPainter) :
                null;
            //Declare it
            TypeDeclaration d = new TypeDeclaration.Builder()
                                .SetAccessModifier(AccessModifier.PUBLIC)
                                .SetIsStatic(false)
                                .SetInheritance(Inheritance.DEFAULT)
                                .SetScope(Scope.CLASS)
                                .SetName(PainterName.RemoveSpecialCharacters())
                                .SetInterfaces(painterInterface)
                                .Build();

            //Import regularly used namespaces, just call a Using(...) if you need more
            UsingNode un = new UsingNode()
                           .Using("UnityEngine")
                           .Using("System.Collections")
                           .Using("System.Collections.Generic")
                           .Using("Pinwheel.Griffin")
                           .Using("Pinwheel.Griffin.PaintTool");

            //Import the base class namespace to simplify its name in the declaration string
            if (d.baseClass != null)
            {
                un.Using(d.baseClass.Namespace);
            }

            //The same for interfaces
            if (d.implementedInterface.HasElement())
            {
                for (int i = 0; i < d.implementedInterface.Count; ++i)
                {
                    un.Using(d.implementedInterface[i].Namespace);
                }
            }

            //Give it a hint to determine type names
            TypeAlias.SetUsingNode(un);

            List <string> code = new List <string>();

            //Implement the type
            TypeNode tn = new TypeNode()
                          .Declare(d)
                          .Implement(code);

            //Put the new type into the namespace
            //NamespaceNode nn = new NamespaceNode()
            //    .SetName("CustomPainter")
            //    .SetTypes(tn);

            //Put everything into a script
            ScriptNode sn = new ScriptNode()
                            .SetCompilationDirective("GRIFFIN")
                            .SetUsing(un)
                                           //.SetNamespace(nn)
                            .SetTypes(tn); //also set type in case namespace is empty

            //Now make the code look awesome
            CodeFormatter formatter = new CodeFormatter();

            formatter.addSpaceAfterUsings    = true;
            formatter.addSpaceBetweenMethods = true;
            formatter.bracketStyle           = CodeFormatter.OpenCurlyBracketStyle.NewLine;

            string[] script = formatter.Format(sn);

            return(script); //phew...
        }
コード例 #11
0
 public ScriptNode SetUsing(UsingNode u)
 {
     usingNode = u;
     return(this);
 }
コード例 #12
0
        private static string[] GenerateCode()
        {
            //Declare it
            TypeDeclaration d = new TypeDeclaration.Builder()
                                .SetAccessModifier(AccessModifier.PUBLIC)
                                .SetIsStatic(true)
                                .SetInheritance(Inheritance.DEFAULT)
                                .SetScope(Scope.CLASS)
                                .SetName(ExtensionName.RemoveSpecialCharacters())
                                .Build();

            //Import regularly used namespaces, just call a Using(...) if you need more
            UsingNode un = new UsingNode()
                           .Using("UnityEngine")
                           .Using("System.Collections")
                           .Using("System.Collections.Generic")
                           .Using("UnityEditor");

            //Import the base class namespace to simplify its name in the declaration string
            if (d.baseClass != null)
            {
                un.Using(d.baseClass.Namespace);
            }

            //The same for interfaces
            if (d.implementedInterface.HasElement())
            {
                for (int i = 0; i < d.implementedInterface.Count; ++i)
                {
                    un.Using(d.implementedInterface[i].Namespace);
                }
            }

            //Give it a hint to determine type names
            TypeAlias.SetUsingNode(un);

            List <string> code = new List <string>();

            //add basic function for an extension
            code.Add(GetExtensionNameCode());
            code.Add(GetPublisherNameCode());
            code.Add(GetDescriptionCode());
            code.Add(GetVersionCode());
            code.Add(GetOpenUserGuideCode());
            code.Add(GetOpenSupportLinkCode());
            code.Add(GetButtonMethodCode());
            code.Add(GetOnGUICode());

            //Implement the type
            TypeNode tn = new TypeNode()
                          .Declare(d)
                          .Implement(code);

            //Put the new type into the namespace
            NamespaceNode nn = new NamespaceNode()
                               .SetName(string.Format("{0}.GriffinExtension", PublisherName.RemoveSpecialCharacters()))
                               .SetTypes(tn);

            //Put everything into a script
            ScriptNode sn = new ScriptNode()
                            .SetCompilationDirective("GRIFFIN && UNITY_EDITOR")
                            .SetUsing(un)
                            .SetNamespace(nn)
                            .SetTypes(tn); //also set type in case namespace is empty

            //Now make the code look awesome
            CodeFormatter formatter = new CodeFormatter();

            formatter.addSpaceAfterUsings    = true;
            formatter.addSpaceBetweenMethods = true;
            formatter.bracketStyle           = CodeFormatter.OpenCurlyBracketStyle.NewLine;

            string[] script = formatter.Format(sn);

            return(script); //phew...
        }
コード例 #13
0
ファイル: LensParser.cs プロジェクト: menozz/lens
        /// <summary>
        /// using_header                                = "using" [ identifier "=" ] line_expr "do"
        /// </summary>
        private UsingNode parseUsingHeader()
        {
            if (!check(LexemType.Using))
                return null;

            var node = new UsingNode();
            if (peek(LexemType.Identifier, LexemType.Assign))
            {
                node.VariableName = getValue();
                skip();
            }

            node.Expression = ensure(parseLineExpr, ParserMessages.ExpressionExpected);
            ensure(LexemType.Do, ParserMessages.SymbolExpected, "do");

            return node;
        }
コード例 #14
0
ファイル: AstVisitor.cs プロジェクト: Vengarioth/UnityCodeGen
 protected virtual void VisitUsingNode(UsingNode node)
 {
 }
コード例 #15
0
 /// <summary>
 /// Give a hint to determine if the namespace should be included in type name or not
 /// </summary>
 /// <param name="un"></param>
 public static void SetUsingNode(UsingNode un)
 {
     usingNode = un;
 }
コード例 #16
0
 public string Visit(UsingNode node)
 => ASTHelper.PrintToken(node.Token) + ASTHelper.PrintValue(node.Name);
コード例 #17
0
 public virtual void Visit(UsingNode node)
 {
 }