Esempio n. 1
0
        private static void genConcreteNode(GenContext ctx, NodeConcreteDecl nodeConcreteDecl)
        {
            ctx.Appendfnl("public partial class {0} : {1}", nodeConcreteDecl.id, ctx.prg.baseClass.name);
            ctx.Appendfnl("{{");
            ctx.IncreaseIndent();
            foreach (var field in nodeConcreteDecl.fields)
            {
                GenerateField(ctx, field);
            }
            foreach (var attr in nodeConcreteDecl.attributes)
            {
                ctx.Appendfnl("public {0} {1} {{ get; set; }}", attr.type, attr.id);
            }
            {
                // default constructor
                ctx.Appendfnl("public {0}()", nodeConcreteDecl.id);
                ctx.Appendfnl("{{");
                foreach (var field in nodeConcreteDecl.fields)
                {
                    ctx.IncreaseIndent();
                    if (field.many)
                    {
                        ctx.Appendfnl("this.{0} = new {1}();", field.id, FieldToCsharpType(ctx, field));
                    }
                    ctx.DecreaseIndent();
                }
                ctx.Appendfnl("}}");
            }
            if (nodeConcreteDecl.fields.Count > 0)
            {
                // constructor with parameters
                var fieldsArgs = nodeConcreteDecl.fields.Select(x => string.Format("{0} {1}_p", FieldToCsharpType(ctx, x), x.id));
                ctx.Appendfnl("public {0}({1})", nodeConcreteDecl.id, string.Join(", ", fieldsArgs));
                ctx.Appendfnl("{{");
                ctx.IncreaseIndent();

                foreach (var field in nodeConcreteDecl.fields)
                {
                    var expr = field.id + "_p";
                    if (field.many)
                    {
                        expr = expr + " ?? new " + FieldToCsharpType(ctx, field) + "()";
                    }
                    ctx.Appendfnl("this.{0} = {1};", field.id, expr);
                }

                ctx.DecreaseIndent();
                ctx.Appendfnl("}}");
            }
            genReplaceChildNode(ctx, nodeConcreteDecl.fields);
            genToString(ctx, nodeConcreteDecl.id, nodeConcreteDecl.fields, nodeConcreteDecl.attributes);
            ctx.DecreaseIndent();
            ctx.Appendfnl("}}");
            ctx.NewLine();
        }
Esempio n. 2
0
 private static void genWalkerConcrete(GenContext ctx, NodeConcreteDecl nodeConcreteDecl)
 {
     ctx.Appendfnl("public virtual void walk{0}({1} __node)", nodeConcreteDecl.id, ToNs(ctx, nodeConcreteDecl.id));
     ctx.Appendfnl("{{");
     ctx.IncreaseIndent();
     var nodeName = nodeConcreteDecl.id;
     foreach (var field in nodeConcreteDecl.fields)
     {
         genWalkerField(ctx, nodeName, field);
     }
     ctx.DecreaseIndent();
     ctx.Appendfnl("}}");
 }
Esempio n. 3
0
	private NodeConcreteDecl nodeConcrete()
	{
		EnterRule_nodeConcrete();
		EnterRule("nodeConcrete", 10);
		TraceIn("nodeConcrete", 10);
		NodeConcreteDecl r = default(NodeConcreteDecl);


		IToken ID16 = default(IToken);
		List<FieldDecl> fields17 = default(List<FieldDecl>);
		List<AttributeDecl> attributes18 = default(List<AttributeDecl>);

		try { DebugEnterRule(GrammarFileName, "nodeConcrete");
		DebugLocation(85, 9);
		try
		{
			// ADL.g:86:5: ( ID EQ ( fields )? ( attributes )? SEMI )
			DebugEnterAlt(1);
			// ADL.g:86:7: ID EQ ( fields )? ( attributes )? SEMI
			{
			DebugLocation(86, 7);
			ID16=(IToken)Match(input,ID,Follow._ID_in_nodeConcrete489); 
			DebugLocation(86, 10);
			Match(input,EQ,Follow._EQ_in_nodeConcrete491); 
			DebugLocation(86, 13);
			// ADL.g:86:13: ( fields )?
			int alt13=2;
			try { DebugEnterSubRule(13);
			try { DebugEnterDecision(13, false);
			int LA13_1 = input.LA(1);

			if ((LA13_1==ID))
			{
				alt13 = 1;
			}
			} finally { DebugExitDecision(13); }
			switch (alt13)
			{
			case 1:
				DebugEnterAlt(1);
				// ADL.g:86:13: fields
				{
				DebugLocation(86, 13);
				PushFollow(Follow._fields_in_nodeConcrete493);
				fields17=fields();
				PopFollow();


				}
				break;

			}
			} finally { DebugExitSubRule(13); }

			DebugLocation(86, 21);
			// ADL.g:86:21: ( attributes )?
			int alt14=2;
			try { DebugEnterSubRule(14);
			try { DebugEnterDecision(14, false);
			int LA14_1 = input.LA(1);

			if ((LA14_1==ATTRIBUTES))
			{
				alt14 = 1;
			}
			} finally { DebugExitDecision(14); }
			switch (alt14)
			{
			case 1:
				DebugEnterAlt(1);
				// ADL.g:86:21: attributes
				{
				DebugLocation(86, 21);
				PushFollow(Follow._attributes_in_nodeConcrete496);
				attributes18=attributes();
				PopFollow();


				}
				break;

			}
			} finally { DebugExitSubRule(14); }

			DebugLocation(87, 4);
			 r = new NodeConcreteDecl 
			       { id = (ID16!=null?ID16.Text:default(string)),
			        fields = fields17 ?? new List<FieldDecl>(),
			        attributes = attributes18 ?? new List<AttributeDecl>()
			       };
			   
			DebugLocation(92, 6);
			Match(input,SEMI,Follow._SEMI_in_nodeConcrete504); 

			}

		}
		catch (RecognitionException re)
		{
			ReportError(re);
			Recover(input,re);
		}
		finally
		{
			TraceOut("nodeConcrete", 10);
			LeaveRule("nodeConcrete", 10);
			LeaveRule_nodeConcrete();
		}
		DebugLocation(92, 9);
		} finally { DebugExitRule(GrammarFileName, "nodeConcrete"); }
		return r;

	}