History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-201
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Doug H
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

print AST visitor

Created: 02/Dec/04 06:49 PM   Updated: 21/Mar/05 06:11 PM
Component/s: Compiler
Affects Version/s: None
Fix Version/s: 0.7

Time Tracking:
Not Specified

File Attachments: 1. File astgen.boo (20 kb)
2. Text File astserialize.patch (2 kb)



 Description  « Hide
A visitor class that prints out the AST types. Useful when learning about the compiler and writing custom macros or attributes.

Additionally you could show the AST tree after each compiler step to visually show what each step did (you might use a "diff" tool to show differences between the tree at each step).



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Doug H - 09/Dec/04 07:07 PM
It looks like just a simple change was needed to make this work. Other changes can be made to make the xml output prettier. And you can create xslt to make it compatible with other AST representations out there like JavaML or .NET CodeDom, or do things like transfer the AST XML back into boo code.

Changes:

  • In boo.lang.compiler/ast/node.cs, add an [System.Xml.Serialization.XmlIgnore] above the Entity property (line 95). (otherwise you get an error because an interface type (IEntity) can't be serialized)
  • Add this to boo.lang.compiler/ast/statement.cs
    [System.Xml.Serialization.XmlInclude(typeof(MacroStatement))]

Optional to make the XML a little prettier:

  • Insert this at line 255 in scripts/astgen.boo:
    if field.Name == "Name":
    writer.WriteLine("""
    [System.Xml.Serialization.XmlAttribute]""")
  • Add an [System.Xml.Serialization.XmlAttribute] or [System.Xml.Serialization.XmlIgnore] above the IsSynthetic property in Node.cs.

I'll post a note to boo-dev with a sample script and its output.


Rodrigo B. de Oliveira - 09/Dec/04 07:11 PM
Hi, Doug,

Looks good to me. Can you provide a patch (diff) with the proposed changes?

Best wishes,
Rodrigo


Doug H - 09/Dec/04 07:29 PM
Right after I uploaded the patch, I realized I forgot to change writer.WriteLine to writer.Write in astgen.boo. Otherwise there is an extra (harmless) line break after the attribute.

+ if field.Name == "Name":
+ writer.Write("""
+ [System.Xml.Serialization.XmlAttribute]""")
+


Doug H - 10/Dec/04 06:42 PM
Here is my copy of astgen.boo to make a few other improvements to the xml output, like printing out the modifiers of a class or method (i.e. private, public, abstract...).

Also I made this one other change:

  • In node.cs, add an [System.ComponentModel.DefaultValue(false)] attribute above the IsSynthetic property to suppress all those issynthetic values in the xml output.

Doug H - 13/Dec/04 12:31 AM
You also need to add this line to Boo.Lang.Compiler/Ast/Expression.cs:

[System.Xml.Serialization.XmlInclude(typeof(TypeofExpression))]