Skip to content

Commit

Permalink
Cleanup @warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Jan 13, 2024
1 parent 3adc3b0 commit 583c449
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
50 changes: 24 additions & 26 deletions annotations/src/main/java/annotations/tc/TCWarningAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

package annotations.tc;

import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
Expand All @@ -41,13 +40,15 @@
import com.fujitsu.vdmj.tc.statements.TCStatement;
import com.fujitsu.vdmj.tc.types.TCType;
import com.fujitsu.vdmj.typechecker.Environment;
import com.fujitsu.vdmj.typechecker.ModuleEnvironment;
import com.fujitsu.vdmj.typechecker.NameScope;
import com.fujitsu.vdmj.typechecker.TypeChecker;

public class TCWarningAnnotation extends TCAnnotation
{
private static final long serialVersionUID = 1L;
private int warningCount = 0;
private String moduleName = null;
private Set<Long> suppressed;

public TCWarningAnnotation(TCIdentifierToken name, TCExpressionList args)
Expand All @@ -56,32 +57,37 @@ public TCWarningAnnotation(TCIdentifierToken name, TCExpressionList args)
}

@Override
public void tcBefore(TCDefinition def, Environment env, NameScope scope)
public void tcBefore(TCModule module, ModuleEnvironment e)
{
moduleName = module.name.getName();
preCheck();
}

@Override
public void tcBefore(TCModule module)
public void tcBefore(TCClassDefinition clazz)
{
moduleName = clazz.name.getName();
preCheck();
}

@Override
public void tcBefore(TCClassDefinition clazz)
public void tcBefore(TCDefinition def, Environment env, NameScope scope)
{
warningCount = TypeChecker.getWarningCount();
preCheck();
}

@Override
public void tcBefore(TCExpression exp, Environment env, NameScope scope)
{
warningCount = TypeChecker.getWarningCount();
preCheck();
}

@Override
public void tcBefore(TCStatement stmt, Environment env, NameScope scope)
{
warningCount = TypeChecker.getWarningCount();
preCheck();
}

Expand All @@ -92,7 +98,6 @@ private void preCheck()
name.report(6010, "@Warning must have one or more numeric arguments");
}

warningCount = TypeChecker.getWarningCount();
suppressed = new HashSet<Long>();

for (TCExpression arg: args)
Expand Down Expand Up @@ -121,6 +126,12 @@ public void tcAfter(TCModule module)
postCheck();
}

@Override
public void tcAfter(TCModule module, ModuleEnvironment e)
{
postCheck();
}

@Override
public void tcAfter(TCExpression exp, TCType type, Environment env, NameScope scope)
{
Expand All @@ -143,38 +154,25 @@ private void postCheck()
{
Iterator<VDMWarning> witer = TypeChecker.getWarnings().iterator();

for (int i=0; i < warningCount; i++)
if (moduleName == null)
{
witer.next(); // skip previous warnings
for (int i=0; i < warningCount; i++)
{
witer.next(); // skip previous warnings
}
}

while (witer.hasNext())
{
VDMWarning w = witer.next();

if (suppressed.contains((long)w.number))
if (moduleName != null && !w.location.module.equals(moduleName))
{
witer.remove();
continue;
}
}
}

@Override
public void doClose()
{
Iterator<VDMWarning> witer = TypeChecker.getWarnings().iterator();
int myLine = name.getLocation().startLine;
File myFile = name.getLocation().file;

while (witer.hasNext())
{
VDMWarning w = witer.next();

if (w.location.startLine == myLine + 1 &&
w.location.file.equals(myFile) &&
suppressed.contains((long)w.number))
if (suppressed.contains((long)w.number))
{
// Warning is on the line after the one we annotated, so remove it
witer.remove();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void tcAfter(TCModule m, ModuleEnvironment e)
{
for (TCAnnotation annotation: this)
{
annotation.tcAfter(m);
annotation.tcAfter(m, e);
}
}

Expand Down

0 comments on commit 583c449

Please sign in to comment.