[cfe-commits] r38943 - in /cfe/cfe/trunk: AST/Expr.cpp AST/Sema.cpp Parse/ParseExpr.cpp Sema/Sema.cpp include/clang/AST/Expr.h include/clang/Parse/Action.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:26:04 PDT 2007
Author: sabre
Date: Wed Jul 11 11:26:04 2007
New Revision: 38943
URL: http://llvm.org/viewvc/llvm-project?rev=38943&view=rev
Log:
Add AST nodes for array, call, . and ->.
Modified:
cfe/cfe/trunk/AST/Expr.cpp
cfe/cfe/trunk/AST/Sema.cpp
cfe/cfe/trunk/Parse/ParseExpr.cpp
cfe/cfe/trunk/Sema/Sema.cpp
cfe/cfe/trunk/include/clang/AST/Expr.h
cfe/cfe/trunk/include/clang/Parse/Action.h
Modified: cfe/cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Expr.cpp?rev=38943&r1=38942&r2=38943&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:26:04 2007
@@ -12,15 +12,19 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/Expr.h"
+#include "clang/Lex/IdentifierTable.h"
#include <iostream>
using namespace llvm;
using namespace clang;
void Expr::dump() const {
- if (this == 0)
+ if (this == 0) {
std::cerr << "<null expr>";
- else
- dump_impl();
+ return;
+ }
+ std::cerr << "(";
+ dump_impl();
+ std::cerr << ")";
}
@@ -59,11 +63,55 @@
}
void UnaryOperator::dump_impl() const {
- std::cerr << "(" << getOpcodeStr(Opc);
+ std::cerr << getOpcodeStr(Opc);
Input->dump();
+}
+
+
+void ArraySubscriptExpr::dump_impl() const {
+ Base->dump();
+ std::cerr << "[";
+ Idx->dump();
+ std::cerr << "]";
+}
+
+CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs)
+ : Fn(fn), NumArgs(numargs) {
+ Args = new Expr*[numargs];
+ for (unsigned i = 0; i != numargs; ++i)
+ Args[i] = args[i];
+}
+
+void CallExpr::dump_impl() const {
+ Fn->dump();
+ std::cerr << "(";
+ for (unsigned i = 0, e = getNumArgs(); i != e; ++i) {
+ if (i) std::cerr << ", ";
+ getArg(i)->dump();
+ }
std::cerr << ")";
}
+CallExprLOC::CallExprLOC(Expr *Fn, SourceLocation lparenloc, Expr **Args,
+ unsigned NumArgs, SourceLocation *commalocs,
+ SourceLocation rparenloc)
+ : CallExpr(Fn, Args, NumArgs), LParenLoc(lparenloc), RParenLoc(rparenloc) {
+ unsigned NumCommas = getNumCommas();
+ if (NumCommas)
+ CommaLocs = new SourceLocation[NumCommas];
+ else
+ CommaLocs = 0;
+
+ for (unsigned i = 0; i != NumCommas; ++i)
+ CommaLocs[i] = commalocs[i];
+}
+
+
+void MemberExpr::dump_impl() const {
+ Base->dump();
+ std::cerr << (isArrow ? "->" : ".") << MemberII->getName();
+}
+
/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
/// corresponds to, e.g. "<<=".
const char *BinaryOperator::getOpcodeStr(Opcode Op) {
@@ -103,19 +151,15 @@
}
void BinaryOperator::dump_impl() const {
- std::cerr << "(";
LHS->dump();
std::cerr << " " << getOpcodeStr(Opc) << " ";
RHS->dump();
- std::cerr << ")";
}
void ConditionalOperator::dump_impl() const {
- std::cerr << "(";
Cond->dump();
std::cerr << " ? ";
LHS->dump();
std::cerr << " : ";
RHS->dump();
- std::cerr << ")";
}
Modified: cfe/cfe/trunk/AST/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.cpp?rev=38943&r1=38942&r2=38943&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:26:04 2007
@@ -51,6 +51,22 @@
virtual ExprTy *ParseUnaryOp(const LexerToken &Tok, ExprTy *Input);
virtual ExprTy *ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input);
+ virtual ExprTy *ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
+ ExprTy *Idx, SourceLocation RLoc);
+ virtual ExprTy *ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
+ tok::TokenKind OpKind,
+ SourceLocation MemberLoc,
+ IdentifierInfo &Member);
+
+ /// 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.
+ virtual ExprTy *ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
+ ExprTy **Args, unsigned NumArgs,
+ SourceLocation *CommaLocs,
+ SourceLocation RParenLoc);
+
+
virtual ExprTy *ParseBinOp(const LexerToken &Tok, ExprTy *LHS, ExprTy *RHS);
/// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
@@ -162,6 +178,41 @@
return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc);
}
+ASTBuilder::ExprTy *ASTBuilder::
+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);
+}
+
+ASTBuilder::ExprTy *ASTBuilder::
+ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
+ tok::TokenKind OpKind, SourceLocation MemberLoc,
+ IdentifierInfo &Member) {
+ if (!FullLocInfo)
+ return new MemberExpr((Expr*)Base, OpKind == tok::arrow, Member);
+ else
+ return new MemberExprLOC((Expr*)Base, OpLoc, OpKind == tok::arrow,
+ MemberLoc, Member);
+}
+
+/// 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.
+ASTBuilder::ExprTy *ASTBuilder::
+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);
+}
+
+
// Binary Operators. 'Tok' is the token for the operator.
ASTBuilder::ExprTy *ASTBuilder::ParseBinOp(const LexerToken &Tok, ExprTy *LHS,
ExprTy *RHS) {
Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=38943&r1=38942&r2=38943&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:26:04 2007
@@ -610,10 +610,12 @@
}
// Match the ')'.
- if (!LHS.isInvalid && ArgExprsOk && Tok.getKind() == tok::r_paren)
+ if (!LHS.isInvalid && ArgExprsOk && Tok.getKind() == tok::r_paren) {
+ assert((ArgExprs.size() == 0 || ArgExprs.size()-1 == CommaLocs.size())&&
+ "Unexpected number of commas!");
LHS = Actions.ParseCallExpr(LHS.Val, Loc, &ArgExprs[0], ArgExprs.size(),
- &CommaLocs[0], CommaLocs.size(),
- Tok.getLocation());
+ &CommaLocs[0], Tok.getLocation());
+ }
MatchRHSPunctuation(tok::r_paren, Loc);
break;
Modified: cfe/cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.cpp?rev=38943&r1=38942&r2=38943&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:26:04 2007
@@ -51,6 +51,22 @@
virtual ExprTy *ParseUnaryOp(const LexerToken &Tok, ExprTy *Input);
virtual ExprTy *ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input);
+ virtual ExprTy *ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
+ ExprTy *Idx, SourceLocation RLoc);
+ virtual ExprTy *ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
+ tok::TokenKind OpKind,
+ SourceLocation MemberLoc,
+ IdentifierInfo &Member);
+
+ /// 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.
+ virtual ExprTy *ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
+ ExprTy **Args, unsigned NumArgs,
+ SourceLocation *CommaLocs,
+ SourceLocation RParenLoc);
+
+
virtual ExprTy *ParseBinOp(const LexerToken &Tok, ExprTy *LHS, ExprTy *RHS);
/// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
@@ -162,6 +178,41 @@
return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc);
}
+ASTBuilder::ExprTy *ASTBuilder::
+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);
+}
+
+ASTBuilder::ExprTy *ASTBuilder::
+ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
+ tok::TokenKind OpKind, SourceLocation MemberLoc,
+ IdentifierInfo &Member) {
+ if (!FullLocInfo)
+ return new MemberExpr((Expr*)Base, OpKind == tok::arrow, Member);
+ else
+ return new MemberExprLOC((Expr*)Base, OpLoc, OpKind == tok::arrow,
+ MemberLoc, Member);
+}
+
+/// 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.
+ASTBuilder::ExprTy *ASTBuilder::
+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);
+}
+
+
// Binary Operators. 'Tok' is the token for the operator.
ASTBuilder::ExprTy *ASTBuilder::ParseBinOp(const LexerToken &Tok, ExprTy *LHS,
ExprTy *RHS) {
Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=38943&r1=38942&r2=38943&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:26:04 2007
@@ -15,9 +15,11 @@
#define LLVM_CLANG_AST_EXPR_H
#include "clang/Basic/SourceLocation.h"
+#include <cassert>
namespace llvm {
namespace clang {
+ class IdentifierInfo;
/// Expr - This represents one expression etc.
///
@@ -97,6 +99,88 @@
};
+/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
+class ArraySubscriptExpr : public Expr {
+ Expr *Base, *Idx;
+public:
+ ArraySubscriptExpr(Expr *base, Expr *idx) : Base(base), Idx(idx) {}
+
+ virtual void dump_impl() const;
+};
+
+
+class ArraySubscriptExprLOC : public ArraySubscriptExpr {
+ SourceLocation LLoc, RLoc;
+public:
+ ArraySubscriptExprLOC(Expr *Base, SourceLocation lloc, Expr *Idx,
+ SourceLocation rloc)
+ : ArraySubscriptExpr(Base, Idx), LLoc(lloc), RLoc(rloc) {}
+};
+
+/// CallExpr - [C99 6.5.2.2] Function Calls.
+///
+class CallExpr : public Expr {
+ Expr *Fn;
+ Expr **Args;
+ unsigned NumArgs;
+public:
+ CallExpr(Expr *fn, Expr **args, unsigned numargs);
+ ~CallExpr() {
+ delete [] Args;
+ }
+
+ /// getNumArgs - Return the number of actual arguments to this call.
+ ///
+ unsigned getNumArgs() const { return NumArgs; }
+
+ /// getArg - Return the specified argument.
+ Expr *getArg(unsigned Arg) const {
+ assert(Arg < NumArgs && "Arg access out of range!");
+ return Args[Arg];
+ }
+
+ /// getNumCommas - Return the number of commas that must have been present in
+ /// this function call.
+ unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
+
+ virtual void dump_impl() const;
+};
+
+class CallExprLOC : public CallExpr {
+ SourceLocation LParenLoc, RParenLoc;
+ SourceLocation *CommaLocs;
+public:
+ CallExprLOC(Expr *Fn, SourceLocation lparenloc, Expr **Args, unsigned NumArgs,
+ SourceLocation *commalocs, SourceLocation rparenloc);
+ ~CallExprLOC() {
+ delete [] CommaLocs;
+ }
+};
+
+/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.
+///
+class MemberExpr : public Expr {
+ Expr *Base;
+ // TODO: union { Decl *MemberDecl; IdentifierInfo *MemberII; };
+ IdentifierInfo *MemberII;
+ bool isArrow; // True if this is "X->F", false if this is "X.F".
+public:
+ MemberExpr(Expr *base, bool isarrow, IdentifierInfo &memberii)
+ : Base(base), MemberII(&memberii), isArrow(isarrow) {
+ }
+ virtual void dump_impl() const;
+};
+
+class MemberExprLOC : public MemberExpr {
+ SourceLocation OpLoc, MemberLoc;
+public:
+ MemberExprLOC(Expr *Base, SourceLocation oploc, bool isArrow,
+ SourceLocation memberLoc, IdentifierInfo &MemberII)
+ : MemberExpr(Base, isArrow, MemberII), OpLoc(oploc), MemberLoc(memberLoc) {
+ }
+
+};
+
class BinaryOperator : public Expr {
public:
enum Opcode {
Modified: cfe/cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Action.h?rev=38943&r1=38942&r2=38943&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:26:04 2007
@@ -100,10 +100,11 @@
/// 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.
+ /// locations. There are guaranteed to be one fewer commas than arguments,
+ /// unless there are zero arguments.
virtual ExprTy *ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
ExprTy **Args, unsigned NumArgs,
- SourceLocation *CommaLocs, unsigned NumCommas,
+ SourceLocation *CommaLocs,
SourceLocation RParenLoc) {
return 0;
}
More information about the cfe-commits
mailing list