[cfe-commits] r40577 - in /cfe/trunk: AST/Expr.cpp AST/StmtPrinter.cpp AST/Type.cpp Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/AST/StmtNodes.def include/clang/AST/Type.h
Steve Naroff
snaroff at apple.com
Sat Jul 28 16:10:27 PDT 2007
Author: snaroff
Date: Sat Jul 28 18:10:27 2007
New Revision: 40577
URL: http://llvm.org/viewvc/llvm-project?rev=40577&view=rev
Log:
Added a new expression, OCUVectorComponent.
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/AST/StmtPrinter.cpp
cfe/trunk/AST/Type.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/StmtNodes.def
cfe/trunk/include/clang/AST/Type.h
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=40577&r1=40576&r2=40577&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Sat Jul 28 18:10:27 2007
@@ -571,3 +571,13 @@
llvm::APSInt Val(32);
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");
+}
Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=40577&r1=40576&r2=40577&view=diff
==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Sat Jul 28 18:10:27 2007
@@ -439,6 +439,11 @@
assert(Field && "MemberExpr should alway reference a field!");
OS << Field->getName();
}
+void StmtPrinter::VisitOCUVectorComponent(OCUVectorComponent *Node) {
+ PrintExpr(Node->getBase());
+ OS << ".";
+ OS << Node->getAccessor().getName();
+}
void StmtPrinter::VisitCastExpr(CastExpr *Node) {
OS << "(" << Node->getType().getAsString() << ")";
PrintExpr(Node->getSubExpr());
Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=40577&r1=40576&r2=40577&view=diff
==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Sat Jul 28 18:10:27 2007
@@ -631,6 +631,13 @@
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 {
// If needed for precedence reasons, wrap the inner part in grouping parens.
if (!S.empty())
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=40577&r1=40576&r2=40577&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sat Jul 28 18:10:27 2007
@@ -423,8 +423,7 @@
QualType ret = CheckOCUVectorComponent(BaseType, OpLoc, Member, MemberLoc);
if (ret.isNull())
return true;
- // FIXME: instantiate a OCUVectorComponentExpr node...
- return true;
+ return new OCUVectorComponent(ret, BaseExpr, Member, MemberLoc);
} else
return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion,
SourceRange(MemberLoc));
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=40577&r1=40576&r2=40577&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Jul 28 18:10:27 2007
@@ -461,6 +461,38 @@
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]
///
class CompoundLiteralExpr : public Expr {
Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=40577&r1=40576&r2=40577&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Sat Jul 28 18:10:27 2007
@@ -62,15 +62,16 @@
STMT(46, ConditionalOperator , Expr)
STMT(47, ImplicitCastExpr , Expr)
STMT(48, CompoundLiteralExpr , Expr)
+STMT(49, OCUVectorComponent , Expr)
// GNU Extensions.
-STMT(49, AddrLabel , Expr)
-STMT(50, StmtExpr , Expr)
+STMT(50, AddrLabel , Expr)
+STMT(51, StmtExpr , Expr)
// C++ Expressions.
-STMT(51, CXXCastExpr , Expr)
-STMT(52, CXXBoolLiteralExpr , Expr)
-LAST_EXPR(52)
+STMT(52, CXXCastExpr , Expr)
+STMT(53, CXXBoolLiteralExpr , Expr)
+LAST_EXPR(53)
#undef STMT
#undef FIRST_STMT
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=40577&r1=40576&r2=40577&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sat Jul 28 18:10:27 2007
@@ -526,6 +526,8 @@
isTextureAccessor(c);
}
}
+ virtual void getAsStringInternal(std::string &InnerString) const;
+
static bool classof(const Type *T) {
return T->getTypeClass() == Vector || T->getTypeClass() == OCUVector;
}
More information about the cfe-commits
mailing list