当前位置: 首页>>代码示例>>C++>>正文


C++ ASTType类代码示例

本文整理汇总了C++中ASTType的典型用法代码示例。如果您正苦于以下问题:C++ ASTType类的具体用法?C++ ASTType怎么用?C++ ASTType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ASTType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: checkUnknown

void SymbolCheckVisitor::checkUnknown(const ASTType& type)
{
   if ( type.isUnknown() )
   {
      error(E0051, UTEXT("Unknown class type ") + type.getObjectName(), type.getPosition());
   }
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:7,代码来源:symbolcheckstep.cpp

示例2:

    virtual ASTType *getType() {
        if(type->isArray()) return type; //XXX bit silly?
        if(alloc == STACK) return type;

        //else heap alloc
        return type->getReferenceTy();
    }
开发者ID:bsurmanski,项目名称:wlc,代码行数:7,代码来源:ast.hpp

示例3: CollectCustomTypes_TemplateArguments

	void CollectCustomTypes_TemplateArguments(bool verbose = false)
	{
		auto templateArguments = tools::LINQSelect(allChildren, [](ASTNode* it) { return it->GetType() == ASTNode::Type::TemplateArg; });
		for (auto it : templateArguments)
		{
			ASTType* itType = (ASTType*)it;
			if (itType->ToIdentifierString().empty() == false)
				continue; // template argument does not define a type
			if (itType->HasModifier(CxxToken::Type::Class) == false && itType->HasModifier(CxxToken::Type::Typename))
				continue; // template argument does not have "class" or "typename"

			auto parents = it->GatherParents();
			auto scopes = tools::LINQSelect(parents, [](ASTNode* it) { return it->GetType() == ASTNode::Type::Namespace || it->GetType() == ASTNode::Type::Template || (it->GetType() >= ASTNode::Type::Class && it->GetType() <= ASTNode::Type::Union); });
			std::reverse(scopes.begin(), scopes.end());

			std::string v;
			for (auto itScope : scopes)
			{
				v.append(itScope->ToString());
				v.append("::");
			}

			v.append(itType->ToNameString());
			if (verbose)
			{
				fprintf(stderr, "CollectCustomType_TemplateArgument: %s\n", v.c_str());
			}


			CollectCustomTypes_Add(v, it);
		}
	}
开发者ID:Lssikkes,项目名称:CppReflector,代码行数:32,代码来源:moduleCppTransfiguration.cpp

示例4: if

// static
ASTType ASTType::greaterType(const ASTType& left, const ASTType& right)
{
   if ( left.greater(right) )
      return right;
   else if ( right.greater(left) )
      return left;

   return ASTType();
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:10,代码来源:asttype.cpp

示例5: visitChildren

void SymbolCheckVisitor::visit(ASTArrayInit& ast)
{
   visitChildren(ast);

   ASTType elementtype = mCurrentType;

   mCurrentType.setKind(ASTType::eArray);
   mCurrentType.setArrayType(elementtype.clone());
   mCurrentType.setArrayDimension(1); // need to determine the depth of the array!
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:10,代码来源:symbolcheckstep.cpp

示例6: isDerivedFrom

bool ASTType::isDerivedFrom(const ASTType& that) const
{
   if ( !isUnknown() && !that.isUnknown() )
   {
      return that.getObjectClass().isBase(getObjectClass())
          || that.getObjectClass().isImplementing(getObjectClass());
   }

   return false;
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:10,代码来源:asttype.cpp

示例7: determineArrayDimension

void ASTType::determineArrayDimension()
{
   mArrayDimension = 1;
   ASTType* ptype = mpArrayType;
   while ( ptype->isArray() )
   {
      ptype = ptype->mpArrayType;
      mArrayDimension++;
   }
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:10,代码来源:asttype.cpp

示例8: ASTType

// static 
ASTType* ASTType::fromString(const String& type)
{
   std::size_t pos = type.lastIndexOf('[');
   if ( pos != String::npos )
   {
      String arraytype = type.subStr(0, pos);
      ASTType* parray = new ASTType(ASTType::eArray);
      parray->setArrayType(fromString(arraytype));
      parray->determineArrayDimension();
      return parray;
   }

   if ( type == SBool )
   {
      return new ASTType(ASTType::eBoolean);
   }
   else if ( type == SInt  )
   {
      return new ASTType(ASTType::eInt);
   }
   else if ( type == SReal )
   {
      return new ASTType(ASTType::eReal);
   }
   else if ( type == SChar )
   {
      return new ASTType(ASTType::eChar);
   }
   else if ( type == SString )
   {
      return new ASTType(ASTType::eString);
   }
   else if ( type == SVoid )
   {
      return new ASTType(ASTType::eVoid);
   }
   else
   {
      String value;

      // todo, what with generics?
      ASTType::Kind kind = ASTType::eObject;
      if ( type[0] == '~' ) {
         kind = ASTType::eGeneric;
         value = type.subStr(1, type.length() - 1);
      }
      else
         value = type;

      ASTType* ptype = new ASTType(kind);
      ptype->setObjectName(value);
      return ptype;
   }
   return NULL;
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:56,代码来源:asttype.cpp

示例9: if

void CodeGeneratorVisitor::visit(const ASTCast& ast)
{
   ast.getNode().accept(*this);

   ASTType from = mCurrentType;
   mCurrentType = ast.getType();

   // add cast instruction
   if ( mCurrentType.isObject() )
   {
   }
   else if ( mCurrentType.isArray() )
   {
   }
   else
   {
      switch ( from.getKind() )
      {
         case ASTType::eBoolean:
            if ( mCurrentType.isString() )
               mBuilder.emit(CIL_bconv_str);
            break;
         case ASTType::eInt:
            if ( mCurrentType.isReal() )
               mBuilder.emit(CIL_iconv_real);
            else if ( mCurrentType.isString() )
               mBuilder.emit(CIL_iconv_str);
            break;
         case ASTType::eReal:
            if ( mCurrentType.isInt() )
               mBuilder.emit(CIL_rconv_int);
            else if ( mCurrentType.isString() )
               mBuilder.emit(CIL_rconv_str);
            break;
         case ASTType::eChar:
            if ( mCurrentType.isString() )
               mBuilder.emit(CIL_cconv_str);
            break;
         case ASTType::eString:
            if ( mCurrentType.isBoolean() )
               mBuilder.emit(CIL_sconv_bool);
            else if ( mCurrentType.isInt() )
               mBuilder.emit(CIL_sconv_int);
            else if ( mCurrentType.isReal() )
               mBuilder.emit(CIL_rconv_str);
            break;
         default:
            break;
      }
   }
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:51,代码来源:codegeneratorvisitor.cpp

示例10: visit

void SymbolCheckVisitor::visit(ASTExpression& ast)
{
   mCurrentType.clear();

   ast.getLeft().accept(*this);

   if ( ast.hasRight() )
   {
      ASTType lefttype = mCurrentType;

      mCurrentType.clear();

      if ( isVariable(ast.getLeft()) )
      {
         ast.getRight().accept(*this);

         if ( !mCurrentType.greater(lefttype) )
         {
            error(E0020, UTEXT("Invalid type for assignment. Can not assign ") + mCurrentType.toString() + UTEXT(" to ") + lefttype.toString(), ast);
         }
      }
      else
      {
         error(E0021, UTEXT("Can only assign to variables."), ast);
      }
   }
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:27,代码来源:symbolcheckstep.cpp

示例11: checkCondition

void SymbolCheckVisitor::checkCondition(const ASTNode& node, const ASTType& type)
{
   if ( !type.isBoolean() )
   {
      error(E0008, UTEXT("Condition expression must return a boolean value."), node);
   }
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:7,代码来源:symbolcheckstep.cpp

示例12: scope

void SymbolCheckVisitor::visit(ASTForeach& ast)
{
   ScopedScope scope(mScopeStack);

   ASTVariable& iteratorvar = ast.getIteratorVariable();
   ASTVariable& var = ast.getVariable();

   if ( var.hasInit() )
   {
      ASTVariableInit& varinit = var.getInit();
      varinit.getExpression().accept(*this);

      ASTClass& iterableclass = mContext.resolveClass(UTEXT("engine.collections.Iterable"));
      ASTType* piteratortype = new ASTType();

      if ( mCurrentType.isObject() )
      {
         if( mCurrentType.getObjectClass().isImplementing(iterableclass) )
         {
            piteratortype->setKind(ASTType::eObject);
            piteratortype->setObjectClass(iterableclass);
         }
         else
         {
            error(E0009, UTEXT("Container ") + var.getName() + UTEXT(" must be iterable for use in foreach."), ast);
         }
      }
      else if ( mCurrentType.isArray() )
      {
         piteratortype->setKind(ASTType::eInt);
      }

      iteratorvar.setType(piteratortype);
   }
   else
   {
      error(E0010, UTEXT("Missing required initializer for foreach variable ") + var.getName(), ast);
   }

   mpFunction->addLocal(iteratorvar.getType().clone());
   mpFunction->addLocal(var.getType().clone());

   ScopeVariable* pvariable = ScopeVariable::fromVariable(var);
   mScopeStack.add(pvariable);

   ast.getBody().accept(*this);
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:47,代码来源:symbolcheckstep.cpp

示例13: getType

Expression *Expression::coerceTo(ASTType *ty) {
    ASTType *expty = getType();

    if(expty->is(ty)) {
        return this;
    }

    if(coercesTo(ty)) {
        //TODO: note in AST that this is implicit
        return new CastExpression(ty, this, loc);
    }

    emit_message(msg::ERROR, "attempt to coerce expression of type '" + expty->getName() +
            "' to incompatible type '" + ty->getName() + "'", loc);

    return NULL;
}
开发者ID:bsurmanski,项目名称:wlc,代码行数:17,代码来源:ast.cpp

示例14: getLongTy

//TODO XXX
ASTType *DotExpression::getType() {
    if(rhs == "sizeof" || rhs == "offsetof") {
        return ASTType::getLongTy();
    }

    ASTType *lhstype = lhs->getType();

    if(rhs == "ptr" && lhstype->isArray()) {
        return lhstype->asArray()->arrayOf->getPointerTy();
    }

    if(rhs == "size" && lhstype->isArray()) {
        return ASTType::getLongTy();
    }


    //if type is pointer, implicit dereference on dot expression
    if(lhstype->asPointer()) {
        lhstype = lhstype->asPointer()->ptrTo;
    }

    if(ASTUserType *uty = lhstype->asUserType()) {
        Identifier *dotid = uty->getDeclaration()->lookup(rhs);
        if(dotid) return dotid->getType();
    }

    return NULL;
}
开发者ID:bsurmanski,项目名称:wlc,代码行数:29,代码来源:ast.cpp

示例15: equals

bool ASTType::equals(const ASTType& that) const
{
   if ( (isObject() || isArray()) && that.isNull() )
   {
      return true;
   }

   return mKind == that.mKind
       && (isObject() ? mpObjectClass == that.mpObjectClass : true);
}
开发者ID:crafter2d,项目名称:crafter2d,代码行数:10,代码来源:asttype.cpp


注:本文中的ASTType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。