Add parsing and AST support for GNU "typeof".
Many small changes to lot's of files.
Still some FIXME's, however the basic support is in place.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40631 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp
index a9fb81f..6f71651 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -584,6 +584,18 @@
return QualType(Decl->TypeForDecl, 0);
}
+QualType ASTContext::getTypeOfType(Expr *tofExpr) {
+ QualType Canonical = tofExpr->getType().getCanonicalType();
+ // Note: TypeOfExpr's aren't uniqued.
+ return QualType(new TypeOfExpr(tofExpr, Canonical), 0);
+}
+
+QualType ASTContext::getTypeOfType(QualType tofType) {
+ QualType Canonical = tofType.getCanonicalType();
+ // Note: TypeOfType's aren't uniqued.
+ return QualType(new TypeOfType(tofType, Canonical), 0);
+}
+
/// getTagDeclType - Return the unique reference to the type for the
/// specified TagDecl (struct/union/class/enum) decl.
QualType ASTContext::getTagDeclType(TagDecl *Decl) {
diff --git a/AST/Type.cpp b/AST/Type.cpp
index 214dbea..ecade56 100644
--- a/AST/Type.cpp
+++ b/AST/Type.cpp
@@ -638,6 +638,18 @@
ElementType.getAsStringInternal(S);
}
+void TypeOfExpr::getAsStringInternal(std::string &InnerString) const {
+ // FIXME: output expression, getUnderlyingExpr()->print().
+ // At the moment, Stmt::print(std::ostream) doesn't work for us here.
+ InnerString = "typeof(<expr>) " + InnerString;
+}
+
+void TypeOfType::getAsStringInternal(std::string &S) const {
+ std::string Tmp;
+ getUnderlyingType().getAsStringInternal(Tmp);
+ S += "typeof(" + Tmp + ")";
+}
+
void FunctionTypeNoProto::getAsStringInternal(std::string &S) const {
// If needed for precedence reasons, wrap the inner part in grouping parens.
if (!S.empty())