fullstack-lang / gongdoc

A gong stack for editing UML diagrams of gong code
MIT License
1 stars 0 forks source link

Removal of BackPointers of Gong Objects ? #155

Closed thomaspeugeot closed 1 year ago

thomaspeugeot commented 1 year ago

Situation:

DSL = gong

Every DSL object has a BackPointer to a DSL node implementation. This allows the CheckNode() and DisableNodeCheckbox() operations from the DSL object.

At the initialisation, FillUpTreeOfGongObjects()

  1. Parses all DSL objects and
    1. creates a DSL object node
    2. creates a DSL object node implementation of the DSL object node
    3. links the DSL object node implementation to the DSL object
    4. set a back pointer from the DSL object to the DSL object node implementation

Given a classdiagram, computeDSLNodesConfiguration()

  1. Computes for all DSL object , is DSL shape is present in the diagram
  2. Parses all DSL objects and computes if disabling the DSL object node is necessary (to decide if the DSL object can be added to the diagram). If so, it perfoms DisableNodeCheckbox() on the DSL object back pointer
  3. Parses all DSL shapes, get the DSL object from the DSL shape and performs CheckNode() on the back pointer of the DSL object

Problem:

Step 2 of computeDSLNodesConfiguration seems overcomplicated

Alternative:

in step 2 of computeDSLNodesConfiguration()`,

  1. parses all DSL object node,
    for _, _node := range nodeCb.treeOfGongObjects.RootNodes {
        ...
    }
  1. get their implementation
  2. get the DSL object, computes if disabling he checkbox is necessay , performs DisableNodeCheckbox on the DSL object node

No need for back pointers anymore

One problem is that DSL object node are just nodes, getting DSL information requires getting info from the DSL node implementation

Steps:

for _, _node := range nodeCb.treeOfGongObjects.RootNodes {
        for _, _node := range _node.Children {
            for _, _node := range _node.Children {
                switch nodeImpl := _node.Impl.(type) {
                case *FieldImpl:
                    gongField := nodeImpl.field
                    switch fieldReal := gongField.(type) {
                    case *gong_models.PointerToGongStructField:
                        if ok := namesOfDisplayedGongstructs[fieldReal.GongStruct.Name]; !ok {
                            nodeImpl.DisableNodeCheckbox()
                        }
                    case *gong_models.SliceOfPointerToGongStructField:
                        if ok := namesOfDisplayedGongstructs[fieldReal.GongStruct.Name]; !ok {
                            nodeImpl.DisableNodeCheckbox()
                        }
                    default:
                    }
                case *GongEnumValueImpl:
                case *GongLinkImpl:
                default:
                    _ = nodeImpl
                    log.Panic("No known implementation")
                }
            }
        }
    }