forked from OSchip/llvm-project
Added a new expression, OCUVectorComponent.
llvm-svn: 40577
This commit is contained in:
parent
ac3a364c51
commit
f7a5da17d9
|
@ -571,3 +571,13 @@ bool Expr::isNullPointerConstant(ASTContext &Ctx) const {
|
||||||
llvm::APSInt Val(32);
|
llvm::APSInt Val(32);
|
||||||
return isIntegerConstantExpr(Val, Ctx, 0, true) && Val == 0;
|
return isIntegerConstantExpr(Val, Ctx, 0, true) && Val == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OCUVectorComponent::ComponentType OCUVectorComponent::getComponentType() const {
|
||||||
|
// derive the component type, no need to waste space.
|
||||||
|
const char *compStr = Accessor.getName();
|
||||||
|
const OCUVectorType *VT = getType()->isOCUVectorType();
|
||||||
|
if (VT->isPointAccessor(*compStr)) return Point;
|
||||||
|
if (VT->isColorAccessor(*compStr)) return Color;
|
||||||
|
if (VT->isTextureAccessor(*compStr)) return Texture;
|
||||||
|
assert(0 && "getComponentType(): Illegal accessor");
|
||||||
|
}
|
||||||
|
|
|
@ -439,6 +439,11 @@ void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
|
||||||
assert(Field && "MemberExpr should alway reference a field!");
|
assert(Field && "MemberExpr should alway reference a field!");
|
||||||
OS << Field->getName();
|
OS << Field->getName();
|
||||||
}
|
}
|
||||||
|
void StmtPrinter::VisitOCUVectorComponent(OCUVectorComponent *Node) {
|
||||||
|
PrintExpr(Node->getBase());
|
||||||
|
OS << ".";
|
||||||
|
OS << Node->getAccessor().getName();
|
||||||
|
}
|
||||||
void StmtPrinter::VisitCastExpr(CastExpr *Node) {
|
void StmtPrinter::VisitCastExpr(CastExpr *Node) {
|
||||||
OS << "(" << Node->getType().getAsString() << ")";
|
OS << "(" << Node->getType().getAsString() << ")";
|
||||||
PrintExpr(Node->getSubExpr());
|
PrintExpr(Node->getSubExpr());
|
||||||
|
|
|
@ -631,6 +631,13 @@ void VectorType::getAsStringInternal(std::string &S) const {
|
||||||
ElementType.getAsStringInternal(S);
|
ElementType.getAsStringInternal(S);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OCUVectorType::getAsStringInternal(std::string &S) const {
|
||||||
|
S += " __attribute__((ocu_vector_type(";
|
||||||
|
S += llvm::utostr_32(NumElements);
|
||||||
|
S += ")))";
|
||||||
|
ElementType.getAsStringInternal(S);
|
||||||
|
}
|
||||||
|
|
||||||
void FunctionTypeNoProto::getAsStringInternal(std::string &S) const {
|
void FunctionTypeNoProto::getAsStringInternal(std::string &S) const {
|
||||||
// If needed for precedence reasons, wrap the inner part in grouping parens.
|
// If needed for precedence reasons, wrap the inner part in grouping parens.
|
||||||
if (!S.empty())
|
if (!S.empty())
|
||||||
|
|
|
@ -423,8 +423,7 @@ ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
|
||||||
QualType ret = CheckOCUVectorComponent(BaseType, OpLoc, Member, MemberLoc);
|
QualType ret = CheckOCUVectorComponent(BaseType, OpLoc, Member, MemberLoc);
|
||||||
if (ret.isNull())
|
if (ret.isNull())
|
||||||
return true;
|
return true;
|
||||||
// FIXME: instantiate a OCUVectorComponentExpr node...
|
return new OCUVectorComponent(ret, BaseExpr, Member, MemberLoc);
|
||||||
return true;
|
|
||||||
} else
|
} else
|
||||||
return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion,
|
return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion,
|
||||||
SourceRange(MemberLoc));
|
SourceRange(MemberLoc));
|
||||||
|
|
|
@ -461,6 +461,38 @@ public:
|
||||||
static bool classof(const MemberExpr *) { return true; }
|
static bool classof(const MemberExpr *) { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// OCUVectorComponent
|
||||||
|
///
|
||||||
|
class OCUVectorComponent : public Expr {
|
||||||
|
public:
|
||||||
|
enum ComponentType {
|
||||||
|
Point,
|
||||||
|
Color,
|
||||||
|
Texture
|
||||||
|
};
|
||||||
|
private:
|
||||||
|
Expr *Base;
|
||||||
|
IdentifierInfo &Accessor;
|
||||||
|
SourceLocation AccessorLoc;
|
||||||
|
public:
|
||||||
|
OCUVectorComponent(QualType ty, Expr *base, IdentifierInfo &accessor,
|
||||||
|
SourceLocation loc) : Expr(OCUVectorComponentClass, ty),
|
||||||
|
Base(base), Accessor(accessor), AccessorLoc(loc) {}
|
||||||
|
|
||||||
|
Expr *getBase() const { return Base; }
|
||||||
|
IdentifierInfo & getAccessor() const { return Accessor; }
|
||||||
|
ComponentType getComponentType() const;
|
||||||
|
|
||||||
|
virtual SourceRange getSourceRange() const {
|
||||||
|
return SourceRange(getBase()->getLocStart(), AccessorLoc);
|
||||||
|
}
|
||||||
|
virtual void visit(StmtVisitor &Visitor);
|
||||||
|
static bool classof(const Stmt *T) {
|
||||||
|
return T->getStmtClass() == OCUVectorComponentClass;
|
||||||
|
}
|
||||||
|
static bool classof(const OCUVectorComponent *) { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
/// CompoundLiteralExpr - [C99 6.5.2.5]
|
/// CompoundLiteralExpr - [C99 6.5.2.5]
|
||||||
///
|
///
|
||||||
class CompoundLiteralExpr : public Expr {
|
class CompoundLiteralExpr : public Expr {
|
||||||
|
|
|
@ -62,15 +62,16 @@ STMT(45, BinaryOperator , Expr)
|
||||||
STMT(46, ConditionalOperator , Expr)
|
STMT(46, ConditionalOperator , Expr)
|
||||||
STMT(47, ImplicitCastExpr , Expr)
|
STMT(47, ImplicitCastExpr , Expr)
|
||||||
STMT(48, CompoundLiteralExpr , Expr)
|
STMT(48, CompoundLiteralExpr , Expr)
|
||||||
|
STMT(49, OCUVectorComponent , Expr)
|
||||||
|
|
||||||
// GNU Extensions.
|
// GNU Extensions.
|
||||||
STMT(49, AddrLabel , Expr)
|
STMT(50, AddrLabel , Expr)
|
||||||
STMT(50, StmtExpr , Expr)
|
STMT(51, StmtExpr , Expr)
|
||||||
|
|
||||||
// C++ Expressions.
|
// C++ Expressions.
|
||||||
STMT(51, CXXCastExpr , Expr)
|
STMT(52, CXXCastExpr , Expr)
|
||||||
STMT(52, CXXBoolLiteralExpr , Expr)
|
STMT(53, CXXBoolLiteralExpr , Expr)
|
||||||
LAST_EXPR(52)
|
LAST_EXPR(53)
|
||||||
|
|
||||||
#undef STMT
|
#undef STMT
|
||||||
#undef FIRST_STMT
|
#undef FIRST_STMT
|
||||||
|
|
|
@ -526,6 +526,8 @@ public:
|
||||||
isTextureAccessor(c);
|
isTextureAccessor(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
virtual void getAsStringInternal(std::string &InnerString) const;
|
||||||
|
|
||||||
static bool classof(const Type *T) {
|
static bool classof(const Type *T) {
|
||||||
return T->getTypeClass() == Vector || T->getTypeClass() == OCUVector;
|
return T->getTypeClass() == Vector || T->getTypeClass() == OCUVector;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue