2006-08-17 13:51:27 +08:00
|
|
|
//===--- Builder.cpp - AST Builder Implementation -------------------------===//
|
|
|
|
//
|
|
|
|
// 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 actions class which builds an AST out of a parse
|
|
|
|
// stream.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-08-18 13:17:52 +08:00
|
|
|
#include "clang/Parse/Action.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
2006-08-23 13:17:46 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
|
|
|
#include "clang/Parse/Scope.h"
|
2006-08-18 13:17:52 +08:00
|
|
|
#include "clang/Lex/IdentifierTable.h"
|
2006-10-06 13:22:26 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2006-08-18 13:17:52 +08:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
/// ASTBuilder
|
|
|
|
namespace {
|
|
|
|
class VISIBILITY_HIDDEN ASTBuilder : public Action {
|
2006-10-06 13:22:26 +08:00
|
|
|
Preprocessor &PP;
|
|
|
|
|
2006-08-23 13:17:46 +08:00
|
|
|
/// FullLocInfo - If this is true, the ASTBuilder constructs AST Nodes that
|
|
|
|
/// capture maximal location information for each source-language construct.
|
|
|
|
bool FullLocInfo;
|
2006-10-16 08:33:54 +08:00
|
|
|
|
|
|
|
/// LastInGroupList - This vector is populated when there are multiple
|
|
|
|
/// declarators in a single decl group (e.g. "int A, B, C"). In this case,
|
|
|
|
/// all but the last decl will be entered into this. This is used by the
|
|
|
|
/// ASTStreamer.
|
|
|
|
std::vector<Decl*> &LastInGroupList;
|
2006-08-18 13:17:52 +08:00
|
|
|
public:
|
2006-10-16 08:33:54 +08:00
|
|
|
ASTBuilder(Preprocessor &pp, bool fullLocInfo,
|
|
|
|
std::vector<Decl*> &prevInGroup)
|
|
|
|
: PP(pp), FullLocInfo(fullLocInfo), LastInGroupList(prevInGroup) {}
|
2006-10-06 13:22:26 +08:00
|
|
|
|
2006-08-18 13:17:52 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Symbol table tracking callbacks.
|
|
|
|
//
|
|
|
|
virtual bool isTypedefName(const IdentifierInfo &II, Scope *S) const;
|
2006-10-16 08:33:54 +08:00
|
|
|
virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
|
|
|
|
DeclTy *LastInGroup);
|
|
|
|
virtual DeclTy *ParseFunctionDefinition(Scope *S, Declarator &D,
|
|
|
|
StmtTy *Body);
|
2006-08-18 13:17:52 +08:00
|
|
|
virtual void PopScope(SourceLocation Loc, Scope *S);
|
2006-08-23 13:17:46 +08:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Expression Parsing Callbacks.
|
2006-08-23 14:42:10 +08:00
|
|
|
|
|
|
|
// Primary Expressions.
|
2006-10-25 11:49:28 +08:00
|
|
|
virtual ExprResult ParseSimplePrimaryExpr(SourceLocation Loc,
|
|
|
|
tok::TokenKind Kind);
|
|
|
|
virtual ExprResult ParseIntegerConstant(SourceLocation Loc);
|
|
|
|
virtual ExprResult ParseFloatingConstant(SourceLocation Loc);
|
2006-08-24 13:02:11 +08:00
|
|
|
virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
|
|
|
|
ExprTy *Val);
|
2006-10-06 13:22:26 +08:00
|
|
|
virtual ExprResult ParseStringExpr(const char *StrData, unsigned StrLen,
|
|
|
|
bool isWide,
|
2006-10-25 11:49:28 +08:00
|
|
|
SourceLocation *TokLocs, unsigned NumToks);
|
2006-08-23 14:42:10 +08:00
|
|
|
|
|
|
|
// Binary/Unary Operators. 'Tok' is the token for the operator.
|
2006-10-25 11:38:23 +08:00
|
|
|
virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
|
|
|
|
ExprTy *Input);
|
2006-08-24 14:49:19 +08:00
|
|
|
virtual ExprResult
|
|
|
|
ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
|
|
|
|
SourceLocation LParenLoc, TypeTy *Ty,
|
|
|
|
SourceLocation RParenLoc);
|
|
|
|
|
2006-10-25 11:49:28 +08:00
|
|
|
virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc,
|
|
|
|
tok::TokenKind Kind, ExprTy *Input);
|
2006-08-23 13:17:46 +08:00
|
|
|
|
2006-08-24 13:02:11 +08:00
|
|
|
virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
|
|
|
|
ExprTy *Idx, SourceLocation RLoc);
|
|
|
|
virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
|
|
|
|
tok::TokenKind OpKind,
|
|
|
|
SourceLocation MemberLoc,
|
|
|
|
IdentifierInfo &Member);
|
2006-08-24 12:40:38 +08:00
|
|
|
|
|
|
|
/// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
|
|
|
|
/// This provides the location of the left/right parens and a list of comma
|
|
|
|
/// locations.
|
2006-08-24 13:02:11 +08:00
|
|
|
virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
|
|
|
|
ExprTy **Args, unsigned NumArgs,
|
|
|
|
SourceLocation *CommaLocs,
|
|
|
|
SourceLocation RParenLoc);
|
2006-08-24 12:40:38 +08:00
|
|
|
|
2006-08-24 14:37:51 +08:00
|
|
|
virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
|
|
|
SourceLocation RParenLoc, ExprTy *Op);
|
2006-08-24 12:40:38 +08:00
|
|
|
|
2006-10-25 11:49:28 +08:00
|
|
|
virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
|
|
|
|
ExprTy *LHS,ExprTy *RHS);
|
2006-08-23 13:17:46 +08:00
|
|
|
|
|
|
|
/// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
|
|
|
|
/// in the case of a the GNU conditional expr extension.
|
2006-08-24 13:02:11 +08:00
|
|
|
virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc,
|
|
|
|
SourceLocation ColonLoc,
|
|
|
|
ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
|
2006-08-18 13:17:52 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Symbol table tracking callbacks.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
bool ASTBuilder::isTypedefName(const IdentifierInfo &II, Scope *S) const {
|
|
|
|
Decl *D = II.getFETokenInfo<Decl>();
|
2006-10-16 06:34:45 +08:00
|
|
|
return D != 0 && D->getDeclSpec().StorageClassSpec == DeclSpec::SCS_typedef;
|
2006-08-18 13:17:52 +08:00
|
|
|
}
|
|
|
|
|
2006-10-16 08:33:54 +08:00
|
|
|
Action::DeclTy *
|
|
|
|
ASTBuilder::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
|
|
|
|
DeclTy *LastInGroup) {
|
2006-08-18 13:17:52 +08:00
|
|
|
IdentifierInfo *II = D.getIdentifier();
|
|
|
|
Decl *PrevDecl = II ? II->getFETokenInfo<Decl>() : 0;
|
|
|
|
|
2006-10-16 06:34:45 +08:00
|
|
|
Decl *New;
|
|
|
|
if (D.isFunctionDeclarator())
|
2006-10-16 08:33:54 +08:00
|
|
|
New = new FunctionDecl(II, D, PrevDecl);
|
2006-10-16 06:34:45 +08:00
|
|
|
else
|
2006-10-16 08:33:54 +08:00
|
|
|
New = new VarDecl(II, D, PrevDecl);
|
2006-08-18 13:17:52 +08:00
|
|
|
|
|
|
|
// If this has an identifier, add it to the scope stack.
|
|
|
|
if (II) {
|
|
|
|
// If PrevDecl includes conflicting name here, emit a diagnostic.
|
|
|
|
II->setFETokenInfo(New);
|
|
|
|
S->AddDecl(II);
|
|
|
|
}
|
2006-10-16 08:33:54 +08:00
|
|
|
|
|
|
|
if (LastInGroup) LastInGroupList.push_back((Decl*)LastInGroup);
|
|
|
|
|
|
|
|
return New;
|
|
|
|
}
|
|
|
|
|
|
|
|
Action::DeclTy *
|
|
|
|
ASTBuilder::ParseFunctionDefinition(Scope *S, Declarator &D, StmtTy *Body) {
|
|
|
|
FunctionDecl *FD = (FunctionDecl *)ParseDeclarator(S, D, 0, 0);
|
2006-10-16 13:52:41 +08:00
|
|
|
|
|
|
|
FD->setBody((Stmt*)Body);
|
|
|
|
|
2006-10-16 08:33:54 +08:00
|
|
|
return FD;
|
2006-08-18 13:17:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTBuilder::PopScope(SourceLocation Loc, Scope *S) {
|
|
|
|
for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
IdentifierInfo &II = *static_cast<IdentifierInfo*>(*I);
|
|
|
|
Decl *D = II.getFETokenInfo<Decl>();
|
|
|
|
assert(D && "This decl didn't get pushed??");
|
|
|
|
|
|
|
|
Decl *Next = D->getNext();
|
|
|
|
|
|
|
|
// FIXME: Push the decl on the parent function list if in a function.
|
|
|
|
delete D;
|
|
|
|
|
|
|
|
II.setFETokenInfo(Next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-23 13:17:46 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Expression Parsing Callbacks.
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2006-10-25 11:49:28 +08:00
|
|
|
Action::ExprResult ASTBuilder::ParseSimplePrimaryExpr(SourceLocation Loc,
|
|
|
|
tok::TokenKind Kind) {
|
|
|
|
switch (Kind) {
|
2006-08-24 12:53:44 +08:00
|
|
|
default:
|
|
|
|
assert(0 && "Unknown simple primary expr!");
|
|
|
|
case tok::identifier: {
|
|
|
|
// Could be enum-constant or decl.
|
|
|
|
//Tok.getIdentifierInfo()
|
|
|
|
return new DeclExpr(*(Decl*)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
case tok::char_constant: // constant: character-constant
|
|
|
|
case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2]
|
|
|
|
case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU]
|
|
|
|
case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU]
|
2006-10-06 13:51:35 +08:00
|
|
|
//assert(0 && "FIXME: Unimp so far!");
|
|
|
|
return new DeclExpr(*(Decl*)0);
|
2006-08-24 12:53:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-25 11:49:28 +08:00
|
|
|
Action::ExprResult ASTBuilder::ParseIntegerConstant(SourceLocation Loc) {
|
2006-08-23 13:17:46 +08:00
|
|
|
return new IntegerConstant();
|
|
|
|
}
|
2006-10-25 11:49:28 +08:00
|
|
|
Action::ExprResult ASTBuilder::ParseFloatingConstant(SourceLocation Loc) {
|
2006-08-23 13:17:46 +08:00
|
|
|
return new FloatingConstant();
|
|
|
|
}
|
|
|
|
|
2006-08-24 13:02:11 +08:00
|
|
|
Action::ExprResult ASTBuilder::ParseParenExpr(SourceLocation L,
|
|
|
|
SourceLocation R,
|
|
|
|
ExprTy *Val) {
|
2006-08-23 14:42:10 +08:00
|
|
|
if (!FullLocInfo) return Val;
|
|
|
|
|
|
|
|
return new ParenExpr(L, R, (Expr*)Val);
|
|
|
|
}
|
|
|
|
|
2006-10-06 13:22:26 +08:00
|
|
|
/// ParseStringExpr - This accepts a string after semantic analysis. This string
|
|
|
|
/// may be the result of string concatenation ([C99 5.1.1.2, translation phase
|
|
|
|
/// #6]), so it may come from multiple tokens.
|
|
|
|
///
|
|
|
|
Action::ExprResult ASTBuilder::
|
|
|
|
ParseStringExpr(const char *StrData, unsigned StrLen, bool isWide,
|
2006-10-25 11:49:28 +08:00
|
|
|
SourceLocation *TokLocs, unsigned NumToks) {
|
2006-10-06 13:22:26 +08:00
|
|
|
assert(NumToks && "Must have at least one string!");
|
|
|
|
|
|
|
|
if (!FullLocInfo)
|
|
|
|
return new StringExpr(StrData, StrLen, isWide);
|
2006-10-25 11:49:28 +08:00
|
|
|
else
|
|
|
|
return new StringExprLOC(StrData, StrLen, isWide, TokLocs, NumToks);
|
2006-10-06 13:22:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-23 14:42:10 +08:00
|
|
|
// Unary Operators. 'Tok' is the token for the operator.
|
2006-10-25 11:38:23 +08:00
|
|
|
Action::ExprResult ASTBuilder::ParseUnaryOp(SourceLocation OpLoc,
|
|
|
|
tok::TokenKind Op,
|
2006-08-24 13:02:11 +08:00
|
|
|
ExprTy *Input) {
|
2006-08-23 14:42:10 +08:00
|
|
|
UnaryOperator::Opcode Opc;
|
2006-10-25 11:38:23 +08:00
|
|
|
switch (Op) {
|
2006-08-23 14:42:10 +08:00
|
|
|
default: assert(0 && "Unknown unary op!");
|
2006-08-24 14:10:04 +08:00
|
|
|
case tok::plusplus: Opc = UnaryOperator::PreInc; break;
|
|
|
|
case tok::minusminus: Opc = UnaryOperator::PreDec; break;
|
|
|
|
case tok::amp: Opc = UnaryOperator::AddrOf; break;
|
|
|
|
case tok::star: Opc = UnaryOperator::Deref; break;
|
|
|
|
case tok::plus: Opc = UnaryOperator::Plus; break;
|
|
|
|
case tok::minus: Opc = UnaryOperator::Minus; break;
|
|
|
|
case tok::tilde: Opc = UnaryOperator::Not; break;
|
|
|
|
case tok::exclaim: Opc = UnaryOperator::LNot; break;
|
|
|
|
case tok::kw_sizeof: Opc = UnaryOperator::SizeOf; break;
|
|
|
|
case tok::kw___alignof: Opc = UnaryOperator::AlignOf; break;
|
2006-10-16 06:34:45 +08:00
|
|
|
case tok::kw___real: Opc = UnaryOperator::Real; break;
|
|
|
|
case tok::kw___imag: Opc = UnaryOperator::Imag; break;
|
|
|
|
case tok::ampamp: Opc = UnaryOperator::AddrLabel; break;
|
2006-08-23 14:42:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!FullLocInfo)
|
|
|
|
return new UnaryOperator((Expr*)Input, Opc);
|
|
|
|
else
|
2006-10-25 11:38:23 +08:00
|
|
|
return new UnaryOperatorLOC(OpLoc, (Expr*)Input, Opc);
|
2006-08-23 14:42:10 +08:00
|
|
|
}
|
|
|
|
|
2006-08-24 14:49:19 +08:00
|
|
|
Action::ExprResult ASTBuilder::
|
|
|
|
ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
|
|
|
|
SourceLocation LParenLoc, TypeTy *Ty,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
if (!FullLocInfo)
|
|
|
|
return new SizeOfAlignOfTypeExpr(isSizeof, (Type*)Ty);
|
|
|
|
else
|
|
|
|
return new SizeOfAlignOfTypeExprLOC(OpLoc, isSizeof, LParenLoc, (Type*)Ty,
|
|
|
|
RParenLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-25 11:49:28 +08:00
|
|
|
Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(SourceLocation OpLoc,
|
|
|
|
tok::TokenKind Kind,
|
2006-08-24 13:02:11 +08:00
|
|
|
ExprTy *Input) {
|
2006-08-23 14:42:10 +08:00
|
|
|
UnaryOperator::Opcode Opc;
|
2006-10-25 11:49:28 +08:00
|
|
|
switch (Kind) {
|
2006-08-23 14:42:10 +08:00
|
|
|
default: assert(0 && "Unknown unary op!");
|
|
|
|
case tok::plusplus: Opc = UnaryOperator::PostInc; break;
|
|
|
|
case tok::minusminus: Opc = UnaryOperator::PostDec; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FullLocInfo)
|
|
|
|
return new UnaryOperator((Expr*)Input, Opc);
|
|
|
|
else
|
2006-10-25 11:49:28 +08:00
|
|
|
return new UnaryOperatorLOC(OpLoc, (Expr*)Input, Opc);
|
2006-08-23 14:42:10 +08:00
|
|
|
}
|
|
|
|
|
2006-08-24 13:02:11 +08:00
|
|
|
Action::ExprResult ASTBuilder::
|
2006-08-24 12:40:38 +08:00
|
|
|
ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
|
|
|
|
ExprTy *Idx, SourceLocation RLoc) {
|
|
|
|
if (!FullLocInfo)
|
|
|
|
return new ArraySubscriptExpr((Expr*)Base, (Expr*)Idx);
|
|
|
|
else
|
|
|
|
return new ArraySubscriptExprLOC((Expr*)Base, LLoc, (Expr*)Idx, RLoc);
|
|
|
|
}
|
|
|
|
|
2006-08-24 13:02:11 +08:00
|
|
|
Action::ExprResult ASTBuilder::
|
2006-08-24 12:40:38 +08:00
|
|
|
ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
|
|
|
|
tok::TokenKind OpKind, SourceLocation MemberLoc,
|
|
|
|
IdentifierInfo &Member) {
|
2006-08-24 13:19:28 +08:00
|
|
|
Decl *MemberDecl = 0;
|
|
|
|
// TODO: Look up MemberDecl.
|
2006-08-24 12:40:38 +08:00
|
|
|
if (!FullLocInfo)
|
2006-08-24 13:19:28 +08:00
|
|
|
return new MemberExpr((Expr*)Base, OpKind == tok::arrow, MemberDecl);
|
2006-08-24 12:40:38 +08:00
|
|
|
else
|
|
|
|
return new MemberExprLOC((Expr*)Base, OpLoc, OpKind == tok::arrow,
|
2006-08-24 13:19:28 +08:00
|
|
|
MemberLoc, MemberDecl);
|
2006-08-24 12:40:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
|
|
|
|
/// This provides the location of the left/right parens and a list of comma
|
|
|
|
/// locations.
|
2006-08-24 13:02:11 +08:00
|
|
|
Action::ExprResult ASTBuilder::
|
2006-08-24 12:40:38 +08:00
|
|
|
ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
|
|
|
|
ExprTy **Args, unsigned NumArgs,
|
|
|
|
SourceLocation *CommaLocs, SourceLocation RParenLoc) {
|
|
|
|
if (!FullLocInfo)
|
|
|
|
return new CallExpr((Expr*)Fn, (Expr**)Args, NumArgs);
|
|
|
|
else
|
|
|
|
return new CallExprLOC((Expr*)Fn, LParenLoc, (Expr**)Args, NumArgs,
|
|
|
|
CommaLocs, RParenLoc);
|
|
|
|
}
|
|
|
|
|
2006-08-24 14:37:51 +08:00
|
|
|
Action::ExprResult ASTBuilder::
|
|
|
|
ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
|
|
|
SourceLocation RParenLoc, ExprTy *Op) {
|
|
|
|
if (!FullLocInfo)
|
|
|
|
return new CastExpr((Type*)Ty, (Expr*)Op);
|
|
|
|
else
|
|
|
|
return new CastExprLOC(LParenLoc, (Type*)Ty, RParenLoc, (Expr*)Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-24 12:40:38 +08:00
|
|
|
|
2006-08-23 13:17:46 +08:00
|
|
|
// Binary Operators. 'Tok' is the token for the operator.
|
2006-10-25 11:49:28 +08:00
|
|
|
Action::ExprResult ASTBuilder::ParseBinOp(SourceLocation TokLoc,
|
|
|
|
tok::TokenKind Kind, ExprTy *LHS,
|
2006-08-24 13:02:11 +08:00
|
|
|
ExprTy *RHS) {
|
2006-08-23 13:17:46 +08:00
|
|
|
BinaryOperator::Opcode Opc;
|
2006-10-25 11:49:28 +08:00
|
|
|
switch (Kind) {
|
2006-08-23 13:17:46 +08:00
|
|
|
default: assert(0 && "Unknown binop!");
|
|
|
|
case tok::star: Opc = BinaryOperator::Mul; break;
|
|
|
|
case tok::slash: Opc = BinaryOperator::Div; break;
|
|
|
|
case tok::percent: Opc = BinaryOperator::Rem; break;
|
|
|
|
case tok::plus: Opc = BinaryOperator::Add; break;
|
|
|
|
case tok::minus: Opc = BinaryOperator::Sub; break;
|
|
|
|
case tok::lessless: Opc = BinaryOperator::Shl; break;
|
|
|
|
case tok::greatergreater: Opc = BinaryOperator::Shr; break;
|
|
|
|
case tok::lessequal: Opc = BinaryOperator::LE; break;
|
|
|
|
case tok::less: Opc = BinaryOperator::LT; break;
|
|
|
|
case tok::greaterequal: Opc = BinaryOperator::GE; break;
|
|
|
|
case tok::greater: Opc = BinaryOperator::GT; break;
|
|
|
|
case tok::exclaimequal: Opc = BinaryOperator::NE; break;
|
|
|
|
case tok::equalequal: Opc = BinaryOperator::EQ; break;
|
|
|
|
case tok::amp: Opc = BinaryOperator::And; break;
|
|
|
|
case tok::caret: Opc = BinaryOperator::Xor; break;
|
|
|
|
case tok::pipe: Opc = BinaryOperator::Or; break;
|
|
|
|
case tok::ampamp: Opc = BinaryOperator::LAnd; break;
|
|
|
|
case tok::pipepipe: Opc = BinaryOperator::LOr; break;
|
|
|
|
case tok::equal: Opc = BinaryOperator::Assign; break;
|
|
|
|
case tok::starequal: Opc = BinaryOperator::MulAssign; break;
|
|
|
|
case tok::slashequal: Opc = BinaryOperator::DivAssign; break;
|
|
|
|
case tok::percentequal: Opc = BinaryOperator::RemAssign; break;
|
|
|
|
case tok::plusequal: Opc = BinaryOperator::AddAssign; break;
|
|
|
|
case tok::minusequal: Opc = BinaryOperator::SubAssign; break;
|
|
|
|
case tok::lesslessequal: Opc = BinaryOperator::ShlAssign; break;
|
|
|
|
case tok::greatergreaterequal: Opc = BinaryOperator::ShrAssign; break;
|
|
|
|
case tok::ampequal: Opc = BinaryOperator::AndAssign; break;
|
|
|
|
case tok::caretequal: Opc = BinaryOperator::XorAssign; break;
|
|
|
|
case tok::pipeequal: Opc = BinaryOperator::OrAssign; break;
|
|
|
|
case tok::comma: Opc = BinaryOperator::Comma; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FullLocInfo)
|
|
|
|
return new BinaryOperator((Expr*)LHS, (Expr*)RHS, Opc);
|
|
|
|
else
|
2006-10-25 11:49:28 +08:00
|
|
|
return new BinaryOperatorLOC((Expr*)LHS, TokLoc, (Expr*)RHS, Opc);
|
2006-08-23 13:17:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
|
|
|
|
/// in the case of a the GNU conditional expr extension.
|
2006-08-24 13:02:11 +08:00
|
|
|
Action::ExprResult ASTBuilder::ParseConditionalOp(SourceLocation QuestionLoc,
|
|
|
|
SourceLocation ColonLoc,
|
|
|
|
ExprTy *Cond, ExprTy *LHS,
|
|
|
|
ExprTy *RHS) {
|
2006-08-23 13:17:46 +08:00
|
|
|
if (!FullLocInfo)
|
|
|
|
return new ConditionalOperator((Expr*)Cond, (Expr*)LHS, (Expr*)RHS);
|
|
|
|
else
|
|
|
|
return new ConditionalOperatorLOC((Expr*)Cond, QuestionLoc, (Expr*)LHS,
|
|
|
|
ColonLoc, (Expr*)RHS);
|
|
|
|
}
|
|
|
|
|
2006-08-18 13:17:52 +08:00
|
|
|
|
|
|
|
/// Interface to the Builder.cpp file.
|
|
|
|
///
|
2006-10-16 08:33:54 +08:00
|
|
|
Action *CreateASTBuilderActions(Preprocessor &PP, bool FullLocInfo,
|
|
|
|
std::vector<Decl*> &LastInGroupList) {
|
|
|
|
return new ASTBuilder(PP, FullLocInfo, LastInGroupList);
|
2006-08-18 13:17:52 +08:00
|
|
|
}
|
|
|
|
|