#include "symbol_t.h"
#include "type_t.h"
#include "parser.h"
+#include "lang_features.h"
#include <assert.h>
#include <stdio.h>
* Print microsoft extended declaration modifiers.
*/
static void print_ms_modifiers(const declaration_t *declaration) {
+ if((c_mode & _MS) == 0)
+ return;
+
decl_modifiers_t modifiers = declaration->modifiers;
/* DM_FORCEINLINE handled outside. */
- if((modifiers & ~DM_FORCEINLINE) != 0 || declaration->alignment != 0 ||
+ if((modifiers & ~DM_FORCEINLINE) != 0 ||
+ declaration->alignment != 0 || declaration->deprecated != 0 ||
declaration->get_property_sym != NULL || declaration->put_property_sym != NULL) {
char *next = "(";
if(modifiers & DM_NOINLINE) {
fputs(next, out); next = ", "; fputs("noinline", out);
}
- if(modifiers & DM_DEPRECATED) {
+ if(declaration->deprecated != 0) {
fputs(next, out); next = ", "; fputs("deprecated", out);
if(declaration->deprecated_string != NULL)
fprintf(out, "(\"%s\")", declaration->deprecated_string);
DM_NOVTABLE = (1 << 8),
DM_NORETURN = (1 << 9),
DM_NOINLINE = (1 << 10),
- DM_DEPRECATED = (1 << 11),
- DM_RESTRICT = (1 << 12),
- DM_NOALIAS = (1 << 13)
+ DM_RESTRICT = (1 << 11),
+ DM_NOALIAS = (1 << 12)
} decl_modifier_t;
typedef unsigned short decl_modifiers_t;
unsigned char namespc;
unsigned char declared_storage_class;
unsigned char storage_class;
- unsigned char alignment; /**< Alignmnet of the declaration, 0 for default. */
+ unsigned char alignment; /**< Alignment of the declaration, 0 for default. */
decl_modifiers_t modifiers; /**< MS __declspec modifiers. */
const char *deprecated_string; /**< MS deprecated string if any. */
symbol_t *get_property_sym; /**< MS get property. */
unsigned int address_taken : 1;
unsigned int is_inline : 1;
unsigned int used : 1; /**< Set if the declaration is used. */
+ unsigned int deprecated : 1; /**< Microsoft of GNU deprecated attribute. */
type_t *type;
symbol_t *symbol;
source_position_t source_position;
source_position_t source_position;
unsigned char declared_storage_class;
unsigned char alignment; /**< Alignment, 0 if not set. */
- bool is_inline;
+ unsigned int is_inline : 1;
+ unsigned int deprecated : 1;
decl_modifiers_t decl_modifiers; /**< MS __declspec extended modifier mask */
const char *deprecated_string; /**< can be set if declaration was marked deprecated. */
symbol_t *get_property_sym; /**< the name of the get property if set. */
return result;
}
+/**
+ * Parse one GNU attribute.
+ */
+static void parse_gnu_attribute(void)
+{
+ eat(T___attribute__);
+ expect('(');
+ expect('(');
+ while(true) {
+ if(token.type != T_IDENTIFIER)
+ break;
+ symbol_t *symbol = token.v.symbol;
+ next_token();
+ if(token.type == '(')
+ eat_until_matching_token('(');
+ if(token.type != ',')
+ break;
+ next_token();
+ }
+ expect(')');
+ expect(')');
+end_error:
+ return;
+}
+
+/**
+ * Parse GNU attributes.
+ */
static void parse_attributes(void)
{
while(true) {
switch(token.type) {
case T___attribute__: {
- next_token();
-
- expect('(');
- int depth = 1;
- while(depth > 0) {
- switch(token.type) {
- case T_EOF:
- errorf(HERE, "EOF while parsing attribute");
- break;
- case '(':
- next_token();
- depth++;
- break;
- case ')':
- next_token();
- depth--;
- break;
- default:
- next_token();
- }
- }
+ parse_gnu_attribute();
break;
}
case T_asm:
expect(')');
} else if(symbol == sym_deprecated) {
next_token();
- DET_MOD(deprecated, DM_DEPRECATED);
- if(token.type == '(') {
+ if(specifiers->deprecated != 0)
+ warningf(HERE, "deprecated used more than once");
+ specifiers->deprecated = 1;
+ if(token.type == '(') {
next_token();
if(token.type == T_STRING_LITERAL) {
specifiers->deprecated_string = token.v.string.begin;
MATCH_STORAGE_CLASS(T_auto, STORAGE_CLASS_AUTO)
MATCH_STORAGE_CLASS(T_register, STORAGE_CLASS_REGISTER)
- case T_declspec:
+ case T__declspec:
next_token();
expect('(');
add_anchor_token(')');
MATCH_TYPE_QUALIFIER(T_const, TYPE_QUALIFIER_CONST);
MATCH_TYPE_QUALIFIER(T_restrict, TYPE_QUALIFIER_RESTRICT);
MATCH_TYPE_QUALIFIER(T_volatile, TYPE_QUALIFIER_VOLATILE);
+ MATCH_TYPE_QUALIFIER(T__w64, TYPE_QUALIFIER_W64);
+ MATCH_TYPE_QUALIFIER(T___ptr32, TYPE_QUALIFIER_PTR32);
+ MATCH_TYPE_QUALIFIER(T___ptr64, TYPE_QUALIFIER_PTR64);
+ MATCH_TYPE_QUALIFIER(T___uptr, TYPE_QUALIFIER_UPTR);
+ MATCH_TYPE_QUALIFIER(T___sptr, TYPE_QUALIFIER_SPTR);
case T___extension__:
/* TODO */
}
type->base.qualifiers = type_qualifiers;
+ /* FIXME: check type qualifiers here */
type_t *result = typehash_insert(type);
if(newtype && result != type) {
MATCH_TYPE_QUALIFIER(T_const, TYPE_QUALIFIER_CONST);
MATCH_TYPE_QUALIFIER(T_restrict, TYPE_QUALIFIER_RESTRICT);
MATCH_TYPE_QUALIFIER(T_volatile, TYPE_QUALIFIER_VOLATILE);
+ /* microsoft extended type modifiers */
+ MATCH_TYPE_QUALIFIER(T__w64, TYPE_QUALIFIER_W64);
+ MATCH_TYPE_QUALIFIER(T___ptr32, TYPE_QUALIFIER_PTR32);
+ MATCH_TYPE_QUALIFIER(T___ptr64, TYPE_QUALIFIER_PTR64);
+ MATCH_TYPE_QUALIFIER(T___uptr, TYPE_QUALIFIER_UPTR);
+ MATCH_TYPE_QUALIFIER(T___sptr, TYPE_QUALIFIER_SPTR);
default:
return type_qualifiers;
declaration_t *const declaration = allocate_declaration_zero();
declaration->declared_storage_class = specifiers->declared_storage_class;
declaration->modifiers = specifiers->decl_modifiers;
+ declaration->deprecated = specifiers->deprecated;
declaration->deprecated_string = specifiers->deprecated_string;
declaration->get_property_sym = specifiers->get_property_sym;
declaration->put_property_sym = specifiers->put_property_sym;
declaration->used = true;
/* check for deprecated functions */
- if(declaration->modifiers & DM_DEPRECATED) {
+ if(declaration->deprecated != 0) {
const char *prefix = "";
if (is_type_function(declaration->type))
prefix = "function ";