Minor change to AstNode.cs requested

Sep 19, 2012 at 6:52 PM

Can the definition of AsString in AstNode.cs be made virtual? This enables overriding it in derived classes.

It seems easier all round for me to just describe this change, instead of checking in code, to be reviewed by you, etc. If I am wrong, just let me know.

Thanks very much.



Sep 20, 2012 at 4:45 PM

sure, no problem, will change in the next code drop, whenever it comes.

But why do you need this? why existing ability to assign it in node constructor is not enough? - what scenario do you have?

Sep 21, 2012 at 12:29 PM

I am building a class hierarchy from MyAstNode, deriving from AstNode, with the following snippet at the end of MyAstNode.Init(...):

public class MyAstNode : AstNode




public override void Init(AstContext context, ParseTreeNode treeNode) {

<Much irrelevant stuff>

AsString = GetType().Name.Replace("Node","");




public override string

AsString {



get { return base

.AsString + Suffix; }



protected set { base.AsString = value

; }




public virtual string Suffix { get { return ""; } }





Sep 21, 2012 at 12:46 PM

Also - Thank you for the quick reply. 

Sep 21, 2012 at 4:44 PM

Hmm... strange - why don't you append the Suffix in constructor directly? even if Suffix is overridden in descendant, it will return node-specific value; and if initialization is complete by this point, it should return proper value (I guess)

Sep 21, 2012 at 4:54 PM

It's a timing issue - the proper value of Suffix is not known at Init time, but is rather calculated later.



Sep 21, 2012 at 4:57 PM

but then I suggest to make this timing dependency explicit: assign initial value of AsString in constructor; then update it later when you compute the suffix. 

Sep 21, 2012 at 5:22 PM

We must agree to disagree on which coding style works best, and is most clear to the reader.


My initial reaction on discovering that I could not override a non-virtual property was "Holy cow Batman! I must remember to make all my properties virtual."

Sep 21, 2012 at 11:05 PM

On reflection, let me expand:. Since the AST nodes are displayed by the core code in Irony, the sub-classed implementation of AsString must be overrides instead of new, so that the modified implementation replaces that buried in AstNode.cs.

Keep up the good work - I am thoroughly enjoying working with Irony.