Skip to content

Commit

Permalink
Merge pull request #259 from DimitriPlotnikov/master
Browse files Browse the repository at this point in the history
Improve stabilit of the symboltable infrastructure
  • Loading branch information
Plotnikov authored Sep 14, 2016
2 parents c0e83a2 + 2dcf3d7 commit 2a91740
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/main/java/org/nest/units/_visitor/UnitsSIVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import com.google.common.collect.Lists;
import de.se_rwth.commons.logging.Finding;
import de.se_rwth.commons.logging.Log;
import org.nest.commons._ast.ASTNESTMLNumericLiteral;
import org.nest.nestml._ast.ASTNESTMLNode;
import org.nest.nestml._visitor.NESTMLVisitor;
import org.nest.spl._ast.ASTSPLNode;
import org.nest.units._ast.ASTUnitType;
import org.nest.units.unitrepresentation.UnitRepresentation;
import org.nest.units.unitrepresentation.UnitTranslator;
import org.nest.utils.LogHelper;

Expand All @@ -25,7 +27,7 @@
* @author ptraeder
*/
public class UnitsSIVisitor implements NESTMLVisitor {
private final static String ERROR_CODE = "NESTML_" + UnitsSIVisitor.class.getName();
private final static String ERROR_CODE = "NESTML_UnitsSIVisitor";
private UnitTranslator translator = new UnitTranslator();

/**
Expand Down Expand Up @@ -90,4 +92,17 @@ public void visit(ASTUnitType astUnitType){

}

public void visit(ASTNESTMLNumericLiteral astNestmlNumericLiteral) {
if (astNestmlNumericLiteral.getType().isPresent()) {
final String unitName = astNestmlNumericLiteral.getType().get();
final Optional<UnitRepresentation> unit = UnitRepresentation.lookupName(unitName);
if (!unit.isPresent()) {
final String msg = ERROR_CODE + "The unit used in the '" + unitName + "' literal is not an SI unit.";
Log.error(msg, astNestmlNumericLiteral.get_SourcePositionStart());
}

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @author plotnikov, traeder
*/
public class UnitRepresentation {
private static final String LOG_NAME = "NESTML_UNIT_REPRESENTATION";
private int magnitude;
private int K, s, m, g, cd, mol, A;

Expand Down Expand Up @@ -213,7 +214,7 @@ static public Optional<UnitRepresentation> lookupName(String unit){
}
catch(Exception e){
//should never happen
Log.error("The unit: " + unit + " doesn't exist. At this stage it must be already checked by a context condition.");
Log.error(LOG_NAME + ": The unit: " + unit + " doesn't exist. At this stage it must be already checked by a context condition.");
return Optional.empty();
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/nest/nestml/_parser/NESTMLParserTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.nest.nestml._parser;

import de.se_rwth.commons.logging.Finding;
import de.se_rwth.commons.logging.Log;
import org.junit.Test;
import org.nest.base.ModelbasedTest;
Expand Down Expand Up @@ -95,6 +96,8 @@ public void testFasleArtifactHandling() throws IOException {
public void testNonExistentType() throws IOException {
final Optional<ASTNESTMLCompilationUnit> ast = parser.parse("src/test/resources/unparsable/wrongTypes.nestml");
assertFalse(ast.isPresent());
List<Finding> findings = LogHelper.getModelFindings(Log.getFindings());
assertEquals(4, findings.size()); // two error are reported twice due to the visitor structure
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/unparsable/wrongTypes.nestml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ neuron iaf_neuron_neuron:

# these parameter are adjusted from outside
parameter:
C_m pf = 250 pF [[C_m > 0 pF]] # ERROR: pf is wrong
Tau ms = 10 MS # ERROR: MS is wrong
C_m pf = 250 pF [[C_m > 0 pF]] # ERROR: pf is wrong
tau_syn ms = 2 ms # Time constant of synaptic current.
t_ref ms = 2 ms # Refractory period.
E_L mV = -70 mV # Resting potential.
Expand Down

0 comments on commit 2a91740

Please sign in to comment.