swp-uebersetzerbau-ss13 / common

Shared files between teams.
1 stars 0 forks source link

StructNode definition #12

Closed Tkrauss closed 11 years ago

Tkrauss commented 11 years ago

Since a struct consists of n fields, one must be able to identify the m-th field with a class ( extending Identifiernode). I think the following methods will be appropriate ( this can be easily implemented by delegating a Map): void AddField (String identifier, IdentifierNode node) IdentifierNode getFieldForIdentifier( String identifier ) ( for debugging purpose ) Set getAllIdentifiers()

correct me if i get the design wrong... rgds

fub-frank commented 11 years ago

There are two different use cases in the AST.

I will use the example struct Point { x: Double, y: Double}

  1. Defining a new Struct This is done by using Type in a DeclarationNode. The type definition is as follows in the current design
Type point = new StructType("Point", new MemberType("x", new DoubleType()), new MemberType("y", new DoubleType());
  1. Referring a Struct in the code For example, in the source program you have something like this:
print somepoint.x

This would become the following tree in the AST

PrintStatementNode
            |
            | rightValue
            |
StructIdentifierNode
   |              |
   | fieldName    |
   |              | IdentifierNode
  "x"             |
                  |
             BasicIdentifier
                      | identifier = "somepoint"

I hope that answers your question / clarifies the problem

Tkrauss commented 11 years ago

Thanks, it's clarified:). The constructor was the answer. Anyway, that's not the matter of the interface. From my point of view, the current design achieve our requirements.

fub-frank commented 11 years ago

No problem.

Type is already implemented and not just an interface. This was part of the SymbolTable definition. You can check it out over here: https://github.com/swp-uebersetzerbau-ss13/common/tree/master/interfaces/src/swp_compiler_ss13/common/types