How to show an error in the Xtext IDE if a type is referenced before it is declared

Vivit

We have a custom Xtext-based DSL and generate C++ code from a document written in this DSL via Xtend. Here is a simple example of the DSL:

component CMP
{
    type A
    {
       B member_1;
    }

    type B
    {
        string member_1;
    }
}

Eventually, a header file containing C++ structs (based on type elements) is generated for every component element. Now the following problem occurs: In my DSL A and B can be correctly resolved (even though B is declared later than A). But when we generate C++ code and do something like resource.contents.filter(TypeElement) to iterate through all type elements, they are delivered in the same order as declared in the document. This leads to compiler errors for the resulting C++ header, because B is declared later than A and cannot be resolved by the compiler without a forward declaration.

What I want is to show an error in the IDE in such a case (i.e. if a reference exists to a type which occurs later in the document). Is there some kind of standard validator for such scenarios? If not, what would be the most proper way to deal with this issue?

Thank you in advance!

Sebastian Zarnekow

There is no standard validator for forward references. You'd need to define one one your own based on the values of your cross reference targets. Inject the ILocationInFileProvider into your validator to obtain the region of the referenced instance and compare it with the region of the reference owner. That will do the trick to detect forward references.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

variable 'error' referenced before assignmentRequest

From Dev

Not an error to use a variable before it is declared?

From Dev

Not an error to use a variable before it is declared?

From Dev

how to fix a simple error on xtext?

From Dev

UnboundLocalError: local variable 'error' referenced before assignment

From Dev

Error: Local variable referenced before assignment

From Dev

Python Bizarre Error - Variable Referenced Before Assignment

From Dev

local variable referenced before assignment django error

From Dev

Action has no declared type error

From Dev

Does not name type and was not declared error

From Dev

XText formatting rule for referenced elements

From Dev

Variable Referenced before Assignment Error - How to use variables across multiple functions?

From Dev

Variable Referenced before Assignment Error - How to use variables across multiple functions?

From Dev

XSD Error: Type is not declared, or is not a simple type

From Dev

The entity "nbsp" was referenced, but not declared

From Dev

How can Applescript objects be referenced before they are defined?

From Dev

How to get declared type with mirrors?

From Dev

Scala type error for cyclically referenced traits

From Dev

Error: Initializers may only be declared within a type

From Dev

ERROR: return type mismatch in function declared to return

From Dev

ERROR: return type mismatch in function declared to return

From Dev

Implicit type compilation error although declared

From Dev

Typescript string prototype show error in webstorm IDE

From Dev

Typescript string prototype show error in webstorm IDE

From Dev

Error Parsing /page.xhtml: Error Traced[line: 45] The entity "laquo" was referenced, but not declared

From Dev

Why should lifetime parameters be declared before type parameters?

From Dev

Xtext - Get cross-referenced child

From Dev

Xtext - Get cross-referenced child

From Dev

Solving error: local variable 'counter' referenced before assignment

Related Related

  1. 1

    variable 'error' referenced before assignmentRequest

  2. 2

    Not an error to use a variable before it is declared?

  3. 3

    Not an error to use a variable before it is declared?

  4. 4

    how to fix a simple error on xtext?

  5. 5

    UnboundLocalError: local variable 'error' referenced before assignment

  6. 6

    Error: Local variable referenced before assignment

  7. 7

    Python Bizarre Error - Variable Referenced Before Assignment

  8. 8

    local variable referenced before assignment django error

  9. 9

    Action has no declared type error

  10. 10

    Does not name type and was not declared error

  11. 11

    XText formatting rule for referenced elements

  12. 12

    Variable Referenced before Assignment Error - How to use variables across multiple functions?

  13. 13

    Variable Referenced before Assignment Error - How to use variables across multiple functions?

  14. 14

    XSD Error: Type is not declared, or is not a simple type

  15. 15

    The entity "nbsp" was referenced, but not declared

  16. 16

    How can Applescript objects be referenced before they are defined?

  17. 17

    How to get declared type with mirrors?

  18. 18

    Scala type error for cyclically referenced traits

  19. 19

    Error: Initializers may only be declared within a type

  20. 20

    ERROR: return type mismatch in function declared to return

  21. 21

    ERROR: return type mismatch in function declared to return

  22. 22

    Implicit type compilation error although declared

  23. 23

    Typescript string prototype show error in webstorm IDE

  24. 24

    Typescript string prototype show error in webstorm IDE

  25. 25

    Error Parsing /page.xhtml: Error Traced[line: 45] The entity "laquo" was referenced, but not declared

  26. 26

    Why should lifetime parameters be declared before type parameters?

  27. 27

    Xtext - Get cross-referenced child

  28. 28

    Xtext - Get cross-referenced child

  29. 29

    Solving error: local variable 'counter' referenced before assignment

HotTag

Archive