yast2-core
|
YCP type. More...
#include <Type.h>
Public Types | |
enum | type_kind { UnspecT = 0, ErrorT, AnyT, BooleanT, ByteblockT, FloatT, IntegerT, LocaleT, PathT, StringT, SymbolT, TermT, VoidT, WildcardT, FlexT, VariableT, ListT, MapT, BlockT, TupleT, FunctionT, NilT, NFlexT } |
typedef enum Type::type_kind | tkind |
Public Member Functions | |
Type () | |
Type (tkind kind, bytecodeistream &str) | |
virtual | ~Type () |
virtual string | toString () const |
virtual string | toXmlString () const |
virtual std::ostream & | toStream (std::ostream &str) const |
virtual std::ostream & | toXml (std::ostream &str, int indent) const |
virtual bool | isBasetype () const |
virtual constTypePtr | matchFlex (constTypePtr, unsigned int=0) const |
virtual int | match (constTypePtr expected) const |
virtual int | matchvalue (YCPValue value) const |
virtual bool | canCast (constTypePtr to) const |
virtual TypePtr | clone () const |
virtual constTypePtr | unflex (constTypePtr type, unsigned int number=0) const |
string | preToString () const |
string | postToString () const |
bool | isConst () const |
void | asConst () |
bool | isReference () const |
void | asReference () |
int | basematch (constTypePtr expected) const |
virtual bool | equals (constTypePtr expected) const |
bool | isUnspec () const |
bool | isError () const |
bool | isAny () const |
bool | isBoolean () const |
bool | isByteblock () const |
bool | isFloat () const |
bool | isInteger () const |
bool | isLocale () const |
bool | isPath () const |
bool | isString () const |
bool | isSymbol () const |
bool | isTerm () const |
bool | isVoid () const |
bool | isWildcard () const |
bool | isFlex () const |
bool | isNFlex () const |
bool | isVariable () const |
bool | isList () const |
bool | isMap () const |
bool | isBlock () const |
bool | isTuple () const |
bool | isFunction () const |
bool | isNil () const |
YCPValueType | valueType () const |
virtual constTypePtr | commontype (constTypePtr type) const |
virtual constTypePtr | detailedtype (constTypePtr type) const |
![]() | |
Rep () | |
Rep (const Rep &) | |
Rep & | operator= (const Rep &) |
virtual | ~Rep () |
void | ref () const |
void | unref () const |
unsigned | refCount () const |
virtual const char * | repName () const |
virtual std::ostream & | dumpOn (std::ostream &str) const |
Static Public Member Functions | |
static void | setNocheck (bool nocheck) |
static constTypePtr | vt2type (enum YCPValueType vt) |
static int | nextToken (const char **signature) |
static constTypePtr | fromSignature (const char **signature) |
static constTypePtr | fromSignature (const string &signature) |
static constTypePtr | determineFlexType (constFunctionTypePtr actual, constFunctionTypePtr declared) |
static FunctionTypePtr | Function (constTypePtr return_type) |
![]() | |
static void | ref (const Rep *obj_r) |
static void | unref (const Rep *obj_r) |
Static Public Attributes | |
static const constTypePtr | Unspec = TypePtr ( new Type (UnspecT)) |
static const constTypePtr | Error = TypePtr ( new Type (ErrorT)) |
static const constTypePtr | Any = TypePtr ( new Type (AnyT)) |
static const constTypePtr | Void = TypePtr ( new Type (VoidT)) |
static const constTypePtr | Boolean = TypePtr ( new Type (BooleanT)) |
static const constTypePtr | Byteblock = TypePtr ( new Type (ByteblockT)) |
static const constTypePtr | Float = TypePtr ( new Type (FloatT)) |
static const constTypePtr | Integer = TypePtr ( new Type (IntegerT)) |
static const constTypePtr | Locale = TypePtr ( new Type (LocaleT)) |
static const constTypePtr | Path = TypePtr ( new Type (PathT)) |
static const constTypePtr | String = TypePtr ( new Type (StringT)) |
static const constTypePtr | Symbol = TypePtr ( new Type (SymbolT)) |
static const constTypePtr | Term = TypePtr ( new Type (TermT)) |
static const constTypePtr | Wildcard = TypePtr ( new Type (WildcardT)) |
static const constTypePtr | ConstAny = TypePtr ( new Type (AnyT, true)) |
static const constTypePtr | ConstVoid = TypePtr ( new Type (VoidT, true)) |
static const constTypePtr | ConstBoolean = TypePtr ( new Type (BooleanT, true)) |
static const constTypePtr | ConstByteblock = TypePtr ( new Type (ByteblockT, true)) |
static const constTypePtr | ConstFloat = TypePtr ( new Type (FloatT, true)) |
static const constTypePtr | ConstInteger = TypePtr ( new Type (IntegerT, true)) |
static const constTypePtr | ConstLocale = TypePtr ( new Type (LocaleT, true)) |
static const constTypePtr | ConstPath = TypePtr ( new Type (PathT, true)) |
static const constTypePtr | ConstString = TypePtr ( new Type (StringT, true)) |
static const constTypePtr | ConstSymbol = TypePtr ( new Type (SymbolT, true)) |
static const constTypePtr | ConstTerm = TypePtr ( new Type (TermT, true)) |
static const constTypePtr | ConstList = TypePtr ( new Type (ListT, true)) |
static const constTypePtr | ConstMap = TypePtr ( new Type (MapT, true)) |
static const constTypePtr | Flex = TypePtr ( new FlexType()) |
static const constTypePtr | ConstFlex = TypePtr ( new FlexType (true)) |
static const constTypePtr | NFlex1 = TypePtr ( new NFlexType(1)) |
static const constTypePtr | ConstNFlex1 = TypePtr ( new NFlexType (1, true)) |
static const constTypePtr | NFlex2 = TypePtr ( new NFlexType(2)) |
static const constTypePtr | ConstNFlex2 = TypePtr ( new NFlexType (2, true)) |
static const constTypePtr | NFlex3 = TypePtr ( new NFlexType(3)) |
static const constTypePtr | ConstNFlex3 = TypePtr ( new NFlexType (3, true)) |
static const constTypePtr | NFlex4 = TypePtr ( new NFlexType(4)) |
static const constTypePtr | ConstNFlex4 = TypePtr ( new NFlexType (4, true)) |
static const constTypePtr | ListUnspec = new ListType (Type::Unspec) |
static const constTypePtr | List = new ListType (Type::Any) |
static const constTypePtr | MapUnspec = new MapType (Type::Unspec, Type::Unspec) |
static const constTypePtr | Map = new MapType (Type::Any, Type::Any) |
static const constTypePtr | Variable = new VariableType (Type::Any) |
static const constTypePtr | Block = new BlockType (Type::Any) |
static const constTypePtr | Nil = TypePtr ( new Type (NilT)) |
Protected Member Functions | |
Type (tkind kind, bool as_const=false, bool as_reference=false) | |
![]() | |
virtual void | ref_to (unsigned) const |
virtual void | unref_to (unsigned) const |
Protected Attributes | |
tkind | m_kind |
bool | m_const |
bool | m_reference |
Private Member Functions | |
REP_BODY (Type) | |
tkind | kind () const |
YCP type.
typedef enum Type::type_kind Type::tkind |
enum Type::type_kind |
|
inlineprotected |
References fromSignature(), nextToken(), setNocheck(), and vt2type().
Type::Type | ( | ) |
References m_kind, and Rep::Rep().
Referenced by kind().
Type::Type | ( | tkind | kind, |
bytecodeistream & | str | ||
) |
References m_const, m_kind, m_reference, and y2debug.
|
virtual |
Referenced by kind().
|
inline |
set const qualifier
|
inline |
set reference qualifier
References basematch(), and equals().
int Type::basematch | ( | constTypePtr | expected | ) | const |
check if base matches with expected type <0: no match, ==0: full match, >0: propagated match
References AnyT, ErrorT, FlexT, isBasetype(), isConst(), isError(), isVoid(), NFlexT, UnspecT, WildcardT, and y2debug.
Referenced by asReference(), match(), VariableType::match(), ListType::match(), MapType::match(), BlockType::match(), TupleType::match(), and FunctionType::match().
|
virtual |
check, if the type can be casted (at runtime considered to be - similar to dynamic_cast) to another type
Reimplemented in FunctionType, TupleType, BlockType, MapType, and ListType.
References isAny(), match(), toString(), and y2debug.
Referenced by ListType::isBasetype(), MapType::isBasetype(), BlockType::isBasetype(), TupleType::isBasetype(), and matchFlex().
|
virtual |
clone this type
Reimplemented in FunctionType, TupleType, BlockType, MapType, ListType, VariableType, NFlexType, and FlexType.
References m_kind.
Referenced by FunctionType::canCast(), FlexType::isBasetype(), NFlexType::isBasetype(), VariableType::isBasetype(), ListType::isBasetype(), MapType::isBasetype(), BlockType::isBasetype(), TupleType::isBasetype(), matchFlex(), and unflex().
|
virtual |
Finds a type that can hold both given types This should be the narrowest such type - TODO
Reimplemented in MapType, and ListType.
References Any, isAny(), isVoid(), FunctionType::match(), FunctionType::toString(), and y2debug.
Referenced by ListType::isBasetype(), MapType::isBasetype(), and isNil().
|
virtual |
Finds a type which contains most information This should be the narrowest such type - TODO
Reimplemented in MapType, and ListType.
References Error, isAny(), isUnspec(), isVoid(), FunctionType::match(), FunctionType::toString(), and y2debug.
Referenced by ListType::isBasetype(), MapType::isBasetype(), and isNil().
|
static |
determine actual type if declared type contains 'flex' or 'flexN' Returns actual - unchanged or fixed
determine actual type if declared type contains flex type Returns actual - unchanged or fixed or NULL on error
symbol | type of a symbol parameter from YEBuiltin, else isUnspec |
References result(), y2debug, and ycp2error.
Referenced by YEBuiltin::finalize(), fromSignature(), i_check_binary_op(), and YEBinary::type().
|
virtual |
check equality of the types, without any assumptions like any == unspec
Reimplemented in FunctionType, TupleType, BlockType, MapType, ListType, and VariableType.
References isBasetype(), and m_kind.
Referenced by asReference(), VariableType::isBasetype(), ListType::isBasetype(), MapType::isBasetype(), BlockType::isBasetype(), TupleType::isBasetype(), and FunctionType::isBasetype().
|
static |
Construct from a string literal type code
Construct from a string literal type code
s | eg. "list <string>" |
References Any, AnyT, BlockT, Boolean, BooleanT, Byteblock, ByteblockT, ConstAny, ConstBoolean, ConstByteblock, ConstFlex, ConstFloat, ConstInteger, ConstLocale, ConstNFlex1, ConstNFlex2, ConstNFlex3, ConstNFlex4, ConstPath, ConstString, ConstSymbol, ConstTerm, ConstVoid, Error, ErrorT, Flex, FlexT, Float, FloatT, FunctionT, Integer, IntegerT, ListT, Locale, LocaleT, MapT, nextToken(), NFlex1, NFlex2, NFlex3, NFlex4, Path, PathT, String, StringT, Symbol, SymbolT, Term, TermT, tr(), TupleT, Unspec, UnspecT, VariableT, Void, VoidT, Wildcard, WildcardT, y2debug, and y2error.
Referenced by fromSig(), fromSignature(), StaticDeclaration::registerDeclarations(), and Type().
|
inlinestatic |
Construct from a string literal type code
s | eg. string("list <string>") |
References determineFlexType(), and fromSignature().
|
static |
Referenced by i_check_binary_op(), i_check_unary_op(), and switch().
|
inline |
References AnyT.
Referenced by canCast(), commontype(), detailedtype(), match(), and matchvalue().
|
inlinevirtual |
Reimplemented in FunctionType, TupleType, BlockType, MapType, ListType, VariableType, NFlexType, and FlexType.
Referenced by basematch(), and equals().
|
inline |
References BlockT.
|
inline |
References BooleanT.
Referenced by matchvalue().
|
inline |
References ByteblockT.
Referenced by matchvalue().
|
inline |
return const qualifier
References m_const.
Referenced by basematch(), FlexType::unflex(), and NFlexType::unflex().
|
inline |
References ErrorT.
Referenced by basematch().
|
inline |
Referenced by FlexType::unflex().
|
inline |
References FloatT.
Referenced by match(), and matchvalue().
|
inline |
References FunctionT.
|
inline |
References IntegerT.
Referenced by match(), and matchvalue().
|
inline |
References ListT.
Referenced by matchvalue().
|
inline |
References MapT.
Referenced by matchvalue().
|
inline |
References NFlexT.
Referenced by NFlexType::unflex().
|
inline |
References commontype(), detailedtype(), NilT, and valueType().
|
inline |
References PathT.
Referenced by matchvalue().
|
inline |
return reference qualifier
References m_reference.
Referenced by FlexType::unflex(), and NFlexType::unflex().
|
inline |
References StringT.
Referenced by match(), and matchvalue().
|
inline |
References SymbolT.
Referenced by matchvalue().
|
inline |
References TermT.
Referenced by matchvalue().
|
inline |
References TupleT.
|
inline |
References UnspecT.
Referenced by detailedtype(), and match().
|
inline |
References VariableT.
|
inline |
References VoidT.
Referenced by basematch(), commontype(), detailedtype(), and match().
|
inline |
References WildcardT.
|
inlineprivate |
References m_kind, str, toStream(), toString(), toXml(), toXmlString(), Type(), and ~Type().
|
virtual |
Checks match with expected type. Match is not symmetric, e.g integer match any but not vice versa.
expected | Target type against which this is matched, so integer.match(any) -> 0 <0: no match, ==0: full match, >0: propagated match |
Reimplemented in FunctionType, TupleType, BlockType, MapType, ListType, VariableType, NFlexType, and FlexType.
References AnyT, basematch(), FlexT, FloatT, IntegerT, isAny(), isFloat(), isInteger(), isLocale(), isString(), isUnspec(), isVoid(), LocaleT, m_kind, NFlexT, StringT, toString(), UnspecT, WildcardT, and y2debug.
Referenced by canCast(), FlexType::isBasetype(), NFlexType::isBasetype(), VariableType::isBasetype(), ListType::isBasetype(), MapType::isBasetype(), BlockType::isBasetype(), TupleType::isBasetype(), FunctionType::isBasetype(), and matchFlex().
|
inlinevirtual |
Reimplemented in FunctionType, TupleType, BlockType, MapType, ListType, VariableType, NFlexType, and FlexType.
References canCast(), clone(), match(), matchvalue(), and unflex().
Referenced by FlexType::isBasetype(), NFlexType::isBasetype(), VariableType::isBasetype(), ListType::isBasetype(), MapType::isBasetype(), BlockType::isBasetype(), TupleType::isBasetype(), and FunctionType::isBasetype().
|
virtual |
check match with value <0: no match, ==0: full match, >0: propagated match
References YCPMap::begin(), YCPMap::end(), isAny(), isBoolean(), isByteblock(), isFloat(), isInteger(), isList(), isMap(), YCPElement::isNull(), isPath(), isString(), isSymbol(), isTerm(), m_kind, YCPList::size(), toString(), YCPList::value(), y2debug, YT_BOOLEAN, YT_BYTEBLOCK, YT_CODE, YT_EXTERNAL, YT_FLOAT, YT_INTEGER, YT_LIST, YT_MAP, YT_PATH, YT_RETURN, YT_STRING, YT_SYMBOL, YT_TERM, and YT_VOID.
Referenced by matchFlex().
|
static |
signature parser, get next token
signature parser, get next token >= 0 -> tkind -1 -> const -100 (-x) -> NFlex '&' -> reference '<' '>' ',' '(' ')'
References AnyT, BlockT, BooleanT, ByteblockT, ErrorT, FlexT, FloatT, IntegerT, ListT, LocaleT, MapT, PathT, StringT, SymbolT, TermT, TupleT, UnspecT, VariableT, VoidT, and WildcardT.
Referenced by fromSignature(), and Type().
|
inline |
postfix qualifier
Referenced by toString(), FlexType::toString(), NFlexType::toString(), ListType::toString(), MapType::toString(), BlockType::toString(), TupleType::toString(), and FunctionType::toString().
|
inline |
prefix qualifier
Referenced by toString(), FlexType::toString(), NFlexType::toString(), ListType::toString(), MapType::toString(), BlockType::toString(), TupleType::toString(), and FunctionType::toString().
|
private |
|
static |
enable/disable type checking
Referenced by Type().
|
virtual |
write bytecode out to stream
write out to bytecode stream
Reimplemented in FunctionType, TupleType, BlockType, MapType, ListType, VariableType, NFlexType, and FlexType.
References m_const, m_kind, m_reference, str, toString(), Bytecode::writeBool(), Bytecode::writeInt32(), and y2debug.
Referenced by FunctionType::canCast(), TupleType::isBasetype(), kind(), BlockType::returnType(), FlexType::toStream(), NFlexType::toStream(), VariableType::toStream(), ListType::toStream(), MapType::toStream(), BlockType::toStream(), TupleType::toStream(), FunctionType::toStream(), ListType::type(), and MapType::valuetype().
|
virtual |
Converts a type code to its YCP notation.
Reimplemented in FunctionType, TupleType, BlockType, MapType, ListType, VariableType, NFlexType, and FlexType.
References AnyT, BlockT, BooleanT, ByteblockT, ErrorT, FlexT, FloatT, FunctionT, IntegerT, ListT, LocaleT, m_kind, MapT, NFlexT, NilT, PathT, postToString(), preToString(), StringT, SymbolT, TermT, TupleT, UnspecT, VariableT, VoidT, and WildcardT.
Referenced by canCast(), kind(), match(), matchvalue(), toStream(), and toXmlString().
|
virtual |
write xml out to stream
References m_const, m_reference, str, and toXmlString().
Referenced by kind().
|
virtual |
References toString(), and Xmlcode::xmlify().
|
virtual |
replace any 'FlexT' (number == 0) or 'NFlexT' (number != 0) with 'type'
Reimplemented in FunctionType, TupleType, BlockType, MapType, ListType, VariableType, NFlexType, and FlexType.
References clone().
Referenced by FunctionType::canCast(), FlexType::isBasetype(), NFlexType::isBasetype(), VariableType::isBasetype(), ListType::isBasetype(), MapType::isBasetype(), BlockType::isBasetype(), TupleType::isBasetype(), and matchFlex().
YCPValueType Type::valueType | ( | ) | const |
References AnyT, BlockT, BooleanT, ByteblockT, ErrorT, FlexT, FloatT, FunctionT, IntegerT, ListT, LocaleT, m_kind, MapT, NFlexT, NilT, PathT, StringT, SymbolT, TermT, TupleT, UnspecT, VariableT, VoidT, WildcardT, YT_BOOLEAN, YT_BYTEBLOCK, YT_CODE, YT_ENTRY, YT_ERROR, YT_FLOAT, YT_INTEGER, YT_LIST, YT_MAP, YT_PATH, YT_STRING, YT_SYMBOL, YT_TERM, and YT_VOID.
Referenced by isNil().
|
static |
convert YCPValueType to Type
References Any, Block, Boolean, Byteblock, Error, Float, Integer, List, Map, Path, String, Symbol, Term, Unspec, Variable, Void, YT_BOOLEAN, YT_BYTEBLOCK, YT_CODE, YT_ENTRY, YT_EXTERNAL, YT_FLOAT, YT_INTEGER, YT_LIST, YT_MAP, YT_PATH, YT_STRING, YT_SYMBOL, YT_TERM, and YT_VOID.
Referenced by Type().
Referenced by fromSignature(), i_check_compare_op(), main(), switch(), YECompare::type(), YEIs::type(), vt2type(), and while().
|
static |
Referenced by fromSignature(), main(), vt2type(), and while().
Referenced by fromSignature(), and YConst::type().
Referenced by fromSignature(), YConst::type(), and while().
|
static |
Referenced by fromSignature(), YConst::type(), and while().
|
static |
Referenced by fromSignature().
Referenced by fromSignature(), YConst::type(), and while().
Referenced by fromSignature(), YConst::type(), and while().
Referenced by fromSignature(), and YConst::type().
|
static |
Referenced by fromSignature().
|
static |
Referenced by fromSignature().
|
static |
Referenced by fromSignature().
|
static |
Referenced by fromSignature().
Referenced by fromSignature(), YConst::type(), and while().
Referenced by fromSignature(), YConst::type(), and while().
Referenced by fromSignature(), YConst::type(), and while().
Referenced by fromSignature(), and YConst::type().
Referenced by fromSignature(), YConst::type(), and while().
Referenced by attach_parameter(), YECall::attachParameter(), YEBuiltin::attachSymVariable(), detailedtype(), ListType::detailedtype(), MapType::detailedtype(), YEBuiltin::finalize(), YECall::finalize(), YEFunction::finalize(), fromSignature(), TupleType::parameterType(), FunctionType::parameterType(), Xmlcode::readType(), Bytecode::readType(), YEBuiltin::type(), and vt2type().
|
static |
Referenced by fromSignature().
Referenced by fromSignature(), main(), switch(), vt2type(), and while().
Referenced by fromSignature(), main(), switch(), vt2type(), and while().
|
static |
Referenced by switch(), and YConst::type().
Referenced by fromSignature(), main(), switch(), YELocale::type(), YLocale::type(), and while().
|
protected |
Referenced by isConst(), toStream(), toXml(), and Type().
|
protected |
Referenced by clone(), equals(), kind(), match(), matchvalue(), toStream(), toString(), Type(), and valueType().
|
protected |
Referenced by isReference(), toStream(), toXml(), and Type().
|
static |
Referenced by switch(), and YConst::type().
|
static |
Referenced by fromSignature().
|
static |
Referenced by fromSignature().
|
static |
Referenced by fromSignature().
|
static |
Referenced by fromSignature().
Referenced by fromSignature(), main(), vt2type(), and while().
Referenced by fromSignature(), main(), switch(), vt2type(), and while().
Referenced by YEBuiltin::attachSymVariable(), fromSignature(), main(), switch(), vt2type(), and while().
Referenced by fromSignature(), main(), switch(), YETerm::type(), vt2type(), and while().
Referenced by attach_parameter(), YETerm::attachParameter(), YEBuiltin::attachParameter(), YECall::attachParameter(), FunctionType::canCast(), fromSignature(), i_check_binary_op(), i_check_unary_op(), YETerm::kind(), YEBuiltin::kind(), main(), YBlock::newNamespace(), StaticDeclaration::registerDeclarations(), StaticDeclaration::StaticDeclaration(), switch(), YCode::type(), YEBinary::type(), YConst::type(), VariableType::type(), ListType::type(), YFunction::type(), MapType::valuetype(), vt2type(), Y2YCPFunction::wantedParameterType(), while(), and YBlock::YBlock().
|
static |
Referenced by vt2type().
Referenced by attach_parameter(), YECall::finalize(), fromSignature(), main(), switch(), YStatement::type(), YSExpression::type(), YSBlock::type(), YSReturn::type(), YSTypedef::type(), YSFunction::type(), YSBracket::type(), YSIf::type(), YSWhile::type(), YSRepeat::type(), YSDo::type(), YSTextdomain::type(), YSInclude::type(), YSImport::type(), YSFilename::type(), YSSwitch::type(), vt2type(), while(), YEBracket::YEBracket(), and YEBuiltin::YEBuiltin().
Referenced by fromSignature().