Пример #1
0
 public StmtSwitchItem(List <Expr> list, StmtBlock block)
 {
     if (list != null)
     {
         this.ExprList = list;
     }
     this.Block = block;
 }
Пример #2
0
 public StmtFor(List <ForItem> list, StmtBlock body)
 {
     if (list != null)
     {
         this.List = list;
     }
     this.Body = body;
 }
Пример #3
0
 public StmtSwitch(Expr expr, List <StmtSwitchItem> list, StmtBlock default_block)
 {
     this.Expr = expr;
     if (list != null)
     {
         this.List = list;
     }
     this.DefalutBlock = default_block;
 }
Пример #4
0
 public ExprCurryLambda(StmtBlock block, List <ExprAlloc> args, bool isRef, SugarType type)
 {
     this.Block = block;
     if (args != null)
     {
         this.Args = args;
     }
     this.IsRef = isRef;
     this.Type  = type;
 }
Пример #5
0
        public override Template Visit(Enum enum_def)
        {
            if (enum_def.Attribute.Find(x => x.Name == "ToString") != null)
            {
                Attr attr = enum_def.Attribute.Find(x => x.Name == "ToString");

                FuncDef func = new FuncDef();
                func.Type = new IdentType("const char*");
                func.Name = attr.Args.Count() == 0 ? "ToString" : attr.Args.First();
                func.Args.Add(new ExprAlloc(new IdentType("const " + enum_def.Name + "&"), "_t_value", null, AllocType.Declare));
                List <StmtSwitchItem> switch_list = new List <StmtSwitchItem>();
                foreach (var item in enum_def.Values)
                {
                    StmtBlock block = new StmtBlock();
                    block.StmtList.Add(new StmtReturn(new ExprConst("\"" + item + "\"", ConstType.String)));
                    switch_list.Add(new StmtSwitchItem(new List <Expr> {
                        new ExprConst(enum_def.Name + "::" + item, ConstType.Ident)
                    }, block));
                }

                StmtBlock default_block = new StmtBlock();
                {
                    default_block.StmtList.Add(new StmtExpr(new ExprCall(new ExprConst("throw", ConstType.Ident), null, new List <Expr> {
                        new ExprConst("\"Not Found\"", ConstType.String)
                    })));
                }

                StmtSwitch stmt_switch = new StmtSwitch(new ExprConst("_t_value", ConstType.Ident), switch_list, default_block);
                StmtBlock  body        = new StmtBlock();
                body.StmtList.Add(stmt_switch);
                func.Body = body;
                return(func.Accept(this));
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Пример #6
0
 public StmtSwitchItem(Expr expr, StmtBlock block)
 {
     this.Expr = expr;
     this.Block = block;
 }
Пример #7
0
 public StmtTry(StmtBlock body_block, Stmt stmt, StmtBlock catch_block)
 {
     this.Body = body_block;
     this.Stmt = stmt;
     this.Catch = catch_block;
 }
Пример #8
0
 public StmtForEach(Expr expr, Expr target, StmtBlock body)
 {
     this.Var = expr;
     this.Target = target;
     this.Body = body;
 }
Пример #9
0
 public StmtIf(Expr condition, StmtBlock body_block, StmtBlock else_block)
 {
     this.Condition = condition;
     this.Body = body_block;
     this.Else = else_block;
 }
Пример #10
0
        public override Template Visit(StmtBlock block)
        {
            Template template = new Template("<list; separator=\"\n\">");
            List<Template> list = new List<Template>();

            int defer_count = 0;
            int scoped_finally_count = 0;
            bool contains_break = false;
            foreach (var node in block.StmtList)
            {
                if (node is StmtDefer)
                {
                    var stmt_defer = (StmtDefer)node;
                    defer_count++;
                    defer_stack.Push(stmt_defer.Stmt.Accept(this));
                    continue;
                }

                contains_break = contains_break || node is StmtReturn;

                if (defer_stack.Count() > 0 && node is StmtReturn)
                {
                    var stmt_return = (StmtReturn) node;
                    if (stmt_return.Expr == null)
                    {
                        foreach (var item in defer_stack)
                        {
                            list.Add(item);
                        }
                        list.Add(node.Accept(this));
                    }
                    else
                    {
                        Template expr = new Template("{ auto defer=<expr>; <list; separator=\" \"> return defer; }");
                        expr.Add("expr", stmt_return.Expr.Accept(this));
                        expr.Add("list", defer_stack.ToList());
                        list.Add(expr);
                    }
                    continue;
                }

                if (node is StmtFinally)
                {
                    var stmt_finally = (StmtFinally)node;
                    string name = string.Format("_t_finally_{0}", stmt_finally_count);
                    stmt_finally_count++;
                    scoped_finally_count++;
                    Template stmt =
                        new Template(
                            "class <name> {\npublic:\n    std::function\\<void()> finally;\n    ~<name>() { finally(); }\n} <name> = { [&]() { <expr> } };");
                    stmt.Add("name", name);
                    stmt.Add("expr", stmt_finally.Stmt.Accept(this));
                    list.Add(stmt);
                    continue;
                }

                if (node is StmtExpr)
                {
                    StmtExpr stmt = (StmtExpr)node;
                    if (stmt.Stmt is ExprConst)
                    {
                        string text = ((ExprConst)stmt.Stmt).Text;
                        if (text == "break" || text == "continue")
                        {
                            contains_break = true;
                            for (int i = 0; i < defer_count; i++)
                            {
                                list.Add(defer_stack.ElementAt(i));
                            }
                        }
                    }
                }

                list.Add(node.Accept(this));
            }

            for (int i = 0; i < defer_count; i++)
            {
                if (contains_break)
                {
                    defer_stack.Pop();
                }
                else
                {
                    list.Add(defer_stack.Pop());
                }
            }

            stmt_finally_count -= scoped_finally_count;

            template.Add("list", list);
            return template;
        }
Пример #11
0
	private StmtBlock stmt_block()
	{
		EnterRule_stmt_block();
		EnterRule("stmt_block", 25);
		TraceIn("stmt_block", 25);
		StmtBlock value = default(StmtBlock);


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


			value = new StmtBlock();

		try { DebugEnterRule(GrammarFileName, "stmt_block");
		DebugLocation(366, 4);
		try
		{
			// SugarWalker.g:371:2: ( ^( Stmt_Block (a= stmt )* ) )
			DebugEnterAlt(1);
			// SugarWalker.g:371:4: ^( Stmt_Block (a= stmt )* )
			{
			DebugLocation(371, 4);
			DebugLocation(371, 6);
			Match(input,Stmt_Block,Follow._Stmt_Block_in_stmt_block1334); 

			if (input.LA(1) == TokenTypes.Down)
			{
				Match(input, TokenTypes.Down, null); 
				DebugLocation(371, 17);
				// SugarWalker.g:371:17: (a= stmt )*
				try { DebugEnterSubRule(47);
				while (true)
				{
					int alt47=2;
					try { DebugEnterDecision(47, false);
					int LA47_0 = input.LA(1);

					if (((LA47_0>=Expr_Access && LA47_0<=Expr_Alloc_Equal)||(LA47_0>=Expr_Bin && LA47_0<=Expr_Where)||LA47_0==IDENT||LA47_0==Match_Expr||LA47_0==Match_Tuple||LA47_0==NUMBER||LA47_0==STRING||(LA47_0>=Stmt_Defer && LA47_0<=Stmt_While)||LA47_0==89||LA47_0==92||LA47_0==96||LA47_0==99||LA47_0==104||LA47_0==110||LA47_0==113||(LA47_0>=117 && LA47_0<=118)||LA47_0==121||LA47_0==128||(LA47_0>=130 && LA47_0<=131)||LA47_0==135||LA47_0==183||LA47_0==DOUBLE))
					{
						alt47 = 1;
					}


					} finally { DebugExitDecision(47); }
					switch ( alt47 )
					{
					case 1:
						DebugEnterAlt(1);
						// SugarWalker.g:371:18: a= stmt
						{
						DebugLocation(371, 19);
						PushFollow(Follow._stmt_in_stmt_block1339);
						a=stmt();
						PopFollow();

						DebugLocation(371, 25);
						 foreach (var x in a ) value.StmtList.Add(x); 

						}
						break;

					default:
						goto loop47;
					}
				}

				loop47:
					;

				} finally { DebugExitSubRule(47); }


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


			}

		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("stmt_block", 25);
			LeaveRule("stmt_block", 25);
			LeaveRule_stmt_block();
		}
		DebugLocation(372, 4);
		} finally { DebugExitRule(GrammarFileName, "stmt_block"); }
		return value;

	}
Пример #12
0
	private List<Stmt> stmt_translate()
	{
		EnterRule_stmt_translate();
		EnterRule("stmt_translate", 20);
		TraceIn("stmt_translate", 20);
		List<Stmt> value = default(List<Stmt>);


		Expr a = default(Expr);
		Expr b = default(Expr);
		List<string> d = default(List<string>);
		List<Expr> e = default(List<Expr>);


			value = new List<Stmt>();

		try { DebugEnterRule(GrammarFileName, "stmt_translate");
		DebugLocation(281, 1);
		try
		{
			// SugarWalker.g:286:2: ( ^( '?=' a= expr b= expr ) | ^( ':=' d= ident_list e= expr_list ) )
			int alt40=2;
			try { DebugEnterDecision(40, false);
			int LA40_0 = input.LA(1);

			if ((LA40_0==112))
			{
				alt40 = 1;
			}
			else if ((LA40_0==98))
			{
				alt40 = 2;
			}
			else
			{
				NoViableAltException nvae = new NoViableAltException("", 40, 0, input);
				DebugRecognitionException(nvae);
				throw nvae;
			}
			} finally { DebugExitDecision(40); }
			switch (alt40)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:286:4: ^( '?=' a= expr b= expr )
				{
				DebugLocation(286, 4);
				DebugLocation(286, 6);
				Match(input,112,Follow._112_in_stmt_translate1128); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(286, 12);
				PushFollow(Follow._expr_in_stmt_translate1132);
				a=expr();
				PopFollow();

				DebugLocation(286, 19);
				PushFollow(Follow._expr_in_stmt_translate1136);
				b=expr();
				PopFollow();


				Match(input, TokenTypes.Up, null); 

				DebugLocation(287, 2);

						StmtBlock block = new StmtBlock();
						block.StmtList.Add(new StmtExpr(new ExprAssign(a, b)));
						StmtIf stmt_if = new StmtIf(new ExprBin("==", a, new ExprConst("nullptr", ConstType.Ident)), block, null);
						value.Add(stmt_if);
					

				}
				break;
			case 2:
				DebugEnterAlt(2);
				// SugarWalker.g:293:4: ^( ':=' d= ident_list e= expr_list )
				{
				DebugLocation(293, 4);
				DebugLocation(293, 6);
				Match(input,98,Follow._98_in_stmt_translate1146); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(293, 12);
				PushFollow(Follow._ident_list_in_stmt_translate1150);
				d=ident_list();
				PopFollow();

				DebugLocation(293, 25);
				PushFollow(Follow._expr_list_in_stmt_translate1154);
				e=expr_list();
				PopFollow();


				Match(input, TokenTypes.Up, null); 

				DebugLocation(294, 2);

						int k = 0;
						for (int i = 0; i < d.Count(); i++)
						{
							value.Add(new StmtExpr(new ExprAlloc("auto", new List<string> { d[i] }, new List<Expr>{ e[k] }, true)));
							k = (k + 1) % e.Count();
						}
					

				}
				break;

			}
		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("stmt_translate", 20);
			LeaveRule("stmt_translate", 20);
			LeaveRule_stmt_translate();
		}
		DebugLocation(302, 1);
		} finally { DebugExitRule(GrammarFileName, "stmt_translate"); }
		return value;

	}
Пример #13
0
 public StmtWhile(Expr condition, StmtBlock body)
 {
     this.Condition = condition;
     this.Body      = body;
 }
Пример #14
0
 public abstract Template Visit(StmtBlock block);
Пример #15
0
	private FuncDef func_def()
	{
		EnterRule_func_def();
		EnterRule("func_def", 17);
		TraceIn("func_def", 17);
		FuncDef value = default(FuncDef);


		CommonTree deconstructor = default(CommonTree);
		List<Attr> attr = default(List<Attr>);
		string a = default(string);
		string b = default(string);
		List<string> x = default(List<string>);
		List<ExprAlloc> args = default(List<ExprAlloc>);
		StmtBlock e = default(StmtBlock);
		Expr f = default(Expr);


			value = new FuncDef();

		try { DebugEnterRule(GrammarFileName, "func_def");
		DebugLocation(210, 1);
		try
		{
			// SugarWalker.g:215:2: ( ^( Func_Def (attr= attribute )? (a= type_name )? (deconstructor= '~' )? b= ident (x= generic_parameter )? (args= func_args )? (e= stmt_block |f= expr ) ) )
			DebugEnterAlt(1);
			// SugarWalker.g:215:4: ^( Func_Def (attr= attribute )? (a= type_name )? (deconstructor= '~' )? b= ident (x= generic_parameter )? (args= func_args )? (e= stmt_block |f= expr ) )
			{
			DebugLocation(215, 4);
			DebugLocation(215, 6);
			Match(input,Func_Def,Follow._Func_Def_in_func_def919); 

			Match(input, TokenTypes.Down, null); 
			DebugLocation(215, 15);
			// SugarWalker.g:215:15: (attr= attribute )?
			int alt32=2;
			try { DebugEnterSubRule(32);
			try { DebugEnterDecision(32, false);
			int LA32_0 = input.LA(1);

			if ((LA32_0==Attribute))
			{
				alt32 = 1;
			}
			} finally { DebugExitDecision(32); }
			switch (alt32)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:215:16: attr= attribute
				{
				DebugLocation(215, 20);
				PushFollow(Follow._attribute_in_func_def924);
				attr=attribute();
				PopFollow();


				}
				break;

			}
			} finally { DebugExitSubRule(32); }

			DebugLocation(215, 33);
			// SugarWalker.g:215:33: (a= type_name )?
			int alt33=2;
			try { DebugEnterSubRule(33);
			try { DebugEnterDecision(33, false);
			int LA33_0 = input.LA(1);

			if ((LA33_0==Type_IDENT))
			{
				alt33 = 1;
			}
			} finally { DebugExitDecision(33); }
			switch (alt33)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:215:34: a= type_name
				{
				DebugLocation(215, 35);
				PushFollow(Follow._type_name_in_func_def931);
				a=type_name();
				PopFollow();


				}
				break;

			}
			} finally { DebugExitSubRule(33); }

			DebugLocation(215, 48);
			// SugarWalker.g:215:48: (deconstructor= '~' )?
			int alt34=2;
			try { DebugEnterSubRule(34);
			try { DebugEnterDecision(34, false);
			int LA34_0 = input.LA(1);

			if ((LA34_0==152))
			{
				alt34 = 1;
			}
			} finally { DebugExitDecision(34); }
			switch (alt34)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:215:49: deconstructor= '~'
				{
				DebugLocation(215, 62);
				deconstructor=(CommonTree)Match(input,152,Follow._152_in_func_def938); 

				}
				break;

			}
			} finally { DebugExitSubRule(34); }

			DebugLocation(215, 70);
			PushFollow(Follow._ident_in_func_def944);
			b=ident();
			PopFollow();

			DebugLocation(215, 77);
			// SugarWalker.g:215:77: (x= generic_parameter )?
			int alt35=2;
			try { DebugEnterSubRule(35);
			try { DebugEnterDecision(35, false);
			int LA35_0 = input.LA(1);

			if ((LA35_0==Generic_Patameters))
			{
				alt35 = 1;
			}
			} finally { DebugExitDecision(35); }
			switch (alt35)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:215:78: x= generic_parameter
				{
				DebugLocation(215, 79);
				PushFollow(Follow._generic_parameter_in_func_def949);
				x=generic_parameter();
				PopFollow();


				}
				break;

			}
			} finally { DebugExitSubRule(35); }

			DebugLocation(215, 101);
			// SugarWalker.g:215:101: (args= func_args )?
			int alt36=2;
			try { DebugEnterSubRule(36);
			try { DebugEnterDecision(36, false);
			int LA36_0 = input.LA(1);

			if ((LA36_0==Func_Args))
			{
				alt36 = 1;
			}
			} finally { DebugExitDecision(36); }
			switch (alt36)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:215:102: args= func_args
				{
				DebugLocation(215, 106);
				PushFollow(Follow._func_args_in_func_def957);
				args=func_args();
				PopFollow();

				DebugLocation(215, 117);
				 value.Args = args; 

				}
				break;

			}
			} finally { DebugExitSubRule(36); }

			DebugLocation(216, 2);
			// SugarWalker.g:216:2: (e= stmt_block |f= expr )
			int alt37=2;
			try { DebugEnterSubRule(37);
			try { DebugEnterDecision(37, false);
			int LA37_0 = input.LA(1);

			if ((LA37_0==Stmt_Block))
			{
				alt37 = 1;
			}
			else if (((LA37_0>=Expr_Access && LA37_0<=Expr_Tuple)||LA37_0==IDENT||LA37_0==Match_Tuple||LA37_0==NUMBER||LA37_0==STRING||LA37_0==75||LA37_0==78||LA37_0==82||LA37_0==85||LA37_0==89||LA37_0==95||LA37_0==98||LA37_0==102||LA37_0==104||LA37_0==110||LA37_0==113||LA37_0==117||LA37_0==150||LA37_0==DOUBLE))
			{
				alt37 = 2;
			}
			else
			{
				NoViableAltException nvae = new NoViableAltException("", 37, 0, input);
				DebugRecognitionException(nvae);
				throw nvae;
			}
			} finally { DebugExitDecision(37); }
			switch (alt37)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:216:4: e= stmt_block
				{
				DebugLocation(216, 5);
				PushFollow(Follow._stmt_block_in_func_def968);
				e=stmt_block();
				PopFollow();

				DebugLocation(217, 2);

						if (attr != null) value.Attribute = attr;
						value.Type = a;
						value.Name = b;
						if (deconstructor != null) 
						{
							value.Name = "~" + value.Name;
						}
						if (x != null)
						{
							value.GenericParameter = x;
						}
						value.Body = e;
					

				}
				break;
			case 2:
				DebugEnterAlt(2);
				// SugarWalker.g:231:4: f= expr
				{
				DebugLocation(231, 5);
				PushFollow(Follow._expr_in_func_def978);
				f=expr();
				PopFollow();

				DebugLocation(232, 2);

						if (attr != null) value.Attribute = attr;
						value.Type = a;
						value.Name = b;
						if (deconstructor != null) 
						{
							value.Name = "~" + value.Name;
						}
						StmtBlock block = new StmtBlock();
						if (a == "void" || a == null)
						{
							block.StmtList.Add(new StmtExpr(f));
						}
						else
						{
							block.StmtList.Add(new StmtReturn(f));
						}
						if (x != null)
						{
							value.GenericParameter = x;
						}
						value.Body = block;
					

				}
				break;

			}
			} finally { DebugExitSubRule(37); }


			Match(input, TokenTypes.Up, null); 


			}

		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("func_def", 17);
			LeaveRule("func_def", 17);
			LeaveRule_func_def();
		}
		DebugLocation(256, 1);
		} finally { DebugExitRule(GrammarFileName, "func_def"); }
		return value;

	}
        public override Template Visit(Enum enum_def)
        {
            if (enum_def.Attribute.Find(x => x.Name == "ToString") != null)
            {
                Attr attr = enum_def.Attribute.Find(x => x.Name == "ToString");

                FuncDef func = new FuncDef();
                func.Type = new IdentType("const char*");
                func.Name = attr.Args.Count() == 0 ? "ToString" : attr.Args.First();
                func.Args.Add(new ExprAlloc(new IdentType("const " + enum_def.Name + "&"), "_t_value", null, AllocType.Declare));
                List<StmtSwitchItem> switch_list = new List<StmtSwitchItem>();
                foreach (var item in enum_def.Values)
                {
                    StmtBlock block = new StmtBlock();
                    block.StmtList.Add(new StmtReturn(new ExprConst("\"" + item + "\"", ConstType.String)));
                    switch_list.Add(new StmtSwitchItem(new List<Expr> { new ExprConst(enum_def.Name + "::" + item, ConstType.Ident) }, block));
                }

                StmtBlock default_block = new StmtBlock();
                {
                    default_block.StmtList.Add(new StmtExpr(new ExprCall(new ExprConst("throw", ConstType.Ident), null, new List<Expr> { new ExprConst("\"Not Found\"", ConstType.String) })));
                }

                StmtSwitch stmt_switch = new StmtSwitch(new ExprConst("_t_value", ConstType.Ident), switch_list, default_block);
                StmtBlock body = new StmtBlock();
                body.StmtList.Add(stmt_switch);
                func.Body = body;
                return func.Accept(this);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Пример #17
0
 public StmtTry(StmtBlock body_block, Stmt stmt, StmtBlock catch_block)
 {
     this.Body  = body_block;
     this.Stmt  = stmt;
     this.Catch = catch_block;
 }
Пример #18
0
 public StmtForEach(Expr expr, Expr target, StmtBlock body)
 {
     this.Var    = expr;
     this.Target = target;
     this.Body   = body;
 }
Пример #19
0
 public StmtWhile(Expr condition, StmtBlock body)
 {
     this.Condition = condition;
     this.Body = body;
 }
Пример #20
0
	private List<Stmt> stmt_translate()
	{
		EnterRule_stmt_translate();
		EnterRule("stmt_translate", 27);
		TraceIn("stmt_translate", 27);
		List<Stmt> value = default(List<Stmt>);


		Expr a = default(Expr);
		Expr b = default(Expr);
		List<string> d = default(List<string>);
		List<Expr> e = default(List<Expr>);


			value = new List<Stmt>();

		try { DebugEnterRule(GrammarFileName, "stmt_translate");
		DebugLocation(390, 1);
		try
		{
			// SugarWalker.g:395:2: ( ^( '?=' a= expr b= expr ) | ^( ':=' d= ident_list e= expr_list ) | ^( '<<' a= expr b= expr ) )
			int alt49=3;
			try { DebugEnterDecision(49, false);
			switch (input.LA(1))
			{
			case 130:
				{
				alt49 = 1;
				}
				break;
			case 113:
				{
				alt49 = 2;
				}
				break;
			case 117:
				{
				alt49 = 3;
				}
				break;
			default:
				{
					NoViableAltException nvae = new NoViableAltException("", 49, 0, input);
					DebugRecognitionException(nvae);
					throw nvae;
				}
			}

			} finally { DebugExitDecision(49); }
			switch (alt49)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:395:4: ^( '?=' a= expr b= expr )
				{
				DebugLocation(395, 4);
				DebugLocation(395, 6);
				Match(input,130,Follow._130_in_stmt_translate1464); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(395, 12);
				PushFollow(Follow._expr_in_stmt_translate1468);
				a=expr();
				PopFollow();

				DebugLocation(395, 19);
				PushFollow(Follow._expr_in_stmt_translate1472);
				b=expr();
				PopFollow();


				Match(input, TokenTypes.Up, null); 

				DebugLocation(396, 2);

						StmtBlock block = new StmtBlock();
						block.StmtList.Add(new StmtExpr(new ExprAssign(a, b)));
						StmtIf stmt_if = new StmtIf(new ExprBin("==", a, new ExprConst("nullptr", ConstType.Ident)), block, null);
						value.Add(stmt_if);
					

				}
				break;
			case 2:
				DebugEnterAlt(2);
				// SugarWalker.g:402:4: ^( ':=' d= ident_list e= expr_list )
				{
				DebugLocation(402, 4);
				DebugLocation(402, 6);
				Match(input,113,Follow._113_in_stmt_translate1482); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(402, 12);
				PushFollow(Follow._ident_list_in_stmt_translate1486);
				d=ident_list();
				PopFollow();

				DebugLocation(402, 25);
				PushFollow(Follow._expr_list_in_stmt_translate1490);
				e=expr_list();
				PopFollow();


				Match(input, TokenTypes.Up, null); 

				DebugLocation(403, 2);

						int k = 0;
						for (int i = 0; i < d.Count(); i++)
						{
							value.Add(new StmtExpr(new ExprAlloc(new AutoType(), d[i], e[k], AllocType.Equal)));
							k = (k + 1) % e.Count();
						}
					

				}
				break;
			case 3:
				DebugEnterAlt(3);
				// SugarWalker.g:411:4: ^( '<<' a= expr b= expr )
				{
				DebugLocation(411, 4);
				DebugLocation(411, 6);
				Match(input,117,Follow._117_in_stmt_translate1500); 

				Match(input, TokenTypes.Down, null); 
				DebugLocation(411, 12);
				PushFollow(Follow._expr_in_stmt_translate1504);
				a=expr();
				PopFollow();

				DebugLocation(411, 19);
				PushFollow(Follow._expr_in_stmt_translate1508);
				b=expr();
				PopFollow();


				Match(input, TokenTypes.Up, null); 


				}
				break;

			}
		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("stmt_translate", 27);
			LeaveRule("stmt_translate", 27);
			LeaveRule_stmt_translate();
		}
		DebugLocation(412, 1);
		} finally { DebugExitRule(GrammarFileName, "stmt_translate"); }
		return value;

	}
Пример #21
0
 public StmtSwitch(Expr expr, List<StmtSwitchItem> list, StmtBlock default_block)
 {
     this.Expr = expr;
     if (list != null)
     {
         this.List = list;
     }
     this.DefalutBlock = default_block;
 }
Пример #22
0
 public StmtIf(Expr condition, StmtBlock body_block, StmtBlock else_block)
 {
     this.Condition = condition;
     this.Body      = body_block;
     this.Else      = else_block;
 }
Пример #23
0
	private StmtBlock stmt_block()
	{
		EnterRule_stmt_block();
		EnterRule("stmt_block", 18);
		TraceIn("stmt_block", 18);
		StmtBlock value = default(StmtBlock);


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


			value = new StmtBlock();

		try { DebugEnterRule(GrammarFileName, "stmt_block");
		DebugLocation(258, 4);
		try
		{
			// SugarWalker.g:263:2: ( ^( Stmt_Block (a= stmt )* ) )
			DebugEnterAlt(1);
			// SugarWalker.g:263:4: ^( Stmt_Block (a= stmt )* )
			{
			DebugLocation(263, 4);
			DebugLocation(263, 6);
			Match(input,Stmt_Block,Follow._Stmt_Block_in_stmt_block1006); 

			if (input.LA(1) == TokenTypes.Down)
			{
				Match(input, TokenTypes.Down, null); 
				DebugLocation(263, 17);
				// SugarWalker.g:263:17: (a= stmt )*
				try { DebugEnterSubRule(38);
				while (true)
				{
					int alt38=2;
					try { DebugEnterDecision(38, false);
					int LA38_0 = input.LA(1);

					if (((LA38_0>=Expr_Access && LA38_0<=Expr_Tuple)||LA38_0==IDENT||LA38_0==Match_Tuple||LA38_0==NUMBER||LA38_0==STRING||(LA38_0>=Stmt_Defer && LA38_0<=Stmt_While)||LA38_0==75||LA38_0==78||LA38_0==82||LA38_0==85||LA38_0==89||LA38_0==95||LA38_0==98||LA38_0==102||LA38_0==104||LA38_0==110||(LA38_0>=112 && LA38_0<=113)||LA38_0==117||LA38_0==150||LA38_0==DOUBLE))
					{
						alt38 = 1;
					}


					} finally { DebugExitDecision(38); }
					switch ( alt38 )
					{
					case 1:
						DebugEnterAlt(1);
						// SugarWalker.g:263:18: a= stmt
						{
						DebugLocation(263, 19);
						PushFollow(Follow._stmt_in_stmt_block1011);
						a=stmt();
						PopFollow();

						DebugLocation(263, 25);
						 foreach (var x in a ) value.StmtList.Add(x); 

						}
						break;

					default:
						goto loop38;
					}
				}

				loop38:
					;

				} finally { DebugExitSubRule(38); }


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


			}

		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("stmt_block", 18);
			LeaveRule("stmt_block", 18);
			LeaveRule_stmt_block();
		}
		DebugLocation(264, 4);
		} finally { DebugExitRule(GrammarFileName, "stmt_block"); }
		return value;

	}
Пример #24
0
 public StmtSwitchItem(List<Expr> list, StmtBlock block)
 {
     if (list != null)
     {
         this.ExprList = list;
     }
     this.Block = block;
 }
Пример #25
0
 public StmtFor(List<ForItem> list, StmtBlock body)
 {
     if (list != null)
     {
         this.List = list;
     }
     this.Body = body;
 }
Пример #26
0
 public ExprCurryLambda(StmtBlock block, List<ExprAlloc> args, bool isRef, SugarType type)
 {
     this.Block = block;
     if (args != null)
     {
         this.Args = args;
     }
     this.IsRef = isRef;
     this.Type = type;
 }
Пример #27
0
        public override Template Visit(Enum enum_def)
        {
            Template template = new Template("enum <name> {\n    <list; separator=\",\n\">\n};<tostring>");
            template.Add("name", enum_def.Name);
            List<Template> list = new List<Template>();
            bool hasFlagAttribute = enum_def.Attribute.Find(x => x.Name == "FlagAttribute") != null;
            int i = 0;
            foreach (var item in enum_def.Values)
            {
                Template tp = new Template("<node><suffix>");
                tp.Add("node", item);
                if (i == 0 || hasFlagAttribute)
                {
                    tp.Add("suffix", string.Format(" = {0}", i));
                }
                else
                {
                    tp.Add("suffix", "");
                }
                list.Add(tp);
                if (hasFlagAttribute)
                {
                    i = i == 0 ? 1 : i * 2;
                }
                else
                {
                    i = i + 1;
                }
            }
            template.Add("list", list);

            if (enum_def.Attribute.Find(x => x.Name == "ToString") != null)
            {
                Attr attr = enum_def.Attribute.Find(x => x.Name == "ToString");

                FuncDef func = new FuncDef();
                func.Type = "const char*";
                func.Name = attr.Args.Count() == 0 ? "ToString" : attr.Args.First();
                func.Args.Add(new ExprAlloc("const " + enum_def.Name + "&", new List<string> { "a" }, null, true));
                StmtBlock body = new StmtBlock();
                StmtSwitch stmt_switch = new StmtSwitch();
                stmt_switch.Expr = new ExprConst("a", ConstType.Ident);
                foreach (var item in enum_def.Values)
                {
                    StmtBlock block = new StmtBlock();
                    block.StmtList.Add(new StmtReturn(new ExprConst("\"" + item + "\"", ConstType.String)));
                    stmt_switch.List.Add(new StmtSwitchItem(new ExprConst(item, ConstType.Ident), block));
                }
                body.StmtList.Add(stmt_switch);
                func.Body = body;
                Template node = new Template("\n\n<stmt>");
                node.Add("stmt", func.Accept(this));
                template.Add("tostring", node);
            }
            else
            {
                template.Add("tostring", "");
            }
            return template;
        }
Пример #28
0
 public abstract Template Visit(StmtBlock block);
Пример #29
0
 public override Template Visit(StmtForEach stmt_for_each)
 {
     if (stmt_for_each.Var is ExprConst)
     {
         ExprConst expr = (ExprConst) stmt_for_each.Var;
         Template template = new Template("for (auto <var> : <expr>) {\n    <body>\n}");
         template.Add("var", expr.Text);
         template.Add("expr", stmt_for_each.Target.Accept(this));
         template.Add("body", stmt_for_each.Body.Accept(this));
         return template;
     }
     else if (stmt_for_each.Var is ExprCall)
     {
         ExprCall expr = (ExprCall)stmt_for_each.Var;
         List<Stmt> stmt_list = new List<Stmt>();
         List<Expr> condition_list = new List<Expr>();
         int i = 0;
         foreach (var argument in expr.Args)
         {
             ExprCall get = new ExprCall(new ExprConst("std::get", ConstType.Ident), new List<string> {i.ToString()},
                                         new List<Expr> {new ExprConst("_t_match", ConstType.Ident)});
             i++;
             if (argument is ExprConst && ((ExprConst)argument).Type == ConstType.Ident && !((ExprConst)argument).Text.StartsWith("@"))
             {
                 ExprConst const_expr = (ExprConst)argument;
                 if (const_expr.Text == "_")
                 {
                     continue;
                 }
                 stmt_list.Add(new StmtExpr(new ExprAlloc("auto", new List<string> { const_expr.Text }, new List<Expr>{ get }, true)));
             }
             else
             {
                 if (((ExprConst)argument).Text.StartsWith("@"))
                 {
                     ((ExprConst)argument).Text = ((ExprConst)argument).Text.Substring(1);
                 }
                 condition_list.Add(new ExprBin("==", get, argument));
             }
         }
         StmtBlock block = new StmtBlock();
         foreach (var item in stmt_list)
         {
             block.StmtList.Add(item);
         }
         foreach (var item in stmt_for_each.Body.StmtList)
         {
             block.StmtList.Add(item);
         }
         if (condition_list.Count() > 0)
         {
             StmtBlock if_body = new StmtBlock();
             if_body.StmtList.Add(new StmtExpr(new ExprAlloc("auto&&", new List<string> { "_t_match" }, new List<Expr> { new ExprCall(new ExprAccess(new ExprConst("_t_iterator", ConstType.Ident), ".", "Unapply"), null, null) }, true)));
             Expr condition = null;
             foreach (var item in condition_list)
             {
                 if (condition == null)
                 {
                     condition = item;
                     if (condition_list.Count() > 1)
                     {
                         condition = new ExprBracket(condition);
                     }
                 }
                 else
                 {
                     condition = new ExprBin("&&", condition, new ExprBracket(item));
                 }
             }
             StmtIf stmt_if = new StmtIf(condition, block, null);
             if_body.StmtList.Add(stmt_if);
             block = if_body;
         }
         else
         {
             block.StmtList.Insert(0, new StmtExpr(new ExprAlloc("auto&&", new List<string> { "_t_match" }, new List<Expr> { new ExprCall(new ExprAccess(new ExprConst("_t_iterator", ConstType.Ident), ".", "Unapply"), null, null) }, true)));
         }
         StmtForEach for_each = new StmtForEach(new ExprConst("_t_iterator", ConstType.Ident), stmt_for_each.Target, block);
         return for_each.Accept(this);
     }
     else if (stmt_for_each.Var is ExprTuple)
     {
         ExprTuple expr = (ExprTuple)stmt_for_each.Var;
         List<Stmt> stmt_list = new List<Stmt>();
         List<Expr> condition_list = new List<Expr>();
         int i = 0;
         foreach (var argument in expr.ExprList)
         {
             ExprCall get = new ExprCall(new ExprConst("get", ConstType.Ident), new List<string> { i.ToString() },
                                         new List<Expr> { new ExprConst("_t_match", ConstType.Ident) });
             i++;
             if (argument is ExprConst && ((ExprConst)argument).Type == ConstType.Ident)
             {
                 ExprConst const_expr = (ExprConst)argument;
                 if (const_expr.Text == "_")
                 {
                     continue;
                 }
                 stmt_list.Add(new StmtExpr(new ExprAlloc("auto", new List<string> { const_expr.Text }, new List<Expr> { get }, true)));
             }
             else
             {
                 condition_list.Add(new ExprBin("==", get, argument));
             }
         }
         StmtBlock block = new StmtBlock();
         foreach (var item in stmt_list)
         {
             block.StmtList.Add(item);
         }
         foreach (var item in stmt_for_each.Body.StmtList)
         {
             block.StmtList.Add(item);
         }
         if (condition_list.Count() > 0)
         {
             StmtBlock if_body = new StmtBlock();
             Expr condition = null;
             foreach (var item in condition_list)
             {
                 if (condition == null)
                 {
                     condition = item;
                     if (condition_list.Count() > 1)
                     {
                         condition = new ExprBracket(condition);
                     }
                 }
                 else
                 {
                     condition = new ExprBin("&&", condition, new ExprBracket(item));
                 }
             }
             StmtIf stmt_if = new StmtIf(condition, block, null);
             if_body.StmtList.Add(stmt_if);
             block = if_body;
         }
         StmtForEach for_each = new StmtForEach(new ExprConst("_t_match", ConstType.Ident), stmt_for_each.Target, block);
         return for_each.Accept(this);
     }
     else
     {
         throw new Exception(string.Format("Iterators in foreach must be either variable or pattern matching"));
     }
 }
Пример #30
0
	private FuncDef func_def()
	{
		EnterRule_func_def();
		EnterRule("func_def", 24);
		TraceIn("func_def", 24);
		FuncDef value = default(FuncDef);


		CommonTree pub = default(CommonTree);
		CommonTree vir = default(CommonTree);
		CommonTree deconstructor = default(CommonTree);
		CommonTree op = default(CommonTree);
		List<Attr> attr = default(List<Attr>);
		SugarType a = default(SugarType);
		string b = default(string);
		List<SugarType> x = default(List<SugarType>);
		List<ExprAlloc> args = default(List<ExprAlloc>);
		StmtBlock e = default(StmtBlock);
		Expr f = default(Expr);


			value = new FuncDef();

		try { DebugEnterRule(GrammarFileName, "func_def");
		DebugLocation(287, 1);
		try
		{
			// SugarWalker.g:292:2: ( ^( Func_Def (pub= 'public' )? (vir= 'virtual' )? (attr= attribute )? (a= type_name )? (deconstructor= '~' )? (b= ident |op= ( '+' | '-' | '*' | '/' ) )? (x= generic_parameter )? (args= func_args )? (e= stmt_block |f= expr | Func_Declare ) ) )
			DebugEnterAlt(1);
			// SugarWalker.g:292:4: ^( Func_Def (pub= 'public' )? (vir= 'virtual' )? (attr= attribute )? (a= type_name )? (deconstructor= '~' )? (b= ident |op= ( '+' | '-' | '*' | '/' ) )? (x= generic_parameter )? (args= func_args )? (e= stmt_block |f= expr | Func_Declare ) )
			{
			DebugLocation(292, 4);
			DebugLocation(292, 6);
			Match(input,Func_Def,Follow._Func_Def_in_func_def1209); 

			Match(input, TokenTypes.Down, null); 
			DebugLocation(292, 15);
			// SugarWalker.g:292:15: (pub= 'public' )?
			int alt38=2;
			try { DebugEnterSubRule(38);
			try { DebugEnterDecision(38, false);
			int LA38_0 = input.LA(1);

			if ((LA38_0==163))
			{
				alt38 = 1;
			}
			} finally { DebugExitDecision(38); }
			switch (alt38)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:292:16: pub= 'public'
				{
				DebugLocation(292, 19);
				pub=(CommonTree)Match(input,163,Follow._163_in_func_def1214); 

				}
				break;

			}
			} finally { DebugExitSubRule(38); }

			DebugLocation(292, 31);
			// SugarWalker.g:292:31: (vir= 'virtual' )?
			int alt39=2;
			try { DebugEnterSubRule(39);
			try { DebugEnterDecision(39, false);
			int LA39_0 = input.LA(1);

			if ((LA39_0==178))
			{
				alt39 = 1;
			}
			} finally { DebugExitDecision(39); }
			switch (alt39)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:292:32: vir= 'virtual'
				{
				DebugLocation(292, 35);
				vir=(CommonTree)Match(input,178,Follow._178_in_func_def1221); 

				}
				break;

			}
			} finally { DebugExitSubRule(39); }

			DebugLocation(292, 48);
			// SugarWalker.g:292:48: (attr= attribute )?
			int alt40=2;
			try { DebugEnterSubRule(40);
			try { DebugEnterDecision(40, false);
			int LA40_0 = input.LA(1);

			if ((LA40_0==Attribute))
			{
				alt40 = 1;
			}
			} finally { DebugExitDecision(40); }
			switch (alt40)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:292:49: attr= attribute
				{
				DebugLocation(292, 53);
				PushFollow(Follow._attribute_in_func_def1228);
				attr=attribute();
				PopFollow();


				}
				break;

			}
			} finally { DebugExitSubRule(40); }

			DebugLocation(292, 65);
			// SugarWalker.g:292:65: (a= type_name )?
			int alt41=2;
			try { DebugEnterSubRule(41);
			try { DebugEnterDecision(41, false);
			int LA41_0 = input.LA(1);

			if (((LA41_0>=Type_Array && LA41_0<=Type_Ident)||(LA41_0>=Type_Ref && LA41_0<=Type_Template)))
			{
				alt41 = 1;
			}
			} finally { DebugExitDecision(41); }
			switch (alt41)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:292:66: a= type_name
				{
				DebugLocation(292, 67);
				PushFollow(Follow._type_name_in_func_def1234);
				a=type_name();
				PopFollow();


				}
				break;

			}
			} finally { DebugExitSubRule(41); }

			DebugLocation(292, 80);
			// SugarWalker.g:292:80: (deconstructor= '~' )?
			int alt42=2;
			try { DebugEnterSubRule(42);
			try { DebugEnterDecision(42, false);
			int LA42_0 = input.LA(1);

			if ((LA42_0==186))
			{
				alt42 = 1;
			}
			} finally { DebugExitDecision(42); }
			switch (alt42)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:292:81: deconstructor= '~'
				{
				DebugLocation(292, 94);
				deconstructor=(CommonTree)Match(input,186,Follow._186_in_func_def1241); 

				}
				break;

			}
			} finally { DebugExitSubRule(42); }

			DebugLocation(292, 101);
			// SugarWalker.g:292:101: (b= ident |op= ( '+' | '-' | '*' | '/' ) )?
			int alt43=3;
			try { DebugEnterSubRule(43);
			try { DebugEnterDecision(43, false);
			try
			{
				alt43 = dfa43.Predict(input);
			}
			catch (NoViableAltException nvae)
			{
				DebugRecognitionException(nvae);
				throw;
			}
			} finally { DebugExitDecision(43); }
			switch (alt43)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:292:102: b= ident
				{
				DebugLocation(292, 103);
				PushFollow(Follow._ident_in_func_def1248);
				b=ident();
				PopFollow();


				}
				break;
			case 2:
				DebugEnterAlt(2);
				// SugarWalker.g:292:112: op= ( '+' | '-' | '*' | '/' )
				{
				DebugLocation(292, 114);

				op=(CommonTree)input.LT(1);
				if (input.LA(1)==95||input.LA(1)==97||input.LA(1)==101||input.LA(1)==109)
				{
					input.Consume();
					state.errorRecovery=false;
				}
				else
				{
					MismatchedSetException mse = new MismatchedSetException(null,input);
					DebugRecognitionException(mse);
					throw mse;
				}


				}
				break;

			}
			} finally { DebugExitSubRule(43); }

			DebugLocation(292, 135);
			// SugarWalker.g:292:135: (x= generic_parameter )?
			int alt44=2;
			try { DebugEnterSubRule(44);
			try { DebugEnterDecision(44, false);
			int LA44_0 = input.LA(1);

			if ((LA44_0==Generic_Patameters))
			{
				alt44 = 1;
			}
			} finally { DebugExitDecision(44); }
			switch (alt44)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:292:136: x= generic_parameter
				{
				DebugLocation(292, 137);
				PushFollow(Follow._generic_parameter_in_func_def1269);
				x=generic_parameter();
				PopFollow();


				}
				break;

			}
			} finally { DebugExitSubRule(44); }

			DebugLocation(292, 159);
			// SugarWalker.g:292:159: (args= func_args )?
			int alt45=2;
			try { DebugEnterSubRule(45);
			try { DebugEnterDecision(45, false);
			int LA45_0 = input.LA(1);

			if ((LA45_0==Func_Args))
			{
				alt45 = 1;
			}
			} finally { DebugExitDecision(45); }
			switch (alt45)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:292:160: args= func_args
				{
				DebugLocation(292, 164);
				PushFollow(Follow._func_args_in_func_def1277);
				args=func_args();
				PopFollow();

				DebugLocation(292, 175);
				 value.Args = args; 

				}
				break;

			}
			} finally { DebugExitSubRule(45); }

			DebugLocation(293, 2);
			// SugarWalker.g:293:2: (e= stmt_block |f= expr | Func_Declare )
			int alt46=3;
			try { DebugEnterSubRule(46);
			try { DebugEnterDecision(46, false);
			switch (input.LA(1))
			{
			case Stmt_Block:
				{
				alt46 = 1;
				}
				break;
			case Expr_Access:
			case Expr_Alloc_Bracket:
			case Expr_Alloc_Equal:
			case Expr_Bin:
			case Expr_Bracket:
			case Expr_Call:
			case Expr_Call_With:
			case Expr_Cast:
			case Expr_Chain:
			case Expr_Cond:
			case Expr_Cond_Not_Null:
			case Expr_Dict:
			case Expr_Infix:
			case Expr_Lambda:
			case Expr_List:
			case Expr_List_Generation:
			case Expr_New_Array:
			case Expr_New_Type:
			case Expr_Not_Null:
			case Expr_Prefix:
			case Expr_Suffix:
			case Expr_Tuple:
			case Expr_Where:
			case IDENT:
			case Match_Expr:
			case Match_Tuple:
			case NUMBER:
			case STRING:
			case 89:
			case 92:
			case 96:
			case 99:
			case 104:
			case 110:
			case 113:
			case 118:
			case 121:
			case 128:
			case 131:
			case 135:
			case 183:
			case DOUBLE:
				{
				alt46 = 2;
				}
				break;
			case Func_Declare:
				{
				alt46 = 3;
				}
				break;
			default:
				{
					NoViableAltException nvae = new NoViableAltException("", 46, 0, input);
					DebugRecognitionException(nvae);
					throw nvae;
				}
			}

			} finally { DebugExitDecision(46); }
			switch (alt46)
			{
			case 1:
				DebugEnterAlt(1);
				// SugarWalker.g:293:4: e= stmt_block
				{
				DebugLocation(293, 5);
				PushFollow(Follow._stmt_block_in_func_def1288);
				e=stmt_block();
				PopFollow();

				DebugLocation(294, 2);

						if (attr != null) value.Attribute = attr;
						if (pub != null) value.Attribute.Add(new Attr { Name = "public" });
						if (vir != null) value.Attribute.Add(new Attr { Name = "virtual" });
						value.Type = a;
						value.Name = b != null ? b : "operator" + op.Text;
						if (deconstructor != null)
						{
							value.Name = "~" + value.Name;
						}
						if (x != null)
						{
							value.GenericParameter = x;
						}
						value.Body = e;
					

				}
				break;
			case 2:
				DebugEnterAlt(2);
				// SugarWalker.g:310:4: f= expr
				{
				DebugLocation(310, 5);
				PushFollow(Follow._expr_in_func_def1298);
				f=expr();
				PopFollow();

				DebugLocation(311, 2);

						if (attr != null) value.Attribute = attr;
						if (pub != null) value.Attribute.Add(new Attr { Name = "public" });
						if (vir != null) value.Attribute.Add(new Attr { Name = "virtual" });
						value.Type = a;
						value.Name = b != null ? b : "operator" + op.Text;
						if (deconstructor != null)
						{
							value.Name = "~" + value.Name;
						}
						StmtBlock block = new StmtBlock();
						if ((a is IdentType && ((IdentType)a).Type=="void") || a == null)
						{
							block.StmtList.Add(new StmtExpr(f));
						}
						else
						{
							block.StmtList.Add(new StmtReturn(f));
						}
						if (x != null)
						{
							value.GenericParameter = x;
						}
						value.Body = block;
					

				}
				break;
			case 3:
				DebugEnterAlt(3);
				// SugarWalker.g:336:4: Func_Declare
				{
				DebugLocation(336, 4);
				Match(input,Func_Declare,Follow._Func_Declare_in_func_def1306); 
				DebugLocation(337, 2);

						if (attr != null) value.Attribute = attr;
						if (pub != null) value.Attribute.Add(new Attr { Name = "public" });
						if (vir != null) value.Attribute.Add(new Attr { Name = "virtual" });
						value.Attribute.Add(new Attr { Name = "extern" });
						value.Type = a;
						value.Name = b != null ? b : "operator" + op.Text;
						if (deconstructor != null)
						{
							value.Name = "~" + value.Name;
						}
						StmtBlock block = new StmtBlock();
						if ((a is IdentType && ((IdentType)a).Type=="void") || a == null)
						{
							block.StmtList.Add(new StmtExpr(f));
						}
						else
						{
							block.StmtList.Add(new StmtReturn(f));
						}
						if (x != null)
						{
							value.GenericParameter = x;
						}
						value.Body = null;
					

				}
				break;

			}
			} finally { DebugExitSubRule(46); }


			Match(input, TokenTypes.Up, null); 


			}

		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("func_def", 24);
			LeaveRule("func_def", 24);
			LeaveRule_func_def();
		}
		DebugLocation(364, 1);
		} finally { DebugExitRule(GrammarFileName, "func_def"); }
		return value;

	}