本文整理汇总了C++中TypeClass类的典型用法代码示例。如果您正苦于以下问题:C++ TypeClass类的具体用法?C++ TypeClass怎么用?C++ TypeClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TypeClass类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visit
void VisitorNodeTyper::visit(ExprOP2 *n){
n->getLeft()->accept(*this);
TypeClass* tc = dynamic_cast<TypeClass*>(n->getLeft()->getType());
Class* old_cur_class = this->cur_class;
this->cur_class = tc ? tc->getClass() : 0;
n->getRight()->accept(*this);
// Type of binary operator is type of operands (with promotion), except for comparison operators
if ( n->getOperator() == ExprOP2::LT || n->getOperator() == ExprOP2::LTE
|| n->getOperator() == ExprOP2::GT || n->getOperator() == ExprOP2::GTE
|| n->getOperator() == ExprOP2::EQ || n->getOperator() == ExprOP2::NEQ
)
{
n->setType(TypePrimary::getBool());
}
else if (n->getOperator() == ExprOP2::DOT)
{
if (!tc)
throw __FILE__ "(" QUOTE(__LINE__) "): Left hand side of . operator must be an object / class.";
n->setType(n->getRight()->getType());
}
else if (n->getOperator() == ExprOP2::ARRAY)
{
// TODO Check rhs type
TypeArray* ta = dynamic_cast<TypeArray*>(n->getLeft()->getType());
if (!ta)
throw __FILE__ "(" QUOTE(__LINE__) "): Left hand side of [] operator must be an array.";
n->setType(ta->getType());
}
else // All other operators
{
n->setType(n->getLeft()->getType());
}
this->cur_class = old_cur_class;
}
示例2: toChars
void ClassDeclaration::semantic(Scope *sc)
{
//printf("ClassDeclaration::semantic(%s), type = %p, sizeok = %d, this = %p\n", toChars(), type, sizeok, this);
//printf("\tparent = %p, '%s'\n", sc->parent, sc->parent ? sc->parent->toChars() : "");
//printf("sc->stc = %x\n", sc->stc);
//{ static int n; if (++n == 20) *(char*)0=0; }
if (!ident) // if anonymous class
{ const char *id = "__anonclass";
ident = Identifier::generateId(id);
}
if (!sc)
sc = scope;
if (!parent && sc->parent && !sc->parent->isModule())
parent = sc->parent;
type = type->semantic(loc, sc);
if (type->ty == Tclass && ((TypeClass *)type)->sym != this)
{
TemplateInstance *ti = ((TypeClass *)type)->sym->isInstantiated();
if (ti && ti->errors)
((TypeClass *)type)->sym = this;
}
if (!members) // if opaque declaration
{ //printf("\tclass '%s' is forward referenced\n", toChars());
return;
}
if (symtab)
{ if (sizeok == SIZEOKdone || !scope)
{ //printf("\tsemantic for '%s' is already completed\n", toChars());
return; // semantic() already completed
}
}
else
symtab = new DsymbolTable();
Scope *scx = NULL;
if (scope)
{
sc = scope;
scx = scope; // save so we don't make redundant copies
scope = NULL;
}
unsigned dprogress_save = Module::dprogress;
int errors = global.errors;
if (sc->stc & STCdeprecated)
{
isdeprecated = true;
}
userAttribDecl = sc->userAttribDecl;
if (sc->linkage == LINKcpp)
cpp = 1;
// Expand any tuples in baseclasses[]
for (size_t i = 0; i < baseclasses->dim; )
{
// Ungag errors when not speculative
Ungag ungag = ungagSpeculative();
BaseClass *b = (*baseclasses)[i];
b->type = b->type->semantic(loc, sc);
Type *tb = b->type->toBasetype();
if (tb->ty == Ttuple)
{ TypeTuple *tup = (TypeTuple *)tb;
PROT protection = b->protection;
baseclasses->remove(i);
size_t dim = Parameter::dim(tup->arguments);
for (size_t j = 0; j < dim; j++)
{ Parameter *arg = Parameter::getNth(tup->arguments, j);
b = new BaseClass(arg->type, protection);
baseclasses->insert(i + j, b);
}
}
else
i++;
}
// See if there's a base class as first in baseclasses[]
if (baseclasses->dim)
{
// Ungag errors when not speculative
Ungag ungag = ungagSpeculative();
BaseClass *b = (*baseclasses)[0];
//b->type = b->type->semantic(loc, sc);
Type *tb = b->type->toBasetype();
if (tb->ty != Tclass)
{
if (b->type != Type::terror)
error("base type must be class or interface, not %s", b->type->toChars());
baseclasses->remove(0);
//.........这里部分代码省略.........
示例3: DtoType
LLType* DtoType(Type* t)
{
t = stripModifiers( t );
if (t->ctype)
{
return t->ctype->getLLType();
}
IF_LOG Logger::println("Building type: %s", t->toChars());
LOG_SCOPE;
assert(t);
switch (t->ty)
{
// basic types
case Tvoid:
case Tint8:
case Tuns8:
case Tint16:
case Tuns16:
case Tint32:
case Tuns32:
case Tint64:
case Tuns64:
case Tint128:
case Tuns128:
case Tfloat32:
case Tfloat64:
case Tfloat80:
case Timaginary32:
case Timaginary64:
case Timaginary80:
case Tcomplex32:
case Tcomplex64:
case Tcomplex80:
//case Tbit:
case Tbool:
case Tchar:
case Twchar:
case Tdchar:
{
return IrTypeBasic::get(t)->getLLType();
}
// pointers
case Tnull:
case Tpointer:
{
return IrTypePointer::get(t)->getLLType();
}
// arrays
case Tarray:
{
return IrTypeArray::get(t)->getLLType();
}
case Tsarray:
{
return IrTypeSArray::get(t)->getLLType();
}
// aggregates
case Tstruct:
{
TypeStruct* ts = static_cast<TypeStruct*>(t);
if (ts->sym->type->ctype)
{
// This should not happen, but the frontend seems to be buggy. Not
// sure if this is the best way to handle the situation, but we
// certainly don't want to override ts->sym->type->ctype.
IF_LOG Logger::cout() << "Struct with multiple Types detected: " <<
ts->toChars() << " (" << ts->sym->locToChars() << ")" << std::endl;
return ts->sym->type->ctype->getLLType();
}
return IrTypeStruct::get(ts->sym)->getLLType();
}
case Tclass:
{
TypeClass* tc = static_cast<TypeClass*>(t);
if (tc->sym->type->ctype)
{
// See Tstruct case.
IF_LOG Logger::cout() << "Class with multiple Types detected: " <<
tc->toChars() << " (" << tc->sym->locToChars() << ")" << std::endl;
return tc->sym->type->ctype->getLLType();
}
return IrTypeClass::get(tc->sym)->getLLType();
}
// functions
case Tfunction:
{
return IrTypeFunction::get(t)->getLLType();
}
// delegates
case Tdelegate:
{
//.........这里部分代码省略.........
示例4: toChars
void ClassDeclaration::semantic(Scope *sc)
{
//printf("ClassDeclaration::semantic(%s), type = %p, sizeok = %d, this = %p\n", toChars(), type, sizeok, this);
//printf("\tparent = %p, '%s'\n", sc->parent, sc->parent ? sc->parent->toChars() : "");
//printf("sc->stc = %x\n", sc->stc);
//{ static int n; if (++n == 20) *(char*)0=0; }
if (!ident) // if anonymous class
{ const char *id = "__anonclass";
ident = Identifier::generateId(id);
}
if (!sc)
sc = scope;
if (!parent && sc->parent && !sc->parent->isModule())
parent = sc->parent;
type = type->semantic(loc, sc);
handle = type;
if (!members) // if forward reference
{ //printf("\tclass '%s' is forward referenced\n", toChars());
return;
}
if (symtab)
{ if (sizeok == SIZEOKdone || !scope)
{ //printf("\tsemantic for '%s' is already completed\n", toChars());
return; // semantic() already completed
}
}
else
symtab = new DsymbolTable();
Scope *scx = NULL;
if (scope)
{ sc = scope;
scx = scope; // save so we don't make redundant copies
scope = NULL;
}
unsigned dprogress_save = Module::dprogress;
int errors = global.gaggedErrors;
if (sc->stc & STCdeprecated)
{
isdeprecated = true;
}
userAttributes = sc->userAttributes;
if (sc->linkage == LINKcpp)
error("cannot create C++ classes");
// Expand any tuples in baseclasses[]
for (size_t i = 0; i < baseclasses->dim; )
{ BaseClass *b = (*baseclasses)[i];
b->type = b->type->semantic(loc, sc);
Type *tb = b->type->toBasetype();
if (tb->ty == Ttuple)
{ TypeTuple *tup = (TypeTuple *)tb;
enum PROT protection = b->protection;
baseclasses->remove(i);
size_t dim = Parameter::dim(tup->arguments);
for (size_t j = 0; j < dim; j++)
{ Parameter *arg = Parameter::getNth(tup->arguments, j);
b = new BaseClass(arg->type, protection);
baseclasses->insert(i + j, b);
}
}
else
i++;
}
// See if there's a base class as first in baseclasses[]
if (baseclasses->dim)
{ TypeClass *tc;
BaseClass *b;
Type *tb;
b = (*baseclasses)[0];
//b->type = b->type->semantic(loc, sc);
tb = b->type->toBasetype();
if (tb->ty != Tclass)
{ if (b->type != Type::terror)
error("base type must be class or interface, not %s", b->type->toChars());
baseclasses->remove(0);
}
else
{
tc = (TypeClass *)(tb);
if (tc->sym->isDeprecated())
{
if (!isDeprecated())
{
// Deriving from deprecated class makes this one deprecated too
isdeprecated = true;
tc->checkDeprecated(loc, sc);
//.........这里部分代码省略.........
示例5: stripModifiers
LLType *DtoType(Type *t) {
t = stripModifiers(t);
if (t->ctype) {
return t->ctype->getLLType();
}
IF_LOG Logger::println("Building type: %s", t->toChars());
LOG_SCOPE;
assert(t);
switch (t->ty) {
// basic types
case Tvoid:
case Tint8:
case Tuns8:
case Tint16:
case Tuns16:
case Tint32:
case Tuns32:
case Tint64:
case Tuns64:
case Tint128:
case Tuns128:
case Tfloat32:
case Tfloat64:
case Tfloat80:
case Timaginary32:
case Timaginary64:
case Timaginary80:
case Tcomplex32:
case Tcomplex64:
case Tcomplex80:
// case Tbit:
case Tbool:
case Tchar:
case Twchar:
case Tdchar: {
return IrTypeBasic::get(t)->getLLType();
}
// pointers
case Tnull:
case Tpointer:
case Treference: { // CALYPSO
return IrTypePointer::get(t)->getLLType();
}
// arrays
case Tarray: {
return IrTypeArray::get(t)->getLLType();
}
case Tsarray: {
return IrTypeSArray::get(t)->getLLType();
}
// aggregates
case Tstruct: {
TypeStruct *ts = static_cast<TypeStruct *>(t);
if (ts->sym->type->ctype) {
// This should not happen, but the frontend seems to be buggy. Not
// sure if this is the best way to handle the situation, but we
// certainly don't want to override ts->sym->type->ctype.
IF_LOG Logger::cout()
<< "Struct with multiple Types detected: " << ts->toChars() << " ("
<< ts->sym->locToChars() << ")" << std::endl;
return ts->sym->type->ctype->getLLType();
}
return IrTypeStruct::get(ts->sym)->getLLType();
}
case Tclass: {
TypeClass *tc = static_cast<TypeClass *>(t);
if (tc->sym->type->ctype) {
// See Tstruct case.
IF_LOG Logger::cout()
<< "Class with multiple Types detected: " << tc->toChars() << " ("
<< tc->sym->locToChars() << ")" << std::endl;
return tc->sym->type->ctype->getLLType();
}
return IrTypeClass::get(tc->sym)->getLLType();
}
// functions
case Tfunction: {
return IrTypeFunction::get(t)->getLLType();
}
// delegates
case Tdelegate: {
return IrTypeDelegate::get(t)->getLLType();
}
// typedefs
// enum
// FIXME: maybe just call toBasetype first ?
case Tenum: {
Type *bt = t->toBasetype();
assert(bt);
//.........这里部分代码省略.........
示例6: TypeClass
void VisitorNodeTyper::visit(ExprClass *n){
TypeClass* tc = new TypeClass(n->getClass());
tc->setStatic(true);
n->setType(tc);
}
示例7: switch
void ClassSpecifierAst::walk()
{
if (checkIsNotWalking()) {
return ;
}
switch (nodeType){
case T_CCLASSSF_CLASS_ID_CLASSDECTIONLIST:{
//std::cout << "walk in T_CCLASSSF_CLASS_ID_CLASSDECTIONLIST" << endl;
LogiMsg::logi("walk in T_CCLASSSF_CLASS_ID_CLASSDECTIONLIST", getLineno());
childs.at(0)->walk();
if (checkIsNotWalking()) {
return ;
}
//Scope *tmpScope = new Scope();
if (Scope::resolveScope(s_context->tmpIdenName, Scope::SCOPE_CLASS))
{
/*std::cout << "error in T_CCLASSSF_CLASS_ID_CLASSDECTIONLIST: " << s_context->tmpIdenName
<< " has been defined at line " << getLineno() << std::endl;*/
string errorStr = "error in T_CCLASSSF_CLASS_ID_CLASSDECTIONLIST: "
+ s_context->tmpIdenName + " has been defined";
LogiMsg::logi(errorStr, getLineno());
stopWalk();
return ;
}
Scope *tmpScope = new Scope();
tmpScope->setTotalByteSize(0);
tmpScope->setTotalFuncByteSize(0);
tmpScope->initClassScope(s_context->tmpIdenName);
Scope::pushScope(Scope::s_curScope,tmpScope);
Scope::setCurScope(tmpScope);
childs.at(1)->walk();
if (checkIsNotWalking()) {
return ;
}
Scope::setCurScope(Scope::encloseScope(Scope::s_curScope));
//std::cout<<"safsadfafasfsafasf"<<Scope::s_curScope->scopeName<<std::endl;
TypeClass tmp;
//tmp.scopeType = tmpScope;
tmp.setScopeType(tmpScope);
tmp.typeSfType = TypeClass::SF_INT;
s_context->clearContext();
s_context->tmpDeclType.clone(&tmp);
break;
}
case T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST:{
//std::cout << "walk in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST" << endl;
LogiMsg::logi("walk in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST", getLineno());
childs.at(0)->walk();
if (checkIsNotWalking()) {
return ;
}
//Scope *tmpScope = new Scope();
if (Scope::resolveScope(s_context->tmpIdenName, Scope::SCOPE_CLASS))
{
/*std::cout << "error in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST: "
<< s_context->tmpIdenName << " has been defined at line " << getLineno() << std::endl;*/
string errorStr = "error in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST: "
+ s_context->tmpIdenName + " has been defined";
LogiMsg::logi(errorStr, getLineno());
stopWalk();
return ;
}
//tmpScope->initClassScope(s_context->tmpIdenName);
if (childs.at(1)->nodeType!=T_CTERMINATE_CIDLIST_ID)
{
/*std::cout << "sorry in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST: our compiler do not support multiple inheritance at line "
<< getLineno() << std::endl;*/
LogiMsg::logi("sorry in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST: our compiler do not support multiple inheritance",
getLineno());
stopWalk();
return ;
}
Scope *tmpScope = new Scope();
tmpScope->initClassScope(s_context->tmpIdenName);
childs.at(1)->walk();
if (checkIsNotWalking()) {
return ;
}
Scope *superScope = Scope::resolveScope(s_context->tmpIdenName, Scope::SCOPE_CLASS);
if (!superScope)
{
//.........这里部分代码省略.........