public override Template Visit(GlobalBlock block)
        {
            Template template = new Template("<list; separator=\"\n\">");
            List<Template> list = new List<Template>();
            bool last = false;
            AstNode last_node = null;
            foreach (var node in block.List)
            {
                // Generic Class/Function Should Defined in Header File
                if (node is FuncDef && ((FuncDef)node).GenericParameter.Count() > 0) continue;
                if (node is Class && ((Class)node).GenericParameter.Count() > 0) continue;
                if (node is GlobalAlloc && node.Attribute.Exists(x => x.Name == "const") && !node.Attribute.Exists(x => x.Name == "static")) continue;
                if (node.Attribute.Exists(x => x.Name == "extern")) continue;

                if (node is Import || node is GlobalUsing || node is GlobalTypeDef || (node is Enum && node.Attribute.All(x => x.Name != "ToString"))) continue;
                bool current = node is FuncDef || node is Class || node is Enum || node is Import || node is GlobalUsing || node is Namespace;
                if ((last || current) && !(last_node is Import && node is Import))
                {
                    Template tp = new Template("\n<node>");
                    tp.Add("node", node.Accept(this));
                    list.Add(tp);
                }
                else
                {
                    list.Add(node.Accept(this));
                }
                last = current;
                last_node = node;
            }
            template.Add("list", list);
            return template;
        }
示例#2
0
 public override Template Visit(GlobalBlock block)
 {
     Template template = new Template("<list; separator=\"\n\">");
     List<Template> list = new List<Template>();
     bool last = false;
     AstNode last_node = null;
     foreach (var node in block.List)
     {
         bool current = node is FuncDef || node is Class || node is Enum || node is Import || node is GlobalUsing || node is Namespace;
         if ((last || current) && !(last_node is Import && node is Import))
         {
             Template tp = new Template("\n<node>");
             tp.Add("node", node.Accept(this));
             list.Add(tp);
         }
         else
         {
             list.Add(node.Accept(this));
         }
         last = current;
         last_node = node;
     }
     template.Add("list", list);
     return template;
 }
示例#3
0
        public override Template Visit(GlobalBlock block)
        {
            Template        template  = new Template("<list; separator=\"\n\">");
            List <Template> list      = new List <Template>();
            bool            last      = false;
            AstNode         last_node = null;

            foreach (var node in block.List)
            {
                if (node is FuncDef && node.Attribute.Exists(x => x.Name == "static"))
                {
                    continue;
                }
                if (node is GlobalAlloc && node.Attribute.Exists(x => x.Name == "static"))
                {
                    continue;
                }
                bool current = node is FuncDef || node is Class || node is Enum || node is Import || node is GlobalUsing || node is Namespace;
                if ((last || current) && !(last_node is Import && node is Import))
                {
                    Template tp = new Template("\n<node>");
                    tp.Add("node", node.Accept(this));
                    list.Add(tp);
                }
                else
                {
                    list.Add(node.Accept(this));
                }
                last      = current;
                last_node = node;
            }
            template.Add("list", list);
            return(template);
        }
        public override Template Visit(GlobalBlock block)
        {
            Template        template  = new Template("<list; separator=\"\n\">");
            List <Template> list      = new List <Template>();
            bool            last      = false;
            AstNode         last_node = null;

            foreach (var node in block.List)
            {
                // Generic Class/Function Should Defined in Header File
                if (node is FuncDef && ((FuncDef)node).GenericParameter.Count() > 0)
                {
                    continue;
                }
                if (node is Class && ((Class)node).GenericParameter.Count() > 0)
                {
                    continue;
                }
                if (node is GlobalAlloc && node.Attribute.Exists(x => x.Name == "const") && !node.Attribute.Exists(x => x.Name == "static"))
                {
                    continue;
                }
                if (node.Attribute.Exists(x => x.Name == "extern"))
                {
                    continue;
                }

                if (node is Import || node is GlobalUsing || node is GlobalTypeDef || (node is Enum && node.Attribute.All(x => x.Name != "ToString")))
                {
                    continue;
                }
                bool current = node is FuncDef || node is Class || node is Enum || node is Import || node is GlobalUsing || node is Namespace;
                if ((last || current) && !(last_node is Import && node is Import))
                {
                    Template tp = new Template("\n<node>");
                    tp.Add("node", node.Accept(this));
                    list.Add(tp);
                }
                else
                {
                    list.Add(node.Accept(this));
                }
                last      = current;
                last_node = node;
            }
            template.Add("list", list);
            return(template);
        }
示例#5
0
 public Template Declare(GlobalBlock block)
 {
     Template template = new Template("<list; separator=\"\n\">");
     List<Template> list = new List<Template>();
     foreach (var node in block.List)
     {
         if (node is Class)
         {
             Template tp = new Template("class <node>;");
             tp.Add("node", ((Class)node).Name);
             list.Add(tp);
         }
     }
     template.Add("list", list);
     return template;
 }
示例#6
0
        public Template Declare(GlobalBlock block)
        {
            Template        template = new Template("<list; separator=\"\n\">");
            List <Template> list     = new List <Template>();

            foreach (var node in block.List)
            {
                if (node is Class)
                {
                    Template tp = new Template("class <node>;");
                    tp.Add("node", ((Class)node).Name);
                    list.Add(tp);
                }
            }
            template.Add("list", list);
            return(template);
        }
示例#7
0
文件: Class.cs 项目: BYVoid/SugarCpp
 public Class(string name, List<string> gp, List<ExprAlloc> args, List<string> inherit ,GlobalBlock block, List<Attr> attr)
 {
     this.Name = name;
     if (gp != null)
     {
         this.GenericParameter = gp;
     }
     if (args != null)
     {
         this.Args = args;
     }
     if (inherit != null)
     {
         this.Inherit = inherit;
     }
     this.Block = block;
     if (attr != null)
     {
         this.Attribute = attr;
     }
 }
示例#8
0
 public Class(string name, List <SugarType> gp, List <ExprAlloc> args, List <string> inherit, GlobalBlock block, List <Attr> attr)
 {
     this.Name = name;
     if (gp != null)
     {
         this.GenericParameter = gp;
     }
     if (args != null)
     {
         this.Args = args;
     }
     if (inherit != null)
     {
         this.Inherit = inherit;
     }
     this.Block = block;
     if (attr != null)
     {
         this.Attribute = attr;
     }
 }
示例#9
0
	private GlobalBlock global_block()
	{
		EnterRule_global_block();
		EnterRule("global_block", 2);
		TraceIn("global_block", 2);
		GlobalBlock value = default(GlobalBlock);


		List<AttrAstNode> a = default(List<AttrAstNode>);


			value = new GlobalBlock();

		try { DebugEnterRule(GrammarFileName, "global_block");
		DebugLocation(39, 1);
		try
		{
			// SugarWalker.g:44:2: ( ^( Global_Block (a= node )* ) )
			DebugEnterAlt(1);
			// SugarWalker.g:44:4: ^( Global_Block (a= node )* )
			{
			DebugLocation(44, 4);
			DebugLocation(44, 6);
			Match(input,Global_Block,Follow._Global_Block_in_global_block105); 

			if (input.LA(1) == TokenTypes.Down)
			{
				Match(input, TokenTypes.Down, null); 
				DebugLocation(44, 19);
				// SugarWalker.g:44:19: (a= node )*
				try { DebugEnterSubRule(1);
				while (true)
				{
					int alt1=2;
					try { DebugEnterDecision(1, false);
					int LA1_0 = input.LA(1);

					if ((LA1_0==Class||LA1_0==Enum||(LA1_0>=Expr_Alloc_Bracket && LA1_0<=Expr_Alloc_Equal)||LA1_0==Func_Def||LA1_0==Import||LA1_0==Namespace||LA1_0==Stmt_Typedef||LA1_0==Stmt_Using||LA1_0==98))
					{
						alt1 = 1;
					}


					} finally { DebugExitDecision(1); }
					switch ( alt1 )
					{
					case 1:
						DebugEnterAlt(1);
						// SugarWalker.g:44:20: a= node
						{
						DebugLocation(44, 21);
						PushFollow(Follow._node_in_global_block110);
						a=node();
						PopFollow();

						DebugLocation(44, 27);
						 foreach (var x in a) value.List.Add(x); 

						}
						break;

					default:
						goto loop1;
					}
				}

				loop1:
					;

				} finally { DebugExitSubRule(1); }


				Match(input, TokenTypes.Up, null); 
			}


			}

		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("global_block", 2);
			LeaveRule("global_block", 2);
			LeaveRule_global_block();
		}
		DebugLocation(45, 1);
		} finally { DebugExitRule(GrammarFileName, "global_block"); }
		return value;

	}
示例#10
0
 public abstract Template Visit(GlobalBlock block);
示例#11
0
 public Root(GlobalBlock block)
 {
     this.Block = block;
 }
示例#12
0
 public abstract Template Visit(GlobalBlock block);
示例#13
0
 public Root(GlobalBlock block)
 {
     this.Block = block;
 }
示例#14
0
 public Namespace(string name, GlobalBlock block)
 {
     this.Name  = name;
     this.Block = block;
 }
示例#15
0
 public Namespace(string name, GlobalBlock block)
 {
     this.Name = name;
     this.Block = block;
 }