// Semantics Consulting's Tyr Library // http://www.semantics.org // // Copyright (c) 2003 by Stephen C. Dewhurst // // Permission to use, copy, modify, distribute, and sell this software // for any purpose is hereby granted without fee, provided that the above // copyright notice appears in all copies and that both that copyright // notice and this permission notice appear in supporting documentation. // The author makes no representations about the suitability of this // software for any purpose. It is provided "as is" without express // or implied warranty. // "typeof" operator implementation // // Described in CUJ 20(8, 10, and 12), August, October, and December 2002: "A Bit-Wise Typeof" // This version is a re-write of the original implementation that employs the typeint implementation // of extended precision compile time arithmetic. Typeints are described in CUJ online experts // column, February 2003. #ifndef GENTYPE_H #define GENTYPE_H #include "typeint.h" namespace Tyr { // // Regenerating a type from a Godel number. // template struct GenType; template struct ModSwitch; template struct ModSwitch { // * typedef typename GenType::GTR *MSR; }; template struct ModSwitch { // * const typedef typename GenType::GTR * const MSR; }; template struct ModSwitch { // * volatile typedef typename GenType::GTR * volatile MSR; }; template struct ModSwitch { // * const volatile typedef typename GenType::GTR * const volatile MSR; }; template struct ModSwitch { // & typedef typename GenType::GTR &MSR; }; template struct ModSwitch { // [N] enum { bound = Value::R>::r }; typedef typename GenType::R>::GTR MSR[bound]; }; template struct ModSwitch { // C::* // Note: BaseLen, not QualBaseLen! typedef typename GenType::R>::GTR MemType; typedef typename DeCode::R>::r>::R ClassType; typedef MemType ClassType::*MSR; }; template struct ModSwitch { // C::*const typedef const typename ModSwitch::MSR MSR; }; template struct ModSwitch { // C::*volatile typedef volatile typename ModSwitch::MSR MSR; }; template struct ModSwitch { // C::*const volatile typedef const volatile typename ModSwitch::MSR MSR; }; template struct FunSwitch; template struct FunSwitch<0,Code> { typedef typename GenType::GTR RetType; typedef RetType FSR(void); }; template struct FunSwitch<1,Code> { typedef typename TypeInt<(1<::R ArglenLenMaskT; typedef typename And::R ArgLenT; enum { arglen = Value::r }; typedef typename RShift::R T1; enum { argshiftlen = (CodeLen*NumCodes)-(arglen+ArglenLen) }; typedef typename LShift::R T2; typedef typename RShift::R T3; typedef typename GenType::GTR RetType; typedef typename GenType::GTR ArgType; typedef RetType FSR( ArgType ); }; template struct ModSwitch { // () typedef typename RShift::R T1; typedef typename TypeInt<(1<::R ArgcountLenMaskT; typedef typename And::R ArgcountT; enum { argcount = Value::r }; typedef typename FunSwitch::FSR MSR; }; template struct ModSwitch { // R (C::*)(void) // Note: BaseLen, not QualBaseLen! typedef typename And::R ClassCode; enum { classtype = Value::r, shiftamt = BaseLen+ArgcountLen+ModLen // pop off class code, 0 (arg count), and Fun mod }; typedef typename RShift::R T1; typedef typename FunSwitch<0,T1>::RetType RetType; typedef typename DeCode::R ClassType; typedef RetType (ClassType::*MSR)(); }; template struct ModSwitch { // R (C::*)(void) const // Note: BaseLen, not QualBaseLen! typedef typename And::R ClassCode; enum { classtype = Value::r, shiftamt = BaseLen+ArgcountLen+ModLen // pop off class code, 0 (arg count), and Fun mod }; typedef typename RShift::R T1; typedef typename FunSwitch<0,T1>::RetType RetType; typedef typename DeCode::R ClassType; typedef RetType (ClassType::*MSR)() const; }; template struct ModSwitch { // R (C::*)(void) volatile // Note: BaseLen, not QualBaseLen! typedef typename And::R ClassCode; enum { classtype = Value::r, shiftamt = BaseLen+ArgcountLen+ModLen // pop off class code, 0 (arg count), and Fun mod }; typedef typename RShift::R T1; typedef typename FunSwitch<0,T1>::RetType RetType; typedef typename DeCode::R ClassType; typedef RetType (ClassType::*MSR)() volatile; }; template struct ModSwitch { // R (C::*)(void) const volatile // Note: BaseLen, not QualBaseLen! typedef typename And::R ClassCode; enum { classtype = Value::r, shiftamt = BaseLen+ArgcountLen+ModLen // pop off class code, 0 (arg count), and Fun mod }; typedef typename RShift::R T1; typedef typename FunSwitch<0,T1>::RetType RetType; typedef typename DeCode::R ClassType; typedef RetType (ClassType::*MSR)() const volatile; }; template struct ModSwitch { // R (C::*)(A) // Note: BaseLen, not QualBaseLen! typedef typename And::R ClassCode; enum { classtype = Value::r, shiftamt = BaseLen+ArgcountLen+ModLen // pop off class code, 1 (arg count), and Fun mod }; typedef typename RShift::R T1; typedef FunSwitch<1,T1> Fun; typedef typename Fun::RetType RetType; typedef typename Fun::ArgType ArgType; typedef typename DeCode::R ClassType; typedef RetType (ClassType::*MSR)(ArgType); }; template struct ModSwitch { // R (C::*)(A) const // Note: BaseLen, not QualBaseLen! typedef typename And::R ClassCode; enum { classtype = Value::r, shiftamt = BaseLen+ArgcountLen+ModLen // pop off class code, 1 (arg count), and Fun mod }; typedef typename RShift::R T1; typedef FunSwitch<1,T1> Fun; typedef typename Fun::RetType RetType; typedef typename Fun::ArgType ArgType; typedef typename DeCode::R ClassType; typedef RetType (ClassType::*MSR)(ArgType) const; }; template struct ModSwitch { // R (C::*)(A) volatile // Note: BaseLen, not QualBaseLen! typedef typename And::R ClassCode; enum { classtype = Value::r, shiftamt = BaseLen+ArgcountLen+ModLen // pop off class code, 1 (arg count), and Fun mod }; typedef typename RShift::R T1; typedef FunSwitch<1,T1> Fun; typedef typename Fun::RetType RetType; typedef typename Fun::ArgType ArgType; typedef typename DeCode::R ClassType; typedef RetType (ClassType::*MSR)(ArgType) volatile; }; template struct ModSwitch { // R (C::*)(A) const volatile // Note: BaseLen, not QualBaseLen! typedef typename And::R ClassCode; enum { classtype = Value::r, shiftamt = BaseLen+ArgcountLen+ModLen // pop off class code, 1 (arg count), and Fun mod }; typedef typename RShift::R T1; typedef FunSwitch<1,T1> Fun; typedef typename Fun::RetType RetType; typedef typename Fun::ArgType ArgType; typedef typename DeCode::R ClassType; typedef RetType (ClassType::*MSR)(ArgType) const volatile; }; //====================================================================== template struct GenModType { enum { mod = Value::R>::r }; typedef typename ModSwitch::R>::MSR MR; }; template struct GenBaseType { enum { base = Value::R>::r, isconst = Value::R>::r, isvol = Value::R>::r }; typedef typename DeCode::R B; typedef typename Select::R CB; typedef typename Select::R VCB; typedef VCB R; }; template struct GenTypeImpl { typedef typename GenBaseType::R R; }; template struct GenTypeImpl { typedef typename GenModType::MR R; }; template struct GenType { // Indirection necessary to avoid instantiating both possibilities. //typedef typename GenTypeImpl::R GTR; //typedef typename GenTypeImpl::R>::r,Code>::R GTR; enum { lhs = Value::r, rhs = 1<::R GTR; }; } // namespace Tyr #endif