blob: b39c95f5403b0a5dd6b8b8deef4b165ba0025f7a [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
32 /// FullLocInfo - If this is true, the ASTBuilder constructs AST Nodes that
33 /// capture maximal location information for each source-language construct.
34 bool FullLocInfo;
35
36 /// LastInGroupList - This vector is populated when there are multiple
37 /// declarators in a single decl group (e.g. "int A, B, C"). In this case,
38 /// all but the last decl will be entered into this. This is used by the
39 /// ASTStreamer.
40 std::vector<Decl*> &LastInGroupList;
41public:
42 ASTBuilder(Preprocessor &pp, bool fullLocInfo,
43 std::vector<Decl*> &prevInGroup)
44 : PP(pp), FullLocInfo(fullLocInfo), LastInGroupList(prevInGroup) {}
45
46 //===--------------------------------------------------------------------===//
47 // Symbol table tracking callbacks.
48 //
49 virtual bool isTypeName(const IdentifierInfo &II, Scope *S) const;
50 virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
51 DeclTy *LastInGroup);
52 virtual DeclTy *ParseFunctionDefinition(Scope *S, Declarator &D,
53 StmtTy *Body);
54 virtual void PopScope(SourceLocation Loc, Scope *S);
55
56 //===--------------------------------------------------------------------===//
57 // Statement Parsing Callbacks.
58
59 virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R,
60 StmtTy **Elts, unsigned NumElts);
61 virtual StmtResult ParseExprStmt(ExprTy *Expr) {
62 // TODO: Full info should track this with a node.
63 return Expr; // Exprs are Stmts.
64 }
65
66 virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
67 StmtTy *ThenVal, SourceLocation ElseLoc,
68 StmtTy *ElseVal);
69
70 virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
71 ExprTy *RetValExp);
72
73 //===--------------------------------------------------------------------===//
74 // Expression Parsing Callbacks.
75
76 // Primary Expressions.
77 virtual ExprResult ParseSimplePrimaryExpr(SourceLocation Loc,
78 tok::TokenKind Kind);
79 virtual ExprResult ParseIntegerConstant(SourceLocation Loc);
80 virtual ExprResult ParseFloatingConstant(SourceLocation Loc);
81 virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
82 ExprTy *Val);
83 virtual ExprResult ParseStringExpr(const char *StrData, unsigned StrLen,
84 bool isWide,
85 SourceLocation *TokLocs, unsigned NumToks);
86
87 // Binary/Unary Operators. 'Tok' is the token for the operator.
88 virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
89 ExprTy *Input);
90 virtual ExprResult
91 ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
92 SourceLocation LParenLoc, TypeTy *Ty,
93 SourceLocation RParenLoc);
94
95 virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc,
96 tok::TokenKind Kind, ExprTy *Input);
97
98 virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
99 ExprTy *Idx, SourceLocation RLoc);
100 virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
101 tok::TokenKind OpKind,
102 SourceLocation MemberLoc,
103 IdentifierInfo &Member);
104
105 /// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
106 /// This provides the location of the left/right parens and a list of comma
107 /// locations.
108 virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
109 ExprTy **Args, unsigned NumArgs,
110 SourceLocation *CommaLocs,
111 SourceLocation RParenLoc);
112
113 virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
114 SourceLocation RParenLoc, ExprTy *Op);
115
116 virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
117 ExprTy *LHS,ExprTy *RHS);
118
119 /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
120 /// in the case of a the GNU conditional expr extension.
121 virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc,
122 SourceLocation ColonLoc,
123 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
124};
125
126
127} // end namespace clang
128} // end namespace llvm
129
130#endif