Revision 9
Added by Willibald K. over 9 years ago
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/expressions/QValConstructor.java | ||
---|---|---|
/**
|
||
*
|
||
* OOAS Compiler
|
||
*
|
||
* Copyright 2015, AIT Austrian Institute of Technology.
|
||
* This code is based on the C# Version of the OOAS Compiler, which is
|
||
* copyright 2015 by the Institute of Software Technology, Graz University
|
||
* of Technology with portions copyright by the AIT Austrian Institute of
|
||
* Technology. All rights reserved.
|
||
*
|
||
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
||
*
|
||
* If you modify the file please update the list of contributors below to in-
|
||
* clude your name. Please also stick to the coding convention of using TABs
|
||
* to do the basic (block-level) indentation and spaces for anything after
|
||
* that. (Enable the display of special chars and it should be pretty obvious
|
||
* what this means.) Also, remove all trailing whitespace.
|
||
*
|
||
* Contributors:
|
||
* Willibald Krenn (AIT)
|
||
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
*
|
||
*/
|
||
|
||
|
||
package org.momut.ooas.ast.expressions;
|
||
|
||
import java.util.Arrays;
|
||
|
||
import org.momut.ooas.ast.IAstVisitor;
|
||
|
||
///////////////////////////////////////////////
|
||
/// Constructor: Qualitative Value
|
||
///
|
||
public final class QValConstructor extends TypeConstructionExpression
|
||
{
|
||
public enum QValDeriv { DonTCare, Dec, Steady, Inc }
|
||
|
||
private Expression[] m_value;
|
||
private QValDeriv m_derivValue;
|
||
|
||
public Expression[] value() { return m_value; }
|
||
public QValDeriv valueDeriv() { return m_derivValue; }
|
||
|
||
|
||
public QValConstructor(int line, int pos)
|
||
{
|
||
super (ExpressionKind.QValConstr, line, pos);
|
||
m_value = new Expression[1];
|
||
m_value[0] = null;
|
||
m_derivValue = QValDeriv.DonTCare;
|
||
}
|
||
|
||
public QValConstructor(QValConstructor toCopy)
|
||
{
|
||
super (toCopy);
|
||
m_value = Arrays.copyOf(toCopy.m_value, toCopy.m_value.length);
|
||
m_derivValue = toCopy.m_derivValue;
|
||
}
|
||
|
||
@Override
|
||
public /*override*/ Expression Clone()
|
||
{
|
||
return new QValConstructor(this);
|
||
}
|
||
|
||
|
||
public /*override*/ void Accept(IAstVisitor visitor)
|
||
{
|
||
visitor.visit(this);
|
||
}
|
||
|
||
public void SetValue(Expression aval)
|
||
{
|
||
m_value[0] = aval;
|
||
}
|
||
|
||
public void AddRange(Expression toRange)
|
||
{
|
||
Expression currVal = m_value[0];
|
||
m_value = new Expression[2];
|
||
m_value[0] = currVal;
|
||
m_value[1] = toRange;
|
||
}
|
||
|
||
public void SetDerivation(QValDeriv newValue)
|
||
{
|
||
m_derivValue = newValue;
|
||
}
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/identifiers/LandmarkIdentifier.java | ||
---|---|---|
/**
|
||
*
|
||
* OOAS Compiler
|
||
*
|
||
* Copyright 2015, AIT Austrian Institute of Technology.
|
||
* This code is based on the C# Version of the OOAS Compiler, which is
|
||
* copyright 2015 by the Institute of Software Technology, Graz University
|
||
* of Technology with portions copyright by the AIT Austrian Institute of
|
||
* Technology. All rights reserved.
|
||
*
|
||
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
||
*
|
||
* If you modify the file please update the list of contributors below to in-
|
||
* clude your name. Please also stick to the coding convention of using TABs
|
||
* to do the basic (block-level) indentation and spaces for anything after
|
||
* that. (Enable the display of special chars and it should be pretty obvious
|
||
* what this means.) Also, remove all trailing whitespace.
|
||
*
|
||
* Contributors:
|
||
* Willibald Krenn (AIT)
|
||
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
*
|
||
*/
|
||
|
||
|
||
package org.momut.ooas.ast.identifiers;
|
||
|
||
import org.antlr.runtime.Token;
|
||
import org.momut.ooas.ast.IAstVisitor;
|
||
import org.momut.ooas.ast.IScope;
|
||
import org.momut.ooas.ast.types.QrType;
|
||
|
||
public final class LandmarkIdentifier extends ValueIdentifier
|
||
{
|
||
public LandmarkIdentifier(Token aToken,
|
||
QrType aType,
|
||
IScope aDefiningScope)
|
||
{
|
||
super(aToken, aType, IdentifierKind.LandmarkIdentifier, aDefiningScope);
|
||
}
|
||
|
||
public LandmarkIdentifier(LandmarkIdentifier toCopy)
|
||
{
|
||
super(toCopy);
|
||
}
|
||
|
||
@Override
|
||
public /*override*/ Identifier Clone()
|
||
{
|
||
return this;
|
||
}
|
||
|
||
@Override
|
||
public /*override*/ void Accept(IAstVisitor visitor)
|
||
{
|
||
visitor.visit(this);
|
||
}
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/statements/QualitativeConstraintStatement.java | ||
---|---|---|
/**
|
||
*
|
||
* OOAS Compiler
|
||
*
|
||
* Copyright 2015, AIT Austrian Institute of Technology.
|
||
* This code is based on the C# Version of the OOAS Compiler, which is
|
||
* copyright 2015 by the Institute of Software Technology, Graz University
|
||
* of Technology with portions copyright by the AIT Austrian Institute of
|
||
* Technology. All rights reserved.
|
||
*
|
||
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
||
*
|
||
* If you modify the file please update the list of contributors below to in-
|
||
* clude your name. Please also stick to the coding convention of using TABs
|
||
* to do the basic (block-level) indentation and spaces for anything after
|
||
* that. (Enable the display of special chars and it should be pretty obvious
|
||
* what this means.) Also, remove all trailing whitespace.
|
||
*
|
||
* Contributors:
|
||
* Willibald Krenn (AIT)
|
||
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
*
|
||
*/
|
||
|
||
|
||
package org.momut.ooas.ast.statements;
|
||
|
||
import org.momut.ooas.ast.IAstVisitor;
|
||
import org.momut.ooas.ast.identifiers.Identifier;
|
||
import org.momut.ooas.utils.exceptions.ArgumentException;
|
||
|
||
///////////////////////////////////////////////
|
||
/// Qualitative Constraints
|
||
///
|
||
public final class QualitativeConstraintStatement extends Statement
|
||
{
|
||
public enum QualitativeConstraintOperation { Equal, Deriv, Sum, Prod, Diff }
|
||
|
||
private Identifier m_variable0;
|
||
private Identifier m_variable1;
|
||
private Identifier m_variable2;
|
||
private final QualitativeConstraintOperation m_operation;
|
||
public boolean tag = false; // says that this is an obs assignment (important for prolog code target)
|
||
|
||
public Identifier variable0() { return m_variable0; }
|
||
public Identifier variable1() { return m_variable1; }
|
||
public Identifier variable2() { return m_variable2; }
|
||
public QualitativeConstraintOperation operation() { return m_operation; }
|
||
|
||
public QualitativeConstraintStatement(Identifier var0, Identifier var1, QualitativeConstraintOperation op, int aline, int apos)
|
||
{
|
||
super (StatementKind.QualConstraint, aline, apos);
|
||
if (op == QualitativeConstraintOperation.Diff
|
||
|| op == QualitativeConstraintOperation.Prod
|
||
|| op == QualitativeConstraintOperation.Sum)
|
||
throw new ArgumentException();
|
||
m_variable0 = var0;
|
||
m_variable1 = var1;
|
||
m_variable2 = null;
|
||
m_operation = op;
|
||
}
|
||
|
||
public QualitativeConstraintStatement(QualitativeConstraintStatement toCopy)
|
||
{
|
||
super (toCopy);
|
||
m_variable0 = toCopy.m_variable0;
|
||
m_variable1 = toCopy.m_variable1;
|
||
m_variable2 = toCopy.m_variable2;
|
||
m_operation = toCopy.m_operation;
|
||
tag = toCopy.tag;
|
||
}
|
||
|
||
|
||
public QualitativeConstraintStatement(Identifier var0, Identifier var1, Identifier var2, QualitativeConstraintOperation op, int aline, int apos)
|
||
{
|
||
super (StatementKind.QualConstraint, aline, apos);
|
||
if (op == QualitativeConstraintOperation.Deriv
|
||
|| op == QualitativeConstraintOperation.Equal)
|
||
throw new ArgumentException();
|
||
m_variable0 = var0;
|
||
m_variable1 = var1;
|
||
m_variable2 = var2;
|
||
m_operation = op;
|
||
}
|
||
|
||
@Override
|
||
public /*override*/ void Accept(IAstVisitor visitor)
|
||
{
|
||
visitor.visit(this);
|
||
}
|
||
|
||
@Override
|
||
public /*override*/ Statement Clone()
|
||
{
|
||
return new QualitativeConstraintStatement(this);
|
||
}
|
||
|
||
public void SetVariable0(Identifier newVal)
|
||
{
|
||
m_variable0 = newVal;
|
||
}
|
||
|
||
public void SetVariable1(Identifier newVal)
|
||
{
|
||
m_variable1 = newVal;
|
||
}
|
||
|
||
public void SetVariable2(Identifier newVal)
|
||
{
|
||
m_variable2 = newVal;
|
||
}
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/types/UlyssesType.java | ||
---|---|---|
/**
|
||
*
|
||
* OOAS Compiler
|
||
*
|
||
* Copyright 2015, AIT Austrian Institute of Technology.
|
||
* This code is based on the C# Version of the OOAS Compiler, which is
|
||
* copyright 2015 by the Institute of Software Technology, Graz University
|
||
* of Technology with portions copyright by the AIT Austrian Institute of
|
||
* Technology. All rights reserved.
|
||
*
|
||
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
||
*
|
||
* If you modify the file please update the list of contributors below to in-
|
||
* clude your name. Please also stick to the coding convention of using TABs
|
||
* to do the basic (block-level) indentation and spaces for anything after
|
||
* that. (Enable the display of special chars and it should be pretty obvious
|
||
* what this means.) Also, remove all trailing whitespace.
|
||
*
|
||
* Contributors:
|
||
* Willibald Krenn (AIT)
|
||
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
*
|
||
*/
|
||
|
||
|
||
package org.momut.ooas.ast.types;
|
||
|
||
import java.util.Iterator;
|
||
|
||
import org.momut.ooas.ast.AstNode;
|
||
import org.momut.ooas.ast.AstNodeTypeEnum;
|
||
import org.momut.ooas.ast.IAst;
|
||
import org.momut.ooas.ast.IAstVisitor;
|
||
import org.momut.ooas.ast.identifiers.TypeIdentifier;
|
||
import org.momut.ooas.utils.exceptions.ArgumentException;
|
||
import org.momut.ooas.utils.exceptions.NotImplementedException;
|
||
import org.momut.ooas.utils.exceptions.OoasCompilerRuntimeException;
|
||
|
||
public abstract class UlyssesType extends AstNode implements IAst
|
||
{
|
||
private String m_origAnonName;
|
||
protected TypeKind m_kind;
|
||
protected TypeIdentifier m_identifier;
|
||
protected int m_hash;
|
||
// protected long TimeStamp = DateTime.Now.Ticks;
|
||
|
||
|
||
public TypeKind kind() { return m_kind; }
|
||
|
||
public TypeIdentifier identifier() {
|
||
synchronized(this) {
|
||
if (m_identifier == null)
|
||
SetupAnonymousName();
|
||
}
|
||
return m_identifier;
|
||
}
|
||
|
||
public boolean isAnonymousType() {
|
||
final String anonName = AnonymousName();
|
||
if (!m_origAnonName.equals(anonName))
|
||
throw new OoasCompilerRuntimeException("Internal Error: Anonymous Name changed from '%s' to '%s'.", m_origAnonName, anonName);
|
||
return anonName.equals(m_identifier.tokenText());
|
||
}
|
||
|
||
protected UlyssesType(TypeKind aKind, TypeIdentifier anIdentifier)
|
||
{
|
||
m_kind = aKind;
|
||
m_identifier = anIdentifier;
|
||
m_hash = aKind.toString().hashCode(); //Enum.GetName(typeof(TypeKind), aKind).GetHashCode();
|
||
}
|
||
|
||
@Override
|
||
public /*override*/ String toString()
|
||
{
|
||
return identifier().tokenText();
|
||
}
|
||
|
||
public /*virtual*/ String AnonymousName()
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
|
||
public void SetTypeIdentifier(TypeIdentifier anId)
|
||
{
|
||
m_identifier = anId;
|
||
}
|
||
|
||
public void SetupAnonymousName()
|
||
{
|
||
if (m_identifier == null)
|
||
{
|
||
final String anonymousName = this.AnonymousName();
|
||
m_identifier = new TypeIdentifier(anonymousName, this, null);
|
||
m_origAnonName = anonymousName;
|
||
}
|
||
}
|
||
|
||
|
||
@Override
|
||
public AstNodeTypeEnum nodeType() { return AstNodeTypeEnum.type; }
|
||
|
||
@Override
|
||
public void Accept(IAstVisitor visitor)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
|
||
|
||
public boolean IsNumeric()
|
||
{
|
||
final Object o = this;
|
||
return (m_kind == TypeKind.IntType) ||
|
||
(m_kind == TypeKind.FloatType) ||
|
||
(m_kind == TypeKind.EnumeratedType && o instanceof ValuedEnumType);
|
||
}
|
||
|
||
public boolean IsQualitative()
|
||
{
|
||
return (m_kind == TypeKind.QrType);
|
||
}
|
||
|
||
/**
|
||
* returns the number of unique values of the type (2 for bool, etc..)
|
||
*/
|
||
public int valueCount() {
|
||
throw new NotImplementedException(); // must be overridden by child
|
||
}
|
||
|
||
public static String High(UlyssesType atype)
|
||
{
|
||
switch (atype.kind())
|
||
{
|
||
case BoolType:
|
||
return "1";
|
||
case EnumeratedType:
|
||
return Integer.toString((((EnumType)atype).listOfEnumSymbols().size() - 1));
|
||
case IntType:
|
||
return Integer.toString(((IntType)atype).rangeHigh());
|
||
case FloatType:
|
||
return Double.toString(((FloatType)atype).high());
|
||
// case TypeKind.QrType:
|
||
// return (((QrType)atype).landmarks.Count - 1).ToString();
|
||
default:
|
||
throw new NotImplementedException();
|
||
}
|
||
}
|
||
|
||
public static String Low(UlyssesType atype)
|
||
{
|
||
switch (atype.kind())
|
||
{
|
||
case BoolType:
|
||
return "0";
|
||
case EnumeratedType:
|
||
return "0";
|
||
case IntType:
|
||
return Integer.toString(((IntType)atype).rangeLow());
|
||
case FloatType:
|
||
return Double.toString(((FloatType)atype).low());
|
||
// case TypeKind.QrType:
|
||
// return "0";
|
||
default:
|
||
throw new NotImplementedException();
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Returns a cover for two types (if possible).
|
||
/// note the cover type for two ints, floats, etc. will have max/min values
|
||
/// that reflect the maximum of the two operands.
|
||
/// </summary>
|
||
|
||
public static UlyssesType CoverType(UlyssesType type1, UlyssesType type2)
|
||
{
|
||
/*first some sanity checks*/
|
||
if (type1 == null)
|
||
throw new ArgumentException("type1 null");
|
||
if (type2 == null)
|
||
throw new ArgumentException("type2 null");
|
||
|
||
if (type1.kind() == TypeKind.OpaqueType)
|
||
throw new ArgumentException("type1 opaque type");
|
||
if (type2.kind() == TypeKind.OpaqueType)
|
||
throw new ArgumentException("type2 opaque type");
|
||
|
||
if (type1 == type2)
|
||
return type1;
|
||
if (UlyssesType.TypeEqual(type1, type2))
|
||
return type1;
|
||
|
||
final TypeKind tk1 = type1.kind();
|
||
final TypeKind tk2 = type2.kind();
|
||
|
||
|
||
|
||
if (tk1 != tk2)
|
||
{
|
||
// the only notion we support here is int->float and valenum -> int
|
||
if ((tk1 == TypeKind.IntType || tk2 == TypeKind.IntType)
|
||
&& (tk1 == TypeKind.FloatType || tk2 == TypeKind.FloatType))
|
||
{
|
||
final IntType aInt = tk1 == TypeKind.IntType ? (IntType)type1 : (IntType)type2;
|
||
final FloatType aFloat = tk1 == TypeKind.IntType ? (FloatType)type2 : (FloatType)type1;
|
||
|
||
final double low = aInt.rangeLow() < aFloat.low() ? (double)aInt.rangeLow() : aFloat.low();
|
||
final double high = aInt.rangeHigh() < aFloat.high() ? aFloat.high() : (double)aInt.rangeHigh();
|
||
final double precision = aFloat.precision() > 1 ? 1.0 : aFloat.precision();
|
||
|
||
return new FloatType(low, high, precision, null);
|
||
|
||
}
|
||
else if ((tk1 == TypeKind.IntType || tk2 == TypeKind.IntType)
|
||
&& (tk1 == TypeKind.EnumeratedType || tk2 == TypeKind.EnumeratedType))
|
||
{
|
||
final IntType intt1 = tk1 == TypeKind.IntType ? (IntType)type1 : (IntType)type2;
|
||
final EnumType anEnum = tk1 == TypeKind.IntType ? (EnumType)type2 : (EnumType)type1;
|
||
|
||
if (anEnum instanceof ValuedEnumType)
|
||
{
|
||
final IntType intt2 = ((ValuedEnumType)anEnum).getIntType();
|
||
final int low = intt1.rangeLow() < intt2.rangeLow() ? intt1.rangeLow() : intt2.rangeLow();
|
||
final int high = intt1.rangeHigh() > intt2.rangeHigh() ? intt1.rangeHigh() : intt2.rangeHigh();
|
||
return new IntType(low, high, null);
|
||
}
|
||
else
|
||
return null;
|
||
}
|
||
else if (tk1 == TypeKind.Any || tk2 == TypeKind.Any)
|
||
{
|
||
final AnyType freeVar = tk1 == TypeKind.Any ? (AnyType)type1 : (AnyType)type2;
|
||
final UlyssesType fixedType = tk1 == TypeKind.Any ? type2 : type1;
|
||
final UlyssesType newcover = freeVar.VariableIdentifier().type().kind() == TypeKind.Any
|
||
? fixedType : CoverType(fixedType, freeVar.VariableIdentifier().type());
|
||
freeVar.VariableIdentifier().SetType(newcover);
|
||
return newcover;
|
||
}
|
||
else if (tk1 == TypeKind.OoActionSystemType && tk2 == TypeKind.Null)
|
||
{
|
||
return type1;
|
||
}
|
||
else if (tk2 == TypeKind.OoActionSystemType && tk1 == TypeKind.Null)
|
||
{
|
||
return type2;
|
||
}
|
||
|
||
else
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
switch (tk1)
|
||
{
|
||
case Any:
|
||
return type1;
|
||
|
||
case IntType:
|
||
final IntType intt1 = (IntType)type1;
|
||
final IntType intt2 = (IntType)type2;
|
||
final int low = intt1.rangeLow() < intt2.rangeLow() ? intt1.rangeLow() : intt2.rangeLow();
|
||
final int high = intt1.rangeHigh() > intt2.rangeHigh() ? intt1.rangeHigh() : intt2.rangeHigh();
|
||
return new IntType(low, high, null);
|
||
case BoolType:
|
||
return type1;
|
||
case FloatType:
|
||
final FloatType floatt1 = (FloatType)type1;
|
||
final FloatType floatt2 = (FloatType)type2;
|
||
final double flow = floatt1.low() < floatt2.low() ? floatt1.low() : floatt2.low();
|
||
final double fhigh = floatt1.high() > floatt2.high() ? floatt1.high() : floatt2.high();
|
||
final double fprec = floatt1.precision() < floatt2.precision() ? floatt1.precision() : floatt2.precision();
|
||
return new FloatType(flow, fhigh, fprec, null);
|
||
case EnumeratedType:
|
||
return null;
|
||
case ListType:
|
||
final ListType listt1 = (ListType)type1;
|
||
final ListType listt2 = (ListType)type2;
|
||
int maxelems = listt1.maxNumberOfElements() > listt2.maxNumberOfElements() ?
|
||
listt1.maxNumberOfElements() : listt2.maxNumberOfElements();
|
||
// empty lists lack type, so take the other one
|
||
if ((listt1.innerType().kind() == TypeKind.Null) && (listt2.innerType().kind() != TypeKind.Null))
|
||
return listt2;
|
||
else if ((listt2.innerType().kind() == TypeKind.Null) && (listt1.innerType().kind() != TypeKind.Null))
|
||
return listt1;
|
||
else if (listt1.innerType().kind() == TypeKind.Null && listt2.innerType().kind() == TypeKind.Null)
|
||
return listt1;
|
||
else
|
||
{
|
||
final UlyssesType subtype = UlyssesType.CoverType(listt1.innerType(), listt2.innerType());
|
||
if (subtype != null)
|
||
return new ListType(subtype, maxelems, null);
|
||
else
|
||
return null;
|
||
}
|
||
case MapType:
|
||
final MapType mapt1 = (MapType)type1;
|
||
final MapType mapt2 = (MapType)type2;
|
||
// empty maps lack type, so take the other one.
|
||
if ((mapt1.fromType().kind() == TypeKind.Null && mapt1.toType().kind() == TypeKind.Null)
|
||
&& (mapt2.fromType().kind() != TypeKind.Null && mapt2.toType().kind() != TypeKind.Null))
|
||
return mapt2;
|
||
else if ((mapt2.fromType().kind() == TypeKind.Null && mapt2.toType().kind() == TypeKind.Null)
|
||
&& (mapt1.fromType().kind() != TypeKind.Null && mapt1.toType().kind() != TypeKind.Null))
|
||
return mapt1;
|
||
else if ((mapt2.fromType().kind() == TypeKind.Null && mapt2.toType().kind() == TypeKind.Null)
|
||
&& (mapt1.fromType().kind() == TypeKind.Null && mapt1.toType().kind() == TypeKind.Null))
|
||
return mapt1;
|
||
else
|
||
{
|
||
final UlyssesType sub1 = UlyssesType.CoverType(mapt1.fromType(), mapt2.fromType());
|
||
final UlyssesType sub2 = UlyssesType.CoverType(mapt2.toType(), mapt2.toType());
|
||
maxelems = mapt1.maxNumberOfElements() > mapt2.maxNumberOfElements() ?
|
||
mapt1.maxNumberOfElements() : mapt2.maxNumberOfElements();
|
||
if (sub1 != null && sub2 != null)
|
||
return new MapType(sub1, sub2, maxelems, null);
|
||
else
|
||
return null;
|
||
}
|
||
case QrType:
|
||
return null; /*if refs are equal, we do not reach this statement! see above..*/
|
||
case TupleType:
|
||
final TupleType tuplet1 = (TupleType)type1;
|
||
final TupleType tuplet2 = (TupleType)type2;
|
||
final TupleType result = new TupleType(null);
|
||
final Iterator<UlyssesType> innert1 = tuplet1.innerTypes().iterator();
|
||
final Iterator<UlyssesType> innert2 = tuplet2.innerTypes().iterator();
|
||
while (innert1.hasNext())
|
||
{
|
||
final UlyssesType newinner = UlyssesType.CoverType(innert1.next(), innert2.next());
|
||
if (newinner == null)
|
||
return null;
|
||
result.AddType(newinner);
|
||
}
|
||
return result;
|
||
case OoActionSystemType:
|
||
if (type1.kind() == TypeKind.Null && type2.kind() != TypeKind.Null)
|
||
return type2;
|
||
else if (type2.kind() == TypeKind.Null && type1.kind() != TypeKind.Null)
|
||
return type1;
|
||
else if (type1.kind() == TypeKind.Null && type2.kind() == TypeKind.Null)
|
||
return type2;
|
||
else if (type1 == type2) // ref equals!
|
||
return type1;
|
||
else
|
||
return ClassBaseType((OoActionSystemType)type1, (OoActionSystemType)type2);
|
||
case OpaqueType:
|
||
assert(false);
|
||
return null;
|
||
default:
|
||
throw new NotImplementedException();
|
||
}
|
||
}
|
||
}
|
||
|
||
private static UlyssesType ClassBaseType(OoActionSystemType type1, OoActionSystemType type2)
|
||
{
|
||
// this is rather inefficient.. should be done differently
|
||
final OoActionSystemType typea = type1;
|
||
final OoActionSystemType typeb = type2;
|
||
OoActionSystemType basea = type1;
|
||
OoActionSystemType baseb = type2;
|
||
while (basea != null)
|
||
{
|
||
if (basea == typeb) // ref equals
|
||
return basea;
|
||
basea = basea.baseType();
|
||
}
|
||
while (baseb != null)
|
||
{
|
||
if (baseb == typea) // ref equals
|
||
return baseb;
|
||
baseb = baseb.baseType();
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public static boolean FirstTypeLessRange(UlyssesType type1, UlyssesType type2)
|
||
{
|
||
final TypeKind tk1 = type1.kind();
|
||
final TypeKind tk2 = type2.kind();
|
||
|
||
if (tk1 != tk2)
|
||
throw new ArgumentException("Types need to be equal");
|
||
|
||
switch (tk1)
|
||
{
|
||
case Any:
|
||
return false;
|
||
case IntType:
|
||
final IntType Int1 = (IntType)type1;
|
||
final IntType Int2 = (IntType)type2;
|
||
return Int1.rangeLow() > Int2.rangeLow() ||
|
||
Int1.rangeHigh() < Int2.rangeHigh();
|
||
case BoolType:
|
||
return false;
|
||
case FloatType:
|
||
final FloatType Float1 = (FloatType)type1;
|
||
final FloatType Float2 = (FloatType)type2;
|
||
return Float1.low() > Float2.low()
|
||
|| Float1.high() < Float2.high()
|
||
|| Float1.precision() > Float2.precision();
|
||
case EnumeratedType:
|
||
return false;
|
||
case ListType:
|
||
final ListType listt1 = (ListType)type1;
|
||
final ListType listt2 = (ListType)type2;
|
||
return (listt1.maxNumberOfElements() < listt2.maxNumberOfElements()) ||
|
||
UlyssesType.FirstTypeLessRange(listt1.innerType(), listt2.innerType());
|
||
case MapType:
|
||
final MapType mapt1 = (MapType)type1;
|
||
final MapType mapt2 = (MapType)type2;
|
||
return (mapt1.maxNumberOfElements() < mapt2.maxNumberOfElements()) ||
|
||
UlyssesType.FirstTypeLessRange(mapt1.fromType(), mapt2.fromType()) ||
|
||
UlyssesType.FirstTypeLessRange(mapt1.toType(), mapt2.toType());
|
||
case QrType:
|
||
return false;
|
||
case TupleType:
|
||
final TupleType tuplet1 = (TupleType)type1;
|
||
final TupleType tuplet2 = (TupleType)type2;
|
||
if (tuplet1.innerTypes().size() != tuplet2.innerTypes().size())
|
||
return false;
|
||
final Iterator<UlyssesType> innert1 = tuplet1.innerTypes().iterator();
|
||
final Iterator<UlyssesType> innert2 = tuplet2.innerTypes().iterator();
|
||
while (innert1.hasNext())
|
||
{
|
||
if (UlyssesType.FirstTypeLessRange(innert1.next(), innert2.next()))
|
||
return true;
|
||
}
|
||
return false;
|
||
case OoActionSystemType:
|
||
return false;
|
||
case OpaqueType:
|
||
assert(false);
|
||
return false;
|
||
default:
|
||
throw new NotImplementedException();
|
||
}
|
||
}
|
||
|
||
public static boolean TypeEqualByKind(UlyssesType type1, UlyssesType type2)
|
||
{
|
||
if ((type1 == null) || (type2 == null))
|
||
return false;
|
||
|
||
final TypeKind tk1 = type1.kind();
|
||
final TypeKind tk2 = type2.kind();
|
||
|
||
// if of different kind, then return false..
|
||
if (tk1 != tk2)
|
||
return false;
|
||
|
||
// if same kind, make a rigorous check
|
||
switch (tk1)
|
||
{
|
||
case Any:
|
||
return true;
|
||
|
||
case IntType:
|
||
case BoolType:
|
||
case FloatType:
|
||
return true;
|
||
case EnumeratedType:
|
||
return type1 == type2; // ref equals
|
||
case ListType:
|
||
final ListType listt1 = (ListType)type1;
|
||
final ListType listt2 = (ListType)type2;
|
||
return UlyssesType.TypeEqualByKind(listt1.innerType(), listt2.innerType());
|
||
case MapType:
|
||
final MapType mapt1 = (MapType)type1;
|
||
final MapType mapt2 = (MapType)type2;
|
||
return UlyssesType.TypeEqualByKind(mapt1.fromType(), mapt2.fromType()) &&
|
||
UlyssesType.TypeEqualByKind(mapt1.toType(), mapt2.toType());
|
||
case QrType:
|
||
final QrType qr1 = (QrType)type1;
|
||
final QrType qr2 = (QrType)type2;
|
||
return qr1 == qr2; // ref equals
|
||
case TupleType:
|
||
final TupleType tuplet1 = (TupleType)type1;
|
||
final TupleType tuplet2 = (TupleType)type2;
|
||
if (tuplet1.innerTypes().size() != tuplet2.innerTypes().size())
|
||
return false;
|
||
final Iterator<UlyssesType> innert1 = tuplet1.innerTypes().iterator();
|
||
final Iterator<UlyssesType> innert2 = tuplet2.innerTypes().iterator();
|
||
while (innert1.hasNext())
|
||
{
|
||
if (!UlyssesType.TypeEqualByKind(innert1.next(), innert2.next()))
|
||
return false;
|
||
}
|
||
return true;
|
||
case OoActionSystemType:
|
||
return type1 == type2; // ref equ.
|
||
case OpaqueType:
|
||
assert(false);
|
||
return false;
|
||
default:
|
||
throw new NotImplementedException();
|
||
}
|
||
}
|
||
|
||
|
||
public static boolean TypeEqual(UlyssesType type1, UlyssesType type2)
|
||
{
|
||
// this will also work with opaque types...
|
||
while (type1 instanceof OpaqueType)
|
||
type1 = ((OpaqueType)type1).resolvedType();
|
||
while (type2 instanceof OpaqueType)
|
||
type2 = ((OpaqueType)type2).resolvedType();
|
||
|
||
if ((type1 == null) || (type2 == null))
|
||
return false;
|
||
|
||
final TypeKind tk1 = type1.kind();
|
||
final TypeKind tk2 = type2.kind();
|
||
|
||
// if of different kind, then return false..
|
||
if (tk1 != tk2)
|
||
return false;
|
||
|
||
// if same kind, make a rigorous check
|
||
switch (tk1)
|
||
{
|
||
case IntType:
|
||
final IntType intt1 = (IntType)type1;
|
||
final IntType intt2 = (IntType)type2;
|
||
return intt1.rangeLow() == intt2.rangeLow() &&
|
||
intt1.rangeHigh() == intt2.rangeHigh();
|
||
case BoolType:
|
||
return true;
|
||
case FloatType:
|
||
final FloatType floatt1 = (FloatType)type1;
|
||
final FloatType floatt2 = (FloatType)type2;
|
||
return floatt1.low() == floatt2.low() &&
|
||
floatt1.high() == floatt2.high() &&
|
||
floatt1.precision() == floatt2.precision();
|
||
case EnumeratedType:
|
||
return type1 == type2; // ref equ
|
||
case ListType:
|
||
final ListType listt1 = (ListType)type1;
|
||
final ListType listt2 = (ListType)type2;
|
||
// an empty list can be of any type..
|
||
/*if ((listt1.innerType.kind == TypeKind.Null) || (listt2.innerType.kind == TypeKind.Null))
|
||
return true;
|
||
else*/
|
||
return UlyssesType.TypeEqual(listt1.innerType(), listt2.innerType()) &&
|
||
listt1.maxNumberOfElements() == listt2.maxNumberOfElements(); // need this because of covertype
|
||
case MapType:
|
||
final MapType mapt1 = (MapType)type1;
|
||
final MapType mapt2 = (MapType)type2;
|
||
return UlyssesType.TypeEqual(mapt1.fromType(), mapt2.fromType()) &&
|
||
UlyssesType.TypeEqual(mapt1.toType(), mapt2.toType()) &&
|
||
mapt1.maxNumberOfElements() == mapt2.maxNumberOfElements(); // need this because of covertype
|
||
case QrType:
|
||
final QrType qr1 = (QrType)type1;
|
||
final QrType qr2 = (QrType)type2;
|
||
return qr1 == qr2; // ref equ.
|
||
case TupleType:
|
||
final TupleType tuplet1 = (TupleType)type1;
|
||
final TupleType tuplet2 = (TupleType)type2;
|
||
if (tuplet1.innerTypes().size() != tuplet2.innerTypes().size())
|
||
return false;
|
||
final Iterator<UlyssesType> innert1 = tuplet1.innerTypes().iterator();
|
||
final Iterator<UlyssesType> innert2 = tuplet2.innerTypes().iterator();
|
||
while (innert1.hasNext())
|
||
{
|
||
if (!UlyssesType.TypeEqual(innert1.next(), innert2.next()))
|
||
return false;
|
||
}
|
||
return true;
|
||
case OoActionSystemType:
|
||
return type1 == type2; // ref equ. // || Covariance((OoActionSystemType)type1, (OoActionSystemType)type2);
|
||
case OpaqueType:
|
||
assert(false);
|
||
return false;
|
||
case Null:
|
||
case Any:
|
||
return true;
|
||
default:
|
||
throw new NotImplementedException();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// checks if type 2 is a desc. of type 1
|
||
/// </summary>
|
||
public static boolean Covariance(OoActionSystemType ooActionSystemType, OoActionSystemType ooActionSystemType_2)
|
||
{
|
||
// check if type 2 is a desc. of type 1
|
||
while (ooActionSystemType != ooActionSystemType_2 && ooActionSystemType_2.baseType() != null) // ref equ.
|
||
ooActionSystemType_2 = ooActionSystemType_2.baseType();
|
||
|
||
return ooActionSystemType == ooActionSystemType_2; // ref equ.
|
||
}
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/types/QrType.java | ||
---|---|---|
/**
|
||
*
|
||
* OOAS Compiler
|
||
*
|
||
* Copyright 2015, AIT Austrian Institute of Technology.
|
||
* This code is based on the C# Version of the OOAS Compiler, which is
|
||
* copyright 2015 by the Institute of Software Technology, Graz University
|
||
* of Technology with portions copyright by the AIT Austrian Institute of
|
||
* Technology. All rights reserved.
|
||
*
|
||
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
||
*
|
||
* If you modify the file please update the list of contributors below to in-
|
||
* clude your name. Please also stick to the coding convention of using TABs
|
||
* to do the basic (block-level) indentation and spaces for anything after
|
||
* that. (Enable the display of special chars and it should be pretty obvious
|
||
* what this means.) Also, remove all trailing whitespace.
|
||
*
|
||
* Contributors:
|
||
* Willibald Krenn (AIT)
|
||
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
*
|
||
*/
|
||
|
||
|
||
package org.momut.ooas.ast.types;
|
||
|
||
import java.util.ArrayList;
|
||
|
||
import org.momut.ooas.ast.IAstVisitor;
|
||
import org.momut.ooas.ast.identifiers.LandmarkIdentifier;
|
||
import org.momut.ooas.ast.identifiers.TypeIdentifier;
|
||
import org.momut.ooas.parser.SymbolTable;
|
||
import org.momut.ooas.utils.exceptions.SymbolAlreadyDefinedException;
|
||
|
||
///////////////////////////////////////////////
|
||
/// Complex Type: QrType
|
||
/// behaves somewhat similar to an enumerated type..
|
||
///
|
||
public final class QrType extends UlyssesType
|
||
{
|
||
private final SymbolTable m_qspaceSymbols;
|
||
private final ArrayList<LandmarkIdentifier> m_listOfQspaceSymbols;
|
||
|
||
public SymbolTable symbolTable() { return m_qspaceSymbols; }
|
||
public ArrayList<LandmarkIdentifier> landmarks() { return m_listOfQspaceSymbols; }
|
||
|
||
public QrType(TypeIdentifier anIdentifier)
|
||
{
|
||
super(TypeKind.QrType, anIdentifier);
|
||
m_listOfQspaceSymbols = new ArrayList<LandmarkIdentifier>();
|
||
m_qspaceSymbols = new SymbolTable();
|
||
}
|
||
|
||
public void AddLandmark(LandmarkIdentifier aLandmark)
|
||
{
|
||
if (m_qspaceSymbols.Defined(aLandmark.tokenText()))
|
||
throw new SymbolAlreadyDefinedException(aLandmark.tokenText());
|
||
|
||
m_qspaceSymbols.AddIdentifier(aLandmark);
|
||
m_listOfQspaceSymbols.add(aLandmark);
|
||
}
|
||
|
||
@Override
|
||
public void Accept(IAstVisitor visitor)
|
||
{
|
||
visitor.visit(this);
|
||
}
|
||
|
||
@Override
|
||
public /*override*/ String AnonymousName()
|
||
{
|
||
StringBuilder result = new StringBuilder();
|
||
result.append("qr_");
|
||
for (LandmarkIdentifier sym: m_listOfQspaceSymbols)
|
||
{
|
||
result.append(sym.tokenText());
|
||
result.append("_");
|
||
}
|
||
return result.toString();
|
||
}
|
||
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/types/EnumType.java | ||
---|---|---|
///////////////////////////////////////////////
|
||
/// Simple Type: Enumeration
|
||
///
|
||
public class EnumType extends UlyssesType
|
||
public class EnumType extends Type
|
||
{
|
||
protected SymbolTable m_enumSymbols;
|
||
protected ArrayList<EnumIdentifier> m_listOfEnumSymbols;
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/types/TupleType.java | ||
---|---|---|
///////////////////////////////////////////////
|
||
/// Complex Type: TupleType
|
||
///
|
||
public final class TupleType extends UlyssesType
|
||
public final class TupleType extends Type
|
||
{
|
||
private final LinkedList<UlyssesType> m_innerTypes;
|
||
private final LinkedList<Type> m_innerTypes;
|
||
|
||
public LinkedList<UlyssesType> innerTypes() { return m_innerTypes; }
|
||
public LinkedList<Type> innerTypes() { return m_innerTypes; }
|
||
|
||
public TupleType(TypeIdentifier anIdentifier)
|
||
{
|
||
super(TypeKind.TupleType, anIdentifier);
|
||
m_innerTypes = new LinkedList<UlyssesType>();
|
||
m_innerTypes = new LinkedList<Type>();
|
||
}
|
||
|
||
public void AddType(UlyssesType aType)
|
||
public void AddType(Type aType)
|
||
{
|
||
m_innerTypes.addLast(aType);
|
||
}
|
||
... | ... | |
{
|
||
StringBuilder result = new StringBuilder();
|
||
result.append("tuple_");
|
||
for (UlyssesType inner: m_innerTypes)
|
||
for (Type inner: m_innerTypes)
|
||
{
|
||
result.append(inner.toString());
|
||
result.append("_");
|
||
... | ... | |
@Override
|
||
public int valueCount() {
|
||
int result = 1;
|
||
for (final UlyssesType inner: m_innerTypes)
|
||
for (final Type inner: m_innerTypes)
|
||
result *= inner.valueCount();
|
||
return result;
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/types/FunctionType.java | ||
---|---|---|
///////////////////////////////////////////////
|
||
/// Complex Type: Function
|
||
///
|
||
public final class FunctionType extends UlyssesType
|
||
public final class FunctionType extends Type
|
||
{
|
||
public enum FunctionTypeEnum {
|
||
Observable (0),
|
||
... | ... | |
|
||
private Boolean m_miracleSafe = null;
|
||
private boolean m_pure;
|
||
private LinkedList<UlyssesType> m_parameter;
|
||
private UlyssesType m_returnType;
|
||
private LinkedList<Type> m_parameter;
|
||
private Type m_returnType;
|
||
private final FunctionTypeEnum m_functionType;
|
||
|
||
public Boolean isMiracleSafe() { return m_miracleSafe; }
|
||
public boolean isPureFunction() { return m_pure; }
|
||
public LinkedList<UlyssesType> parameter() { return m_parameter; }
|
||
public UlyssesType returnType() { return m_returnType; }
|
||
public LinkedList<Type> parameter() { return m_parameter; }
|
||
public Type returnType() { return m_returnType; }
|
||
public FunctionTypeEnum functionType() { return m_functionType; }
|
||
|
||
public FunctionType(FunctionTypeEnum functionType, LinkedList<UlyssesType> parameter, UlyssesType returnType)
|
||
public FunctionType(FunctionTypeEnum functionType, LinkedList<Type> parameter, Type returnType)
|
||
{
|
||
super (TypeKind.FunctionType, null);
|
||
if (parameter != null)
|
||
m_parameter = parameter;
|
||
else
|
||
m_parameter = new LinkedList<UlyssesType>();
|
||
m_parameter = new LinkedList<Type>();
|
||
m_returnType = returnType;
|
||
m_functionType = functionType;
|
||
m_miracleSafe = null;
|
||
... | ... | |
}
|
||
|
||
|
||
public void AddParameterType(UlyssesType aType)
|
||
public void AddParameterType(Type aType)
|
||
{
|
||
m_parameter.addLast(aType);
|
||
}
|
||
|
||
public void SetReturnType(UlyssesType aType)
|
||
public void SetReturnType(Type aType)
|
||
{
|
||
m_returnType = aType;
|
||
}
|
||
... | ... | |
result.append("fun_");
|
||
result.append(m_functionType.toString());
|
||
result.append("_");
|
||
for (final UlyssesType sym: m_parameter)
|
||
for (final Type sym: m_parameter)
|
||
{
|
||
result.append(sym.toString());
|
||
result.append("_");
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/cadp/CadpExpression.java | ||
---|---|---|
import org.momut.ooas.ast.types.MapType;
|
||
import org.momut.ooas.ast.types.OoActionSystemInstance;
|
||
import org.momut.ooas.ast.types.OoActionSystemType;
|
||
import org.momut.ooas.ast.types.QrType;
|
||
import org.momut.ooas.ast.types.TupleType;
|
||
import org.momut.ooas.ast.types.TypeKind;
|
||
import org.momut.ooas.ast.types.UlyssesType;
|
||
import org.momut.ooas.ast.types.Type;
|
||
import org.momut.ooas.codegen.OoasCodeEmitter;
|
||
import org.momut.ooas.parser.SymbolTable;
|
||
import org.momut.ooas.visitors.OoaExpressionVisitor;
|
||
... | ... | |
m_emitter = tmp;
|
||
|
||
// treat cases of MyTuple(a,b..) = <expr>
|
||
final Iterator<UlyssesType> elem = ((TupleType)tupleConstructor.type()).innerTypes().iterator();
|
||
final Iterator<Type> elem = ((TupleType)tupleConstructor.type()).innerTypes().iterator();
|
||
int i = 0;
|
||
m_emitter.Append("(");
|
||
while (elem.hasNext())
|
||
... | ... | |
|
||
CadpType.EmitType(binaryOperator.type());
|
||
final ListType alist = (ListType)binaryOperator.type();
|
||
final UlyssesType innerType = alist.innerType();
|
||
final Type innerType = alist.innerType();
|
||
final String resultTypeName = CadpIdentifier.GetIdentifierString(binaryOperator.type().identifier());
|
||
|
||
m_helperCode.AppendLine(String.format("%4$s %3$s(%1$s listA, %2$s listB){", childATypeName, childBTypeName, result, resultTypeName));
|
||
... | ... | |
|
||
CadpType.EmitType(binaryOperator.type());
|
||
final ListType alist = (ListType)binaryOperator.type();
|
||
final UlyssesType innerType = alist.innerType();
|
||
final Type innerType = alist.innerType();
|
||
final String resultTypeName = CadpIdentifier.GetIdentifierString(binaryOperator.type().identifier());
|
||
|
||
m_helperCode.AppendLine(String.format("%4$s %3$s(%1$s listA, %2$s listB){", childATypeName, childBTypeName, result, resultTypeName));
|
||
... | ... | |
|
||
final FunctionType fun = (FunctionType)leftcall.child().type();
|
||
final FunctionIdentifier funid = (FunctionIdentifier) fun.identifier();
|
||
final Iterator<UlyssesType> node = fun.parameter().iterator();
|
||
final Iterator<Type> node = fun.parameter().iterator();
|
||
for (int i = 0; i < fun.parameter().size() - 2; i++)
|
||
{
|
||
final UlyssesType nodeValue = node.next();
|
||
final Type nodeValue = node.next();
|
||
paramtypes.add(CadpType.DumpType(nodeValue));
|
||
final CadpIdentifier paramid = new CadpIdentifier(m_procInfo.stateVariableString);
|
||
funid.parameter().get(i).Accept(paramid);
|
||
... | ... | |
/* The cast support in this target instanceof limited: We can not cast differently sized types!
|
||
* Hence list and map lengths must be equal.
|
||
* */
|
||
private boolean CADPCastEquivalent(UlyssesType type1, UlyssesType type2)
|
||
private boolean CADPCastEquivalent(Type type1, Type type2)
|
||
{
|
||
if ((type1 == null) || (type2 == null))
|
||
return false;
|
||
... | ... | |
return CADPCastEquivalent(mapt1.fromType(), mapt2.fromType()) &&
|
||
CADPCastEquivalent(mapt1.toType(), mapt2.toType()) &&
|
||
mapt1.maxNumberOfElements() == mapt2.maxNumberOfElements();
|
||
case QrType:
|
||
final QrType qr1 = (QrType)type1;
|
||
final QrType qr2 = (QrType)type2;
|
||
return qr1 == qr2; // ref eq.
|
||
case TupleType:
|
||
final TupleType tuplet1 = (TupleType)type1;
|
||
final TupleType tuplet2 = (TupleType)type2;
|
||
if (tuplet1.innerTypes().size() != tuplet2.innerTypes().size())
|
||
return false;
|
||
final Iterator<UlyssesType> innert1 = tuplet1.innerTypes().iterator();
|
||
final Iterator<UlyssesType> innert2 = tuplet2.innerTypes().iterator();
|
||
final Iterator<Type> innert1 = tuplet1.innerTypes().iterator();
|
||
final Iterator<Type> innert2 = tuplet2.innerTypes().iterator();
|
||
while (innert1.hasNext())
|
||
{
|
||
final UlyssesType innert1Value = innert1.next();
|
||
final UlyssesType innert2Value = innert2.next();
|
||
final Type innert1Value = innert1.next();
|
||
final Type innert2Value = innert2.next();
|
||
|
||
if (!CADPCastEquivalent(innert1Value, innert2Value))
|
||
return false;
|
||
... | ... | |
return true;
|
||
case OoActionSystemType:
|
||
return type1 == type2 /*ref. eq.*/ ||
|
||
UlyssesType.Covariance((OoActionSystemType)type2, (OoActionSystemType)type1);
|
||
Type.Covariance((OoActionSystemType)type2, (OoActionSystemType)type1);
|
||
case OpaqueType:
|
||
throw new IllegalArgumentException();
|
||
case Null:
|
||
... | ... | |
unaryOperator.type().Accept(targetType);
|
||
final CadpType sourceType = new CadpType();
|
||
unaryOperator.child().type().Accept(sourceType);
|
||
if (!(UlyssesType.Covariance((OoActionSystemType)unaryOperator.child().type(), (OoActionSystemType)unaryOperator.type())))
|
||
if (!(Type.Covariance((OoActionSystemType)unaryOperator.child().type(), (OoActionSystemType)unaryOperator.type())))
|
||
{
|
||
// cast result type (unaryOperator.type) not a sub-type of unaryOperator.child.type
|
||
return String.format("/* up-cast: %1$s as %2$s */ *(%2$s*)&", sourceType.ToString(), targetType.ToString());
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/AstBuilder.java | ||
---|---|---|
import org.momut.ooas.ast.types.ListType;
|
||
import org.momut.ooas.ast.types.OoActionSystemType;
|
||
import org.momut.ooas.ast.types.OpaqueType;
|
||
import org.momut.ooas.ast.types.UlyssesType;
|
||
import org.momut.ooas.ast.types.Type;
|
||
import org.momut.ooas.parser.ParserError;
|
||
import org.momut.ooas.parser.ParserState;
|
||
|
||
... | ... | |
|
||
|
||
public static AttributeIdentifier createObjectAttribute(String varName, Identifier aClass, boolean doInstantiate, Identifier root){
|
||
final UlyssesType aType = aClass.type();
|
||
final Type aType = aClass.type();
|
||
aType.SetupAnonymousName(); //not sure if necessary
|
||
Expression anExpr;
|
||
if (doInstantiate){
|
||
... | ... | |
return new ValueExpression<Boolean>(b, 0, 0, Boolean.class);
|
||
}
|
||
|
||
public static ListType createListType(UlyssesType elemType, int max, TypeIdentifier anIdentifier){
|
||
public static ListType createListType(Type elemType, int max, TypeIdentifier anIdentifier){
|
||
final ListType result = new ListType(elemType, max, null);
|
||
result.SetupAnonymousName();
|
||
result.SetTypeIdentifier(anIdentifier);
|
||
... | ... | |
}
|
||
|
||
|
||
public static UlyssesType createIntType(int low, int high){
|
||
public static Type createIntType(int low, int high){
|
||
return new IntType(low, high, null);
|
||
}
|
||
|
||
... | ... | |
|
||
public static AttributeIdentifier createBoolAttribute(String varname, boolean isStatic, boolean init, Identifier root){
|
||
final Expression anExpr = new ValueExpression<Boolean>(init, 0, 0, Boolean.class);
|
||
final UlyssesType aType = new BoolType(null);
|
||
final Type aType = new BoolType(null);
|
||
aType.SetupAnonymousName();
|
||
final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varname, aType, ((IScope)(root).type()), anExpr, isStatic, false, false );
|
||
((IScope)(root).type()).AddIdentifier(attributeIdentifier, null);
|
||
... | ... | |
return attributeIdentifier;
|
||
}
|
||
|
||
public static AttributeIdentifier createAttribute(String varname, boolean isStatic, UlyssesType aType, Expression anExpr, IScope scope){
|
||
public static AttributeIdentifier createAttribute(String varname, boolean isStatic, Type aType, Expression anExpr, IScope scope){
|
||
final AttributeIdentifier attributeIdentifier = new AttributeIdentifier(varname, aType, scope, anExpr, isStatic, false, false );
|
||
scope.AddIdentifier(attributeIdentifier, null);
|
||
|
||
... | ... | |
public static MethodIdentifier createMethod(
|
||
String name,
|
||
LinkedList<ParameterIdentifier> params,
|
||
UlyssesType returnType,
|
||
Type returnType,
|
||
Identifier as,
|
||
Statement body
|
||
) {
|
||
final LinkedList<UlyssesType> parameterTypes = new LinkedList<UlyssesType>();
|
||
final LinkedList<Type> parameterTypes = new LinkedList<Type>();
|
||
for (final ParameterIdentifier param : params) {
|
||
parameterTypes.add(param.type());
|
||
}
|
||
... | ... | |
public static NamedActionIdentifier createActionWithoutBody(
|
||
FunctionType.FunctionTypeEnum functionType,
|
||
String name,
|
||
LinkedList<UlyssesType> parameters,
|
||
LinkedList<Type> parameters,
|
||
Identifier as)
|
||
{
|
||
final FunctionType actionType = new FunctionType(functionType, parameters, null);
|
||
... | ... | |
public static Identifier createAction(
|
||
FunctionType.FunctionTypeEnum functionType,
|
||
String name,
|
||
LinkedList<UlyssesType> parameters,
|
||
LinkedList<Type> parameters,
|
||
Identifier as,
|
||
Statement body)
|
||
{
|
||
... | ... | |
// -- define the (implicitly declared type of the action) --lBlock
|
||
final FunctionType helloWorldActionType = new FunctionType( // this type is anonymous and doesn't have a name!
|
||
FunctionTypeEnum.Observable, // This is observable, hence an action
|
||
new LinkedList<UlyssesType>(), // no parameters
|
||
new LinkedList<Type>(), // no parameters
|
||
null // void return
|
||
);
|
||
helloWorldActionType.SetupAnonymousName(); // need to be called before setting the type identifier
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/types/ListType.java | ||
---|---|---|
///////////////////////////////////////////////
|
||
/// Complex Type: List
|
||
///
|
||
public final class ListType extends UlyssesType
|
||
public final class ListType extends Type
|
||
{
|
||
private UlyssesType m_innerType;
|
||
private Type m_innerType;
|
||
private final int m_maxNumberOfElements;
|
||
|
||
public UlyssesType innerType() { return m_innerType; }
|
||
public Type innerType() { return m_innerType; }
|
||
public int maxNumberOfElements() { return m_maxNumberOfElements; }
|
||
|
||
public ListType(UlyssesType elemType, int max, TypeIdentifier anIdentifier)
|
||
public ListType(Type elemType, int max, TypeIdentifier anIdentifier)
|
||
{
|
||
super(TypeKind.ListType, anIdentifier);
|
||
m_innerType = elemType;
|
||
... | ... | |
visitor.visit(this);
|
||
}
|
||
|
||
public void SetInnerType(UlyssesType newType)
|
||
public void SetInnerType(Type newType)
|
||
{
|
||
if (newType == null)
|
||
throw new ArgumentException();
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/java/runtime/QualitativeValue.java | ||
---|---|---|
/**
|
||
*
|
||
* OOAS Compiler
|
||
*
|
||
* Copyright 2015, AIT Austrian Institute of Technology.
|
||
* This code is based on the C# Version of the OOAS Compiler, which is
|
||
* copyright 2015 by the Institute of Software Technology, Graz University
|
||
* of Technology with portions copyright by the AIT Austrian Institute of
|
||
* Technology. All rights reserved.
|
||
*
|
||
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
||
*
|
||
* If you modify the file please update the list of contributors below to in-
|
||
* clude your name. Please also stick to the coding convention of using TABs
|
||
* to do the basic (block-level) indentation and spaces for anything after
|
||
* that. (Enable the display of special chars and it should be pretty obvious
|
||
* what this means.) Also, remove all trailing whitespace.
|
||
*
|
||
* Contributors:
|
||
* Willibald Krenn (AIT)
|
||
* Stephan Zimmerer (AIT)
|
||
* Markus Demetz (AIT)
|
||
* Christoph Czurda (AIT)
|
||
*
|
||
*/
|
||
|
||
|
||
package org.momut.ooas.codegen.java.runtime;
|
||
|
||
public class QualitativeValue
|
||
{
|
||
public Integer intervalLow;
|
||
public Integer intervalHigh;
|
||
public Integer derivation;
|
||
|
||
public QualitativeValue(Integer lowval, Integer highval, Integer deriv)
|
||
{
|
||
intervalLow = lowval;
|
||
intervalHigh = highval;
|
||
derivation = deriv;
|
||
}
|
||
}
|
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/cadp/CadpType.java | ||
---|---|---|
import org.momut.ooas.ast.types.OoActionSystemInstance;
|
||
import org.momut.ooas.ast.types.OoActionSystemType;
|
||
import org.momut.ooas.ast.types.OpaqueType;
|
||
import org.momut.ooas.ast.types.QrType;
|
||
import org.momut.ooas.ast.types.TupleType;
|
||
import org.momut.ooas.ast.types.TypeKind;
|
||
import org.momut.ooas.ast.types.UlyssesType;
|
||
import org.momut.ooas.ast.types.Type;
|
||
import org.momut.ooas.ast.types.ValuedEnumType;
|
||
import org.momut.ooas.codegen.OoasCodeEmitter;
|
||
import org.momut.ooas.parser.SymbolTable;
|
||
... | ... | |
{
|
||
throw new UnsupportedOperationException();
|
||
}
|
||
@Override
|
||
public void visit(QrType qrType)
|
||
{
|
||
throw new UnsupportedOperationException();
|
||
}
|
||
|
||
@Override
|
||
public void visit(FunctionType functionType)
|
||
... | ... | |
super(null);
|
||
}
|
||
|
||
public static String DumpType(UlyssesType atype)
|
||
public static String DumpType(Type atype)
|
||
{
|
||
final CadpType newtype = new CadpType();
|
||
atype.Accept(newtype);
|
||
... | ... | |
|
||
private static HashSet<String> emittedTypes = new HashSet<String>();
|
||
|
||
private static void EmitType(UlyssesType aType, OoasCodeEmitter emitter)
|
||
private static void EmitType(Type aType, OoasCodeEmitter emitter)
|
||
{
|
||
final String typename = CadpIdentifier.GetIdentifierString(aType.identifier());
|
||
if (!emittedTypes.contains(typename))
|
||
... | ... | |
emitter.AppendLine("#endif");
|
||
emitter.AppendLineIncIndent(String.format("struct struct_%1$s {", typeName));
|
||
int i = 0;
|
||
for (final UlyssesType it: atupleType.innerTypes())
|
||
for (final Type it: atupleType.innerTypes())
|
||
{
|
||
EmitType(it);
|
||
emitter.AppendLine(String.format("%1$s elem_%2$s;", DumpType(it), i));
|
||
... | ... | |
emitter.AppendLine(String.format("/*%1$s%2$s*/", constructorString, typeName));
|
||
emitter.Append(String.format("%1$s %2$s%1$s (", typeName, constructorString));
|
||
i = 0;
|
||
for (final UlyssesType it: atupleType.innerTypes())
|
||
for (final Type it: atupleType.innerTypes())
|
||
{
|
||
if (!emittedTypes.contains(CadpIdentifier.GetIdentifierString(it.identifier())))
|
||
EmitType(it, result);
|
||
... | ... | |
emitter.AppendLineIncIndent(") {");
|
||
emitter.AppendLine(String.format("%1$s result;", typeName));
|
||
i = 0;
|
||
for (final UlyssesType it: atupleType.innerTypes())
|
||
for (final Type it: atupleType.innerTypes())
|
||
{
|
||
emitter.AppendLine(String.format("result.elem_%1$s = arg_%1$s;", i));
|
||
/*do range checking on ints and floats*/
|
||
... | ... | |
emitter.AppendLine(String.format("/*%1$s%2$s*/", highString, typeName));
|
||
emitter.Append(String.format("long long int %2$s%1$s (void) { return ", typeName, highString));
|
||
i = 0;
|
||
for (final UlyssesType x : atupleType.innerTypes())
|
||
for (final Type x : atupleType.innerTypes())
|
||
{
|
||
if (i != 0)
|
||
emitter.Append(" * ");
|
||
... | ... | |
emitter.Append(String.format("return %2$s%1$s (", typeName, constructorString));
|
||
i = 0;
|
||
final StringBuilder divisor = new StringBuilder("value");
|
||
for (final UlyssesType it: atupleType.innerTypes())
|
||
for (final Type it: atupleType.innerTypes())
|
||
{
|
||
if (i != 0)
|
||
emitter.Append(",");
|
||
... | ... | |
emitter.AppendLine(String.format("void %1$s%2$s (CAESAR_TYPE_FILE CAESAR_FILE, %2$s A_VALUE)", printString, typeName));
|
||
emitter.AppendLine("{");
|
||
emitter.AppendLine(String.format(" fprintf(CAESAR_FILE,\" (\");"));
|
||
final Iterator<UlyssesType> iter = atupleType.innerTypes().iterator();
|
||
final Iterator<Type> iter = atupleType.innerTypes().iterator();
|
||
for (i = 0; i < atupleType.innerTypes().size(); i++)
|
||
{
|
||
if (i != 0)
|
||
... | ... | |
|
||
|
||
|
||
public static String GetMaxVal(UlyssesType atype)
|
||
public static String GetMaxVal(Type atype)
|
||
{
|
||
return String.format(" (%2$s%1$s() - 1) ", GetIdentifierString(atype.identifier()), highString);
|
||
}
|
||
|
||
public static String GetMinVal(UlyssesType atype)
|
||
public static String GetMinVal(Type atype)
|
||
{
|
||
return String.format(" %2$s%1$s() ", GetIdentifierString(atype.identifier()), lowString);
|
Also available in: Unified diff
remove support for Qualitative Action Systems, rename UlyssesType to Type