Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Validating unused declarations(Xtext Validation)
Validating unused declarations [message #872422] Wed, 16 May 2012 05:12 Go to next message
Brad Riching is currently offline Brad RichingFriend
Messages: 20
Registered: May 2012
Junior Member
Greetings eclipse-xtext world,

I am implementing a new hardware description language in Xtext that describes the PCB capture process. However, I have run into a problem with validating unused variable declarations, in my case when I declare a net. I need to be able to count the number of references to a declaration in my DSL model which refer to the declaration and issue an error if there are fewer than two. The reason is, if there are fewer than two device pins connected to a net, that net is actually unused and constitutes a design problem.

The simplified relevant grammar rules follow:

DesignDecl: 'design' name=ID '{' decls+=ConnectionDecl* devInsts+=DeviceInst* '}';

ConnectionDecl: 'net' names+=ConnectionName (',' names+=ConnectionName)* ';';

ConnectionName: name=ID;

DeviceInst: 'inst' name=ID 'of' device=[DeviceDecl | QualifiedName] '{' pins+=PinAssign* '}';

PinAssign: name=[PinDecl] '=' concatenation=Concatenation ';';

Concatenation: connections+=ConnectionRef ('&' connections+=ConnectionRef)*;

ConnectionRef: name=[ConnectionName];


My scoping is properly set up, and all appropriate references are resolved.

In my validator, I have the following method:
@Check
public void checkUnusedConnectionDecls(ConnectionDecl c) {
	for (ConnectionName n : c.getNames()) {
		if (n.eCrossReferences().size() < 2) {
			EStructuralFeature f = PhdlPackage.Literals.CONNECTION_NAME__NAME;
			error("Unconnected net.", n, f, c.getNames().indexOf(n));
		}
	}
}


I would like to throw errors with this DSL code:
design top {
	net a;
	
	inst d_inst of d {
		p1 = a;
	}
}


But not this code:
design top {
	net a;
	
	inst d_inst1 of d {
		p1 = a;
	}

	inst d_inst2 of d {
		p1 = a;
	}
}


because both instances of d's pin 1 (p1) are electrically connected by net a. Therefore, there are two references inside the instances that refer to net a.

The problem is, n.eCrossReferences() always comes up empty, no matter how many cross references there are to it. Does anyone know if Xtext supports this kind of functionality?

This is a similar problem to unused variable declaration warnings in conventional programming languages, but in this case I would like to throw an error in the editor if there are fewer than two references to the declaration which would cause an unconnected net in the PCB layout.

I have another solution that iterates over all connections in all instances of a design and creates a running tally to the references in a Map. I then query the map by iterating over all connection declarations to see how many refer to each one. However, this is a huge kluge in my opinion, and I would be grateful if anyone knows how to solve this with a much more simplified validator method like I started above. Any ideas are welcome. Thanks in advance!

Brad

[Updated on: Wed, 16 May 2012 05:29]

Report message to a moderator

Re: Validating unused declarations [message #872693 is a reply to message #872422] Wed, 16 May 2012 15:57 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Take a look at the Linker's #afterModelLinked - that is probably where
you want to perform checks that involves links.

Not sure about the details for eCrossReferences, but the references
generated by links are not bi-directional. Also guess that all links
would need to be resolved in order for this to work correctly. Hence, I
think the best is to scan the index for references descriptions (the
list is available, and does not require all resources to be loaded).

Hope that helps.
- henrik

On 2012-16-05 7:12, Brad Riching wrote:
> Greetings eclipse-xtext world,
>
> I am implementing a new hardware description language in Xtext that
> describes the PCB capture process. However, I have run into a problem
> with validating unused variable declarations, in my case when I declare
> a net. I need to be able to count the number of references to a
> declaration in my DSL model which refer to the declaration and issue an
> error if there are fewer than two. The reason is, if there are fewer
> than two device pins connected to a net, that net is actually unused and
> constitutes a design problem.
>
> The simplified relevant grammar rules follow:
>
>
> DesignDecl: 'design' name=ID '{' decls+=ConnectionDecl*
> devInsts+=DeviceInst* '}';
>
> ConnectionDecl: 'net' names+=ConnectionName (',' names+=ConnectionName)*;
>
> ConnectionName: name=ID;
>
> DeviceInst: 'inst' name=ID 'of' device=[DeviceDecl | QualifiedName] '{'
> pins+=PinAssign* '}';
>
> PinAssign: name=[PinDecl] '=' concatenation=Concatenation ';';
>
> Concatenation: connections+=ConnectionRef ('&'
> connections+=ConnectionRef)*;
>
> ConnectionRef: name=[ConnectionName];
>
>
> My scoping is properly set up, and all appropriate references are resolved.
>
> In my validator, I have the following method:
>
> @Check
> public void checkUnusedConnectionDecls(ConnectionDecl c) {
> for (ConnectionName n : c.getNames()) {
> if (n.eCrossReferences().size() < 2) {
> EStructuralFeature f = PhdlPackage.Literals.CONNECTION_NAME__NAME;
> error("Unconnected net.", n, f, c.getNames().indexOf(n));
> }
> }
> }
>
>
> I would like to throw errors with this DSL code:
>
> design top {
> net a;
>
> inst d_inst of d {
> p1 = a;
> }
> }
>
>
> But not this code:
>
> design top {
> net a;
>
> inst d_inst1 of d {
> p1 = a;
> }
>
> inst d_inst2 of d {
> p1 = a;
> }
> }
>
>
> because both instances of d's pin 1 (p1) are electrically connected by
> net a. Therefore, there are two references inside the instances that
> refer to net a.
>
> The problem is, n.eCrossReferences() always comes up empty, no matter
> how many cross references there are to it. Does anyone know if Xtext
> supports this kind of functionality?
> This is a similar problem to unused variable declaration warnings in
> conventional programming languages, but in this case I would like to
> throw an error in the editor if there are fewer than two references to
> the declaration which would cause an unconnected net in the PCB layout.
>
> I have another solution that iterates over all connections in all
> instances of a design and creates a running tally to the references in a
> Map. I then query the map by iterating over all connection declarations
> to see how many refer to each one. However, this is a huge cluge in my
> opinion, and I would be grateful if anyone knows how to solve this with
> a much more simplified validator method like I started above. Any ideas
> are welcome. Thanks in advance!
>
> Brad
Previous Topic:two grammar rules should be independent
Next Topic:Spell checking for Strings
Goto Forum:
  


Current Time: Sat Dec 05 00:22:17 GMT 2020

Powered by FUDForum. Page generated in 0.01981 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top