nmodl icon indicating copy to clipboard operation
nmodl copied to clipboard

Indexed node with expression contains `Name` and not `VarName`

Open georgemitenkov opened this issue 5 years ago • 4 comments

While looking at IndexedName node, I noticed that the expression that is used as index created differently from a regular expression. Consider the following program:

PROCEDURE foo() {
    LOCAL x[4], i, j
    i = 0
    j = 1 + i
    x[2 + i] = 3
}

Comparing the AST generated for j = 1 + i and x[2 + i]:

{
                  "BinaryExpression": [
                    {
                      "VarName": [
                        {
                          "Name": [
                            {
                              "String": [
                                {
                                  "name": "j"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "BinaryOperator": [
                        {
                          "name": "="
                        }
                      ]
                    },
                    {
                      "WrappedExpression": [
                        {
                          "BinaryExpression": [
                            {
                              "Double": [
                                {
                                  "name": "1"
                                }
                              ]
                            },
                            {
                              "BinaryOperator": [
                                {
                                  "name": "+"
                                }
                              ]
                            },
                            {
                              "VarName": [
                                {
                                  "Name": [
                                    {
                                      "String": [
                                        {
                                          "name": "i"
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }

and

{
                          "IndexedName": [
                            {
                              "Name": [
                                {
                                  "String": [
                                    {
                                      "name": "x"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "WrappedExpression": [
                                {
                                  "BinaryExpression": [
                                    {
                                      "Integer": [
                                        {
                                          "name": "2"
                                        }
                                      ]
                                    },
                                    {
                                      "BinaryOperator": [
                                        {
                                          "name": "+"
                                        }
                                      ]
                                    },
                                    {
                                      "Name": [
                                        {
                                          "String": [
                                            {
                                              "name": "i"
                                            }
                                          ]
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }

Here, in indexed case, the binary operator has a Name and not VarName node. this creates an ambiguity for code generation.

georgemitenkov avatar Mar 08 '21 18:03 georgemitenkov

Maybe we should fix that in the parser level? @pramodk what do you think?

iomaganaris avatar Mar 11 '21 15:03 iomaganaris

I think this may not be only place where Name and VarName are used interchangeably. We can take a look next week.

pramodk avatar Mar 13 '21 17:03 pramodk

We should remove VarName at then and use Identifier (base class of all type).

alkino avatar Aug 29 '22 13:08 alkino

Related to #903

alkino avatar Sep 13 '22 12:09 alkino