blob: 3c8111ebdf8a7851d1af6e722fa0e82eb2b08ff4 [file] [log] [blame]
Chris Lattner7cee11f2006-11-03 06:42:29 +00001//===--- ASTBuilder.h - Stream ASTs for top-level decls --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the ASTBuilder interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_ASTBUILDER_H
15#define LLVM_CLANG_AST_ASTBUILDER_H
16
17#include "clang/Parse/Action.h"
18#include <vector>
19
20namespace llvm {
21namespace clang {
22 class Preprocessor;
23 class Decl;
24
25/// ASTBuilder - This is a simple implementation of the actions module which
26/// builds AST nodes for the code being parsed. Clients can either use this
27/// unmodified or subclass it and overload methods to do more specialized
28/// things.
29class ASTBuilder : public Action {
30 Preprocessor &PP;
31
Chris Lattner7cee11f2006-11-03 06:42:29 +000032 /// LastInGroupList - This vector is populated when there are multiple
33 /// declarators in a single decl group (e.g. "int A, B, C"). In this case,
34 /// all but the last decl will be entered into this. This is used by the
35 /// ASTStreamer.
36 std::vector<Decl*> &LastInGroupList;
37public:
Chris Lattner72b7d392006-11-04 06:37:16 +000038 ASTBuilder(Preprocessor &pp, std::vector<Decl*> &prevInGroup)
39 : PP(pp), LastInGroupList(prevInGroup) {}
Chris Lattner7cee11f2006-11-03 06:42:29 +000040
41 //===--------------------------------------------------------------------===//
42 // Symbol table tracking callbacks.
43 //
44 virtual bool isTypeName(const IdentifierInfo &II, Scope *S) const;
45 virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
46 DeclTy *LastInGroup);
47 virtual DeclTy *ParseFunctionDefinition(Scope *S, Declarator &D,
48 StmtTy *Body);
49 virtual void PopScope(SourceLocation Loc, Scope *S);
50
51 //===--------------------------------------------------------------------===//
52 // Statement Parsing Callbacks.
53
54 virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R,
55 StmtTy **Elts, unsigned NumElts);
56 virtual StmtResult ParseExprStmt(ExprTy *Expr) {
Chris Lattner7cee11f2006-11-03 06:42:29 +000057 return Expr; // Exprs are Stmts.
58 }
Chris Lattner6c0ff132006-11-05 00:19:50 +000059 virtual StmtResult ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
60 SourceLocation DotDotDotLoc, ExprTy *RHSVal,
61 SourceLocation ColonLoc, StmtTy *SubStmt);
62 virtual StmtResult ParseDefaultStmt(SourceLocation DefaultLoc,
63 SourceLocation ColonLoc, StmtTy *SubStmt);
64 virtual StmtResult ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
65 SourceLocation ColonLoc, StmtTy *SubStmt);
Chris Lattner7cee11f2006-11-03 06:42:29 +000066 virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
67 StmtTy *ThenVal, SourceLocation ElseLoc,
68 StmtTy *ElseVal);
Chris Lattnerf2174b62006-11-04 20:59:27 +000069 virtual StmtResult ParseSwitchStmt(SourceLocation SwitchLoc, ExprTy *Cond,
70 StmtTy *Body);
Chris Lattner85ed8732006-11-04 20:40:44 +000071 virtual StmtResult ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
72 StmtTy *Body);
73 virtual StmtResult ParseDoStmt(SourceLocation DoLoc, StmtTy *Body,
74 SourceLocation WhileLoc, ExprTy *Cond);
75
Chris Lattner71e23ce2006-11-04 20:18:38 +000076 virtual StmtResult ParseForStmt(SourceLocation ForLoc,
77 SourceLocation LParenLoc,
78 StmtTy *First, ExprTy *Second, ExprTy *Third,
79 SourceLocation RParenLoc, StmtTy *Body);
Chris Lattner16976d32006-11-05 01:46:01 +000080 virtual StmtResult ParseGotoStmt(SourceLocation GotoLoc,
81 SourceLocation LabelLoc,
82 IdentifierInfo *LabelII);
83 virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc,
84 SourceLocation StarLoc,
85 ExprTy *DestExp);
86 virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc);
87 virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc);
Chris Lattner71e23ce2006-11-04 20:18:38 +000088
Chris Lattner7cee11f2006-11-03 06:42:29 +000089 virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
90 ExprTy *RetValExp);
91
92 //===--------------------------------------------------------------------===//
93 // Expression Parsing Callbacks.
94
95 // Primary Expressions.
96 virtual ExprResult ParseSimplePrimaryExpr(SourceLocation Loc,
97 tok::TokenKind Kind);
98 virtual ExprResult ParseIntegerConstant(SourceLocation Loc);
99 virtual ExprResult ParseFloatingConstant(SourceLocation Loc);
100 virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
101 ExprTy *Val);
102 virtual ExprResult ParseStringExpr(const char *StrData, unsigned StrLen,
103 bool isWide,
104 SourceLocation *TokLocs, unsigned NumToks);
105
106 // Binary/Unary Operators. 'Tok' is the token for the operator.
107 virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
108 ExprTy *Input);
109 virtual ExprResult
110 ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
111 SourceLocation LParenLoc, TypeTy *Ty,
112 SourceLocation RParenLoc);
113
114 virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc,
115 tok::TokenKind Kind, ExprTy *Input);
116
117 virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
118 ExprTy *Idx, SourceLocation RLoc);
119 virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
120 tok::TokenKind OpKind,
121 SourceLocation MemberLoc,
122 IdentifierInfo &Member);
123
124 /// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
125 /// This provides the location of the left/right parens and a list of comma
126 /// locations.
127 virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
128 ExprTy **Args, unsigned NumArgs,
129 SourceLocation *CommaLocs,
130 SourceLocation RParenLoc);
131
132 virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
133 SourceLocation RParenLoc, ExprTy *Op);
134
135 virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
136 ExprTy *LHS,ExprTy *RHS);
137
138 /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
139 /// in the case of a the GNU conditional expr extension.
140 virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc,
141 SourceLocation ColonLoc,
142 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
143};
144
145
146} // end namespace clang
147} // end namespace llvm
148
149#endif