Add support for encoding a OCUVectorComponent into a single integer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40768 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Expr.cpp b/AST/Expr.cpp
index 2df7612..9b5fc78 100644
--- a/AST/Expr.cpp
+++ b/AST/Expr.cpp
@@ -611,3 +611,20 @@
}
return false;
}
+
+/// getEncodedElementAccess - We encode fields with two bits per component.
+unsigned OCUVectorComponent::getEncodedElementAccess() const {
+ const char *compStr = Accessor.getName();
+ unsigned length = strlen(compStr);
+
+ unsigned Result = 0;
+
+ while (length--) {
+ Result <<= 2;
+ int Idx = OCUVectorType::getAccessorIdx(compStr[length]);
+ assert(Idx != -1 && "Invalid accessor letter");
+ Result |= Idx;
+ }
+ return Result;
+}
+