blob: 95136694aa3ca8122c6c958a3481555b5ac7a43e [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2016 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Created on: 7 août 2008
*
* Contributors:
* Arnault Lapitre (CEA LIST) arnault.lapitre@cea.fr
* - Initial API and implementation
******************************************************************************/
#ifndef ENUMTYPESPECIFIER_H_
#define ENUMTYPESPECIFIER_H_
#include <fml/type/BaseSymbolTypeSpecifier.h>
#include <common/BF.h>
namespace sep
{
class DataType;
class EnumTypeSpecifier : public BaseSymbolTypeSpecifier ,
AVM_INJECT_INSTANCE_COUNTER_CLASS( EnumTypeSpecifier )
{
AVM_DECLARE_UNCLONABLE_CLASS(EnumTypeSpecifier)
protected:
/*
* ATTRIBUTES
*/
bool mIntegerEnumerationFlag;
BF mInfimum;
BF mSupremum;
public:
/**
* CONSTRUCTOR
* Default
*/
EnumTypeSpecifier(DataType * aCompiledType)
: BaseSymbolTypeSpecifier(CLASS_KIND_T( EnumTypeSpecifier ),
TYPE_ENUM_SPECIFIER, aCompiledType, 1, 1, 0),
mIntegerEnumerationFlag( false ),
mInfimum( ),
mSupremum( )
{
//!!! NOTHING
}
/**
* DESTRUCTOR
*/
virtual ~EnumTypeSpecifier()
{
//!!! NOTHING
}
/**
* GETTER - SETTER
* mInfimum
*/
inline const BF & getInfimum() const
{
return( mInfimum );
}
inline bool hasInfimum() const
{
return( mInfimum.valid() );
}
inline void setInfimum(const BF & anInfimum)
{
mInfimum = anInfimum;
}
/**
* GETTER - SETTER
* mSupremum
*/
inline const BF & getSupremum()const
{
return( mSupremum );
}
inline bool hasSupremum() const
{
return( mSupremum.valid() );
}
inline void setSupremum(const BF & aSupremum)
{
mSupremum = aSupremum;
}
/**
* SETTER
* mBound
*/
void updateBound();
void updateBound(avm_integer_t min, avm_integer_t max);
/**
* GETTER - SETTER
* mSymbolData
*/
bool hasSymbolData(InstanceOfData * aSymbolData) const;
bool hasSymbolData(const BF & aSymbol) const;
bool hasSymbolDataWithValue(const BF & aValue) const;
const Symbol & getSymbolDataByValue(const BF & aValue) const;
avm_size_t getRandomSymbolOffset();
const Symbol & getRandomSymbolData();
const BF & getRandomSymbolValue();
/**
* GETTER
* newfresh Enum Value
*/
BF newfreshSymbolValue();
/**
* SETTER
* mBitSize
*/
inline virtual void updateSize()
{
setBitSize( mSymbolData.size() );
}
/**
* CONSTRAINT generation
* for a given parameter
*/
BF minConstraint(const BF & aParam) const;
BF maxConstraint(const BF & aParam) const;
BF genConstraint(const BF & aParam) const;
/**
* Format a value w.r.t. its type
*/
inline virtual void formatStream(OutStream & out, const BF & bfValue) const
{
if( bfValue.is< InstanceOfData >() &&
(bfValue.to_ptr< InstanceOfData >()->getTypeSpecifier() == this) )
{
AVM_IF_DEBUG_FLAG( DATA )
out << bfValue.to_ptr< InstanceOfData >()->getFullyQualifiedNameID();
AVM_DEBUG_ELSE
out << bfValue.to_ptr< InstanceOfData >()->getNameID();
AVM_ENDIF_DEBUG_FLAG( DATA )
}
else
{
const Symbol & aSymbol = getSymbolDataByValue(bfValue);
AVM_IF_DEBUG_FLAG( DATA )
out << ( aSymbol.valid() ?
aSymbol.getFullyQualifiedNameID() : bfValue.str() );
AVM_DEBUG_ELSE
out << ( aSymbol.valid() ? aSymbol.getNameID() : bfValue.str() );
AVM_ENDIF_DEBUG_FLAG( DATA )
}
}
/**
* Serialization
*/
void toStream(OutStream & out) const;
};
}
#endif /* ENUMTYPESPECIFIER_H_ */