本文整理汇总了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());
}
}
示例2:
virtual ASTType *getType() {
if(type->isArray()) return type; //XXX bit silly?
if(alloc == STACK) return type;
//else heap alloc
return type->getReferenceTy();
}
示例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);
}
}
示例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();
}
示例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!
}
示例6: isDerivedFrom
bool ASTType::isDerivedFrom(const ASTType& that) const
{
if ( !isUnknown() && !that.isUnknown() )
{
return that.getObjectClass().isBase(getObjectClass())
|| that.getObjectClass().isImplementing(getObjectClass());
}
return false;
}
示例7: determineArrayDimension
void ASTType::determineArrayDimension()
{
mArrayDimension = 1;
ASTType* ptype = mpArrayType;
while ( ptype->isArray() )
{
ptype = ptype->mpArrayType;
mArrayDimension++;
}
}
示例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;
}
示例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;
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}