//===--- ParseDecl.cpp - Declaration Parsing ------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Chris Lattner and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the Declaration portions of the Parser interfaces.
//
//===----------------------------------------------------------------------===//
#include "clang/Parse/Parser.h"
#include "clang/Parse/DeclSpec.h"
#include "llvm/ADT/SmallSet.h"
using namespace clang;
//===----------------------------------------------------------------------===//
// C99 6.7: Declarations.
//===----------------------------------------------------------------------===//
/// ParseTypeName
/// type-name: [C99 6.7.6]
/// specifier-qualifier-list abstract-declarator[opt]
Parser::TypeTy *Parser::ParseTypeName() {
// Parse the common declaration-specifiers piece.
DeclSpec DS;
ParseSpecifierQualifierList(DS);
// Parse the abstract-declarator, if present.
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
ParseDeclarator(DeclaratorInfo);
return Actions.ParseTypeName(CurScope, DeclaratorInfo).Val;
}
/// ParseAttributes - Parse a non-empty attributes list.
///
/// [GNU] attributes:
/// attribute
/// attributes attribute
///
/// [GNU] attribute:
/// '__attribute__' '(' '(' attribute-list ')' ')'
///
/// [GNU] attribute-list:
/// attrib
/// attribute_list ',' attrib
///
/// [GNU] attrib:
/// empty
/// attrib-name
/// attrib-name '(' identifier ')'
/// attrib-name '(' identifier ',' nonempty-expr-list ')'
/// attrib-name '(' argument-expression-list [C99 6.5.2] ')'
///
/// [GNU] attrib-name:
/// identifier
/// typespec
/// typequal
/// storageclass
///
/// FIXME: The GCC grammar/code for this construct implies we need two
/// token lookahead. Comment from gcc: "If they start with an identifier
/// which is followed by a comma or close parenthesis, then the arguments
/// start with that identifier; otherwise they are an expression list."
///
/// At the moment, I am not doing 2 token lookahead. I am also unaware of
/// any attributes that don't work (based on my limited testing). Most
/// attributes are very simple in practice. Until we find a bug, I don't see
/// a pressing need to implement the 2 token lookahead.
AttributeList *Parser::ParseAttributes() {
assert(Tok.getKind() == tok::kw___attribute && "Not an attribute list!");
AttributeList