[cfe-commits] r38944 - 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:05 PDT 2007
Author: sabre
Date: Wed Jul 11 11:26:04 2007
New Revision: 38944
URL: http://llvm.org/viewvc/llvm-project?rev=38944&view=rev
Log:
Add initial support for simple-primary exprs, including DeclExprs.
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=38944&r1=38943&r2=38944&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:26:04 2007
@@ -27,6 +27,9 @@
std::cerr << ")";
}
+void DeclExpr::dump_impl() const {
+ std::cerr << "x";
+}
void IntegerConstant::dump_impl() const {
std::cerr << "1";
Modified: cfe/cfe/trunk/AST/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.cpp?rev=38944&r1=38943&r2=38944&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:26:04 2007
@@ -42,6 +42,7 @@
// Expression Parsing Callbacks.
// Primary Expressions.
+ virtual ExprTy *ParseSimplePrimaryExpr(const LexerToken &Tok);
virtual ExprTy *ParseIntegerConstant(const LexerToken &Tok);
virtual ExprTy *ParseFloatingConstant(const LexerToken &Tok);
virtual ExprTy *ParseParenExpr(SourceLocation L, SourceLocation R,
@@ -122,6 +123,25 @@
// Expression Parsing Callbacks.
//===--------------------------------------------------------------------===//
+ASTBuilder::ExprTy *ASTBuilder::ParseSimplePrimaryExpr(const LexerToken &Tok) {
+ switch (Tok.getKind()) {
+ 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]
+ assert(0 && "Unimp so far!");
+ return 0;
+ }
+}
+
ASTBuilder::ExprTy *ASTBuilder::ParseIntegerConstant(const LexerToken &Tok) {
return new IntegerConstant();
}
Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=38944&r1=38943&r2=38944&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:26:04 2007
@@ -477,8 +477,7 @@
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]
- // TODO: Build AST.
- Res = ExprResult(false);
+ Res = Actions.ParseSimplePrimaryExpr(Tok);
ConsumeToken();
// These can be followed by postfix-expr pieces.
return ParsePostfixExpressionSuffix(Res);
Modified: cfe/cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.cpp?rev=38944&r1=38943&r2=38944&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:26:04 2007
@@ -42,6 +42,7 @@
// Expression Parsing Callbacks.
// Primary Expressions.
+ virtual ExprTy *ParseSimplePrimaryExpr(const LexerToken &Tok);
virtual ExprTy *ParseIntegerConstant(const LexerToken &Tok);
virtual ExprTy *ParseFloatingConstant(const LexerToken &Tok);
virtual ExprTy *ParseParenExpr(SourceLocation L, SourceLocation R,
@@ -122,6 +123,25 @@
// Expression Parsing Callbacks.
//===--------------------------------------------------------------------===//
+ASTBuilder::ExprTy *ASTBuilder::ParseSimplePrimaryExpr(const LexerToken &Tok) {
+ switch (Tok.getKind()) {
+ 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]
+ assert(0 && "Unimp so far!");
+ return 0;
+ }
+}
+
ASTBuilder::ExprTy *ASTBuilder::ParseIntegerConstant(const LexerToken &Tok) {
return new IntegerConstant();
}
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=38944&r1=38943&r2=38944&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
@@ -20,6 +20,7 @@
namespace llvm {
namespace clang {
class IdentifierInfo;
+ class Decl;
/// Expr - This represents one expression etc.
///
@@ -40,6 +41,16 @@
// Primary Expressions.
//===----------------------------------------------------------------------===//
+/// DeclExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
+/// enum, etc.
+class DeclExpr : public Expr {
+ // TODO: Union with the decl when resolved.
+ Decl &D;
+public:
+ DeclExpr(Decl &d) : D(d) {}
+ virtual void dump_impl() const;
+};
+
class IntegerConstant : public Expr {
public:
IntegerConstant() {}
@@ -99,6 +110,11 @@
};
+
+//===----------------------------------------------------------------------===//
+// Postfix Operators.
+//===----------------------------------------------------------------------===//
+
/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
class ArraySubscriptExpr : public Expr {
Expr *Base, *Idx;
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=38944&r1=38943&r2=38944&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
@@ -72,6 +72,7 @@
//===--------------------------------------------------------------------===//
// Primary Expressions.
+ virtual ExprTy *ParseSimplePrimaryExpr(const LexerToken &Tok) { return 0; }
virtual ExprTy *ParseIntegerConstant(const LexerToken &Tok) { return 0; }
virtual ExprTy *ParseFloatingConstant(const LexerToken &Tok) { return 0; }
More information about the cfe-commits
mailing list