/**
*
* OOAS Compiler (Deprecated)
*
* Copyright 2015, Institute for Software Technology, Graz University of
* Technology. Portions are copyright 2015 by the AIT Austrian Institute
* of Technology. All rights reserved.
*
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
*
* Please notice that this version of the OOAS compiler is considered de-
* precated. Only the Java version is maintained.
*
* Contributors:
* Willibald Krenn (TU Graz/AIT)
* Stefan Tiran (TU Graz/AIT)
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace TUG.Mogentes
{
///
/// This visitor scans all methods and decides whether they are pure, i.e. there is no state-update.
///
public sealed class OoaMethodPureClassifierVisitor : OoaCompleteAstTraversalVisitor
{
Stack currentMethod = new Stack();
public override void visit(MethodIdentifier methodIdentifier)
{
currentMethod.Push( methodIdentifier);
((FunctionType)currentMethod.Peek().type).SetIsPureFunction(true); // assume is true..
base.visit(currentMethod.Peek());
if (((FunctionType)currentMethod.Peek().type).isPureFunction)
{
m_ParserState.AddMessage(
new ParserMessage(m_ParserState.filename, methodIdentifier.line,
methodIdentifier.column, String.Format("Found pure method: {0}",
methodIdentifier.tokenText)));
} else
m_ParserState.AddMessage( new ParserMessage(m_ParserState.filename, methodIdentifier.line,
methodIdentifier.column, String.Format("Found extended method: {0}",
methodIdentifier.tokenText)));
currentMethod.Pop();
}
public override void visit(OoActionSystemType systemType)
{
bool functionPure = false; //introduce variable with save value
if (currentMethod.Count > 0 && currentMethod.Peek() != null) //if we are determining the pureness...
{
functionPure = ((FunctionType)currentMethod.Peek().type).isPureFunction; //...save the current value
}
base.visit(systemType); // go down in recursion
if ( currentMethod.Count > 0 && currentMethod.Peek() != null) //but restore old pureness!
{
((FunctionType)currentMethod.Peek().type).SetIsPureFunction(functionPure);
}
}
public override void visit(Assignment assignment)
{
bool assignmentPure = true;
if (currentMethod.Count > 0 && currentMethod.Peek() != null)
{
foreach (var x in assignment.places)
{
if (x.kind != ExpressionKind.Identifier)
assignmentPure = false;
else if (((IdentifierExpression)x).identifier.kind == IdentifierKind.AttributeIdentifier)
assignmentPure = false;
}
bool functionPure = assignmentPure && ((FunctionType)currentMethod.Peek().type).isPureFunction;
((FunctionType)currentMethod.Peek().type).SetIsPureFunction(functionPure);
}
base.visit(assignment);
}
public OoaMethodPureClassifierVisitor(ParserState aState)
: base(aState)
{ }
}
}