summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/AttributeList.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-02-11 23:02:49 +0000
committerDouglas Gregor <dgregor@apple.com>2009-02-11 23:02:49 +0000
commit4e5cbdcbed0b0d8e1c319d70507886d66f8bda8b (patch)
tree5c7843528143b1e00b2c513c762ed1850c8aa081 /clang/lib/Parse/AttributeList.cpp
parent318aea93bf1f9ea31d8e2889c6208aa4a277e774 (diff)
downloadbcm5719-llvm-4e5cbdcbed0b0d8e1c319d70507886d66f8bda8b.tar.gz
bcm5719-llvm-4e5cbdcbed0b0d8e1c319d70507886d66f8bda8b.zip
Initial implementation of function overloading in C.
This commit adds a new attribute, "overloadable", that enables C++ function overloading in C. The attribute can only be added to function declarations, e.g., int *f(int) __attribute__((overloadable)); If the "overloadable" attribute exists on a function with a given name, *all* functions with that name (and in that scope) must have the "overloadable" attribute. Sets of overloaded functions with the "overloadable" attribute then follow the normal C++ rules for overloaded functions, e.g., overloads must have different parameter-type-lists from each other. When calling an overloaded function in C, we follow the same overloading rules as C++, with three extensions to the set of standard conversions: - A value of a given struct or union type T can be converted to the type T. This is just the identity conversion. (In C++, this would go through a copy constructor). - A value of pointer type T* can be converted to a value of type U* if T and U are compatible types. This conversion has Conversion rank (it's considered a pointer conversion in C). - A value of type T can be converted to a value of type U if T and U are compatible (and are not both pointer types). This conversion has Conversion rank (it's considered to be a new kind of conversion unique to C, a "compatible" conversion). Known defects (and, therefore, next steps): 1) The standard-conversion handling does not understand conversions involving _Complex or vector extensions, so it is likely to get these wrong. We need to add these conversions. 2) All overloadable functions with the same name will have the same linkage name, which means we'll get a collision in the linker (if not sooner). We'll need to mangle the names of these functions. llvm-svn: 64336
Diffstat (limited to 'clang/lib/Parse/AttributeList.cpp')
-rw-r--r--clang/lib/Parse/AttributeList.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/Parse/AttributeList.cpp b/clang/lib/Parse/AttributeList.cpp
index eb0527dcf9c..954e93e056a 100644
--- a/clang/lib/Parse/AttributeList.cpp
+++ b/clang/lib/Parse/AttributeList.cpp
@@ -98,6 +98,9 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
if (!memcmp(Str, "constructor", 11)) return AT_constructor;
if (!memcmp(Str, "unavailable", 11)) return AT_unavailable;
break;
+ case 12:
+ if (!memcmp(Str, "overloadable", 12)) return AT_overloadable;
+ break;
case 13:
if (!memcmp(Str, "address_space", 13)) return AT_address_space;
if (!memcmp(Str, "always_inline", 13)) return AT_always_inline;
OpenPOWER on IntegriCloud