Skip to content

Commit

Permalink
More callback tody up
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Jan 16, 2019
1 parent a201d4b commit 51e12f5
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 249 deletions.
Expand Up @@ -20,11 +20,14 @@
import org.overture.parser.syntax.ExpressionReader;
import org.overture.parser.syntax.ModuleReader;
import org.overture.parser.syntax.StatementReader;
import org.overture.parser.syntax.SyntaxReader;

public interface ASTAnnotation
{
public void astBefore(SyntaxReader reader);
public void astBefore(DefinitionReader reader);
public void astBefore(StatementReader reader);
public void astBefore(ExpressionReader reader);
public void astBefore(ModuleReader reader);
public void astBefore(ClassReader reader);

public void astAfter(DefinitionReader reader, PDefinition def);
public void astAfter(StatementReader reader, PStm stmt);
Expand Down
Expand Up @@ -801,19 +801,46 @@ protected ILexCommentList getComments()
return reader.getComments();
}

/**
* Annotation processing...
*/
protected void beforeAnnotations(SyntaxReader reader, List<PAnnotation> annotations)
{
for (PAnnotation annotation: annotations)
{
if (annotation.getImpl() instanceof ASTAnnotation)
{
ASTAnnotation impl = (ASTAnnotation)annotation.getImpl();
impl.astBefore(reader);

// This is not as ugly as multiple overloaded beforeAnotation and beforeAnnotations!
if (reader instanceof DefinitionReader)
{
impl.astBefore((DefinitionReader)reader);
}
else if (reader instanceof ExpressionReader)
{
impl.astBefore((ExpressionReader)reader);
}
else if (reader instanceof StatementReader)
{
impl.astBefore((StatementReader)reader);
}
else if (reader instanceof ModuleReader)
{
impl.astBefore((ModuleReader)reader);
}
else if (reader instanceof ClassReader)
{
impl.astBefore((ClassReader)reader);
}
else
{
System.err.println("Cannot apply annoation to " + reader.getClass().getSimpleName());
}
}
}
}


protected void afterAnnotations(DefinitionReader reader, List<PAnnotation> annotations, PDefinition def)
{
for (PAnnotation annotation: annotations)
Expand Down
Expand Up @@ -10,13 +10,16 @@

package org.overture.pog.visitors;

import java.util.List;

import org.overture.ast.analysis.AnalysisException;
import org.overture.ast.analysis.QuestionAnswerAdaptor;
import org.overture.ast.annotations.PAnnotation;
import org.overture.ast.definitions.PDefinition;
import org.overture.ast.definitions.SClassDefinition;
import org.overture.ast.expressions.PExp;
import org.overture.ast.modules.AModuleModules;
import org.overture.ast.node.INode;
import org.overture.ast.statements.PStm;
import org.overture.pog.annotations.POAnnotation;
import org.overture.pog.obligation.ProofObligationList;
Expand All @@ -31,198 +34,101 @@ public abstract class AbstractPogParamVisitor extends QuestionAnswerAdaptor<IPOC
/**
* Process annotations.
*/
protected IProofObligationList beforeAnnotation(PAnnotation annotation, PDefinition node, IPOContextStack question)
protected IProofObligationList beforeAnnotation(PAnnotation annotation, INode node, IPOContextStack question)
throws AnalysisException
{
IProofObligationList list = new ProofObligationList();

if (annotation.getImpl() instanceof POAnnotation)
{
POAnnotation impl = (POAnnotation)annotation.getImpl();
list.addAll(impl.poBefore(node, question));

// This is not as ugly as multiple overloaded beforeAnotation and beforeAnnotations!
if (node instanceof PDefinition)
{
impl.poBefore((PDefinition)node, question);
}
else if (node instanceof PExp)
{
impl.poBefore((PExp)node, question);
}
else if (node instanceof PStm)
{
impl.poBefore((PStm)node, question);
}
else if (node instanceof AModuleModules)
{
impl.poBefore((AModuleModules)node, question);
}
else if (node instanceof SClassDefinition)
{
impl.poBefore((SClassDefinition)node, question);
}
else
{
System.err.println("Cannot apply annoation to " + node.getClass().getSimpleName());
}
}

return list;
}

protected IProofObligationList beforeAnnotation(PAnnotation annotation, PExp node, IPOContextStack question)
throws AnalysisException
{
IProofObligationList list = new ProofObligationList();

if (annotation.getImpl() instanceof POAnnotation)
{
POAnnotation impl = (POAnnotation)annotation.getImpl();
list.addAll(impl.poBefore(node, question));
}

return list;
}

protected IProofObligationList beforeAnnotation(PAnnotation annotation, PStm node, IPOContextStack question)
throws AnalysisException
{
IProofObligationList list = new ProofObligationList();

if (annotation.getImpl() instanceof POAnnotation)
{
POAnnotation impl = (POAnnotation)annotation.getImpl();
list.addAll(impl.poBefore(node, question));
}

return list;
}

protected IProofObligationList beforeAnnotation(PAnnotation annotation, AModuleModules node, IPOContextStack question)
throws AnalysisException
{
IProofObligationList list = new ProofObligationList();

if (annotation.getImpl() instanceof POAnnotation)
{
POAnnotation impl = (POAnnotation)annotation.getImpl();
list.addAll(impl.poBefore(node, question));
}

return list;
}

protected IProofObligationList beforeAnnotation(PAnnotation annotation, SClassDefinition node, IPOContextStack question)
throws AnalysisException
{
IProofObligationList list = new ProofObligationList();

if (annotation.getImpl() instanceof POAnnotation)
{
POAnnotation impl = (POAnnotation)annotation.getImpl();
list.addAll(impl.poBefore(node, question));
}

return list;
}

protected IProofObligationList afterAnnotation(PAnnotation annotation, PDefinition node, IProofObligationList list, IPOContextStack question)
throws AnalysisException
{
if (annotation.getImpl() instanceof POAnnotation)
{
POAnnotation impl = (POAnnotation)annotation.getImpl();
impl.poAfter(node, list, question);
}

return list;
}

protected IProofObligationList afterAnnotation(PAnnotation annotation, PExp node, IProofObligationList list, IPOContextStack question)
throws AnalysisException
{
if (annotation.getImpl() instanceof POAnnotation)
{
POAnnotation impl = (POAnnotation)annotation.getImpl();
impl.poAfter(node, list, question);
}

return list;
}

protected IProofObligationList afterAnnotation(PAnnotation annotation, PStm node, IProofObligationList list, IPOContextStack question)
protected IProofObligationList afterAnnotation(PAnnotation annotation, INode node, IProofObligationList list, IPOContextStack question)
throws AnalysisException
{
if (annotation.getImpl() instanceof POAnnotation)
{
POAnnotation impl = (POAnnotation)annotation.getImpl();
impl.poAfter(node, list, question);

// This is not as ugly as multiple overloaded beforeAnotation and beforeAnnotations!
if (node instanceof PDefinition)
{
impl.poAfter((PDefinition)node, list, question);
}
else if (node instanceof PExp)
{
impl.poAfter((PExp)node, list, question);
}
else if (node instanceof PStm)
{
impl.poAfter((PStm)node, list, question);
}
else if (node instanceof AModuleModules)
{
impl.poAfter((AModuleModules)node, list, question);
}
else if (node instanceof SClassDefinition)
{
impl.poAfter((SClassDefinition)node, list, question);
}
else
{
System.err.println("Cannot apply annoation to " + node.getClass().getSimpleName());
}
}

return list;
}

protected IProofObligationList afterAnnotation(PAnnotation annotation, AModuleModules node, IProofObligationList list, IPOContextStack question)
throws AnalysisException
{
if (annotation.getImpl() instanceof POAnnotation)
{
POAnnotation impl = (POAnnotation)annotation.getImpl();
impl.poAfter(node, list, question);
}

return list;
}

protected IProofObligationList afterAnnotation(PAnnotation annotation, SClassDefinition node, IProofObligationList list, IPOContextStack question)
throws AnalysisException
{
if (annotation.getImpl() instanceof POAnnotation)
{
POAnnotation impl = (POAnnotation)annotation.getImpl();
impl.poAfter(node, list, question);
}

return list;
}

/**
* Methods for applying before/after a list of annotations
*/
protected IProofObligationList beforeAnnotations(PDefinition node, IPOContextStack question) throws AnalysisException
{
IProofObligationList list = new ProofObligationList();

for (PAnnotation annotation: node.getAnnotations())
{
list.addAll(beforeAnnotation(annotation, node, question));
}

return list;
}

protected IProofObligationList afterAnnotations(PDefinition node, IProofObligationList list, IPOContextStack question) throws AnalysisException
{
for (PAnnotation annotation: node.getAnnotations())
{
afterAnnotation(annotation, node, list, question);
}

return list;
}

protected IProofObligationList beforeAnnotations(AModuleModules node, IPOContextStack question) throws AnalysisException
{
IProofObligationList list = new ProofObligationList();

for (PAnnotation annotation: node.getAnnotations())
{
list.addAll(beforeAnnotation(annotation, node, question));
}

return list;
}

protected IProofObligationList afterAnnotations(AModuleModules node, IProofObligationList list, IPOContextStack question) throws AnalysisException
{
for (PAnnotation annotation: node.getAnnotations())
{
afterAnnotation(annotation, node, list, question);
}

return list;
}

protected IProofObligationList beforeAnnotations(SClassDefinition node, IPOContextStack question) throws AnalysisException
protected IProofObligationList beforeAnnotations(List<PAnnotation> annotations, INode node, IPOContextStack question) throws AnalysisException
{
IProofObligationList list = new ProofObligationList();

for (PAnnotation annotation: node.getAnnotations())
for (PAnnotation annotation: annotations)
{
list.addAll(beforeAnnotation(annotation, node, question));
}

return list;
}

protected IProofObligationList afterAnnotations(SClassDefinition node, IProofObligationList list, IPOContextStack question) throws AnalysisException
protected IProofObligationList afterAnnotations(List<PAnnotation> annotations, INode node, IProofObligationList list, IPOContextStack question) throws AnalysisException
{
for (PAnnotation annotation: node.getAnnotations())
for (PAnnotation annotation: annotations)
{
afterAnnotation(annotation, node, list, question);
}
Expand Down

0 comments on commit 51e12f5

Please sign in to comment.