From 2122dad8b095cdec313313a6ca4d1613aa956a06 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 27 Mar 2018 11:50:08 +0300 Subject: [PATCH] Expose __attribute__ and __declspec attributes. Closes #50. --- src/libclang/cxtokenizer.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/libclang/cxtokenizer.cpp b/src/libclang/cxtokenizer.cpp index d374cef..edbbf72 100644 --- a/src/libclang/cxtokenizer.cpp +++ b/src/libclang/cxtokenizer.cpp @@ -545,12 +545,23 @@ namespace auto arguments = parse_attribute_arguments(stream); result.push_back(cpp_attribute(cpp_attribute_kind::alignas_, std::move(arguments))); } - else if (skip_if(stream, "__attribute__")) + else if (skip_if(stream, "__attribute__") && stream.peek() == "(") { // GCC/clang attributes - // __attribute__() - // ^ - skip_brackets(stream); + // __attribute__(()) + // ^^ + skip(stream, "("); + skip(stream, "("); + + auto scope = parse_attribute_using(stream); + while (!skip_if(stream, ")")) + { + auto attribute = parse_attribute_token(stream, scope); + result.push_back(std::move(attribute)); + detail::skip_if(stream, ","); + } + + skip(stream, ")"); return true; } else if (skip_if(stream, "__declspec")) @@ -558,7 +569,15 @@ namespace // MSVC declspec // __declspec() // ^ - skip_brackets(stream); + skip(stream, "("); + auto scope = parse_attribute_using(stream); + while (!skip_if(stream, ")")) + { + auto attribute = parse_attribute_token(stream, scope); + result.push_back(std::move(attribute)); + detail::skip_if(stream, ","); + } + return true; }