2006-11-09 06:54:47 +00:00
|
|
|
//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
|
2006-11-03 06:42:29 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-11-09 06:54:47 +00:00
|
|
|
// This file defines the Sema class, which performs semantic analysis and
|
|
|
|
// builds ASTs.
|
2006-11-03 06:42:29 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-11-09 06:54:47 +00:00
|
|
|
#ifndef LLVM_CLANG_AST_SEMA_H
|
|
|
|
#define LLVM_CLANG_AST_SEMA_H
|
2006-11-03 06:42:29 +00:00
|
|
|
|
|
|
|
#include "clang/Parse/Action.h"
|
2007-05-28 06:28:18 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-07-22 07:07:56 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2006-11-03 06:42:29 +00:00
|
|
|
#include <vector>
|
2006-11-10 05:17:58 +00:00
|
|
|
#include <string>
|
2006-11-03 06:42:29 +00:00
|
|
|
|
2007-08-23 05:46:52 +00:00
|
|
|
namespace llvm {
|
|
|
|
class APSInt;
|
|
|
|
}
|
|
|
|
|
2006-11-03 06:42:29 +00:00
|
|
|
namespace clang {
|
2006-11-10 06:20:45 +00:00
|
|
|
class ASTContext;
|
2006-11-03 06:42:29 +00:00
|
|
|
class Preprocessor;
|
|
|
|
class Decl;
|
2007-09-13 18:10:37 +00:00
|
|
|
class ScopedDecl;
|
2007-04-02 22:55:05 +00:00
|
|
|
class Expr;
|
2007-09-02 15:34:30 +00:00
|
|
|
class InitListExpr;
|
2007-01-21 07:42:07 +00:00
|
|
|
class VarDecl;
|
2007-06-13 20:44:40 +00:00
|
|
|
class ParmVarDecl;
|
2007-01-27 19:27:06 +00:00
|
|
|
class TypedefDecl;
|
|
|
|
class FunctionDecl;
|
2007-04-05 22:36:20 +00:00
|
|
|
class QualType;
|
2007-09-04 02:45:27 +00:00
|
|
|
struct LangOptions;
|
|
|
|
struct DeclaratorChunk;
|
2007-07-20 16:59:19 +00:00
|
|
|
class Token;
|
2007-05-07 00:24:15 +00:00
|
|
|
class IntegerLiteral;
|
2007-05-08 21:09:37 +00:00
|
|
|
class ArrayType;
|
2007-05-28 06:28:18 +00:00
|
|
|
class LabelStmt;
|
2007-07-22 07:07:56 +00:00
|
|
|
class SwitchStmt;
|
2007-07-27 22:15:19 +00:00
|
|
|
class OCUVectorType;
|
2007-07-29 16:33:31 +00:00
|
|
|
class TypedefDecl;
|
2007-09-29 00:54:24 +00:00
|
|
|
class ObjcInterfaceDecl;
|
2007-09-29 17:04:06 +00:00
|
|
|
class ObjcProtocolDecl;
|
2007-09-29 17:14:55 +00:00
|
|
|
class ObjcImplementationDecl;
|
2007-10-02 16:38:50 +00:00
|
|
|
class ObjcCategoryImplDecl;
|
|
|
|
class ObjcCategoryDecl;
|
2007-10-02 21:43:37 +00:00
|
|
|
class ObjcIvarDecl;
|
2007-07-29 16:33:31 +00:00
|
|
|
|
2006-11-09 06:54:47 +00:00
|
|
|
/// Sema - This implements semantic analysis and AST building for C.
|
|
|
|
class Sema : public Action {
|
2007-02-28 01:22:02 +00:00
|
|
|
Preprocessor &PP;
|
|
|
|
|
2006-11-10 06:20:45 +00:00
|
|
|
ASTContext &Context;
|
2006-11-03 06:42:29 +00:00
|
|
|
|
2006-11-21 01:21:07 +00:00
|
|
|
/// CurFunctionDecl - If inside of a function body, this contains a pointer to
|
|
|
|
/// the function decl for the function being parsed.
|
|
|
|
FunctionDecl *CurFunctionDecl;
|
|
|
|
|
2006-11-03 06:42:29 +00: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;
|
2007-05-28 06:28:18 +00:00
|
|
|
|
|
|
|
/// LabelMap - This is a mapping from label identifiers to the LabelStmt for
|
|
|
|
/// it (which acts like the label decl in some ways). Forward referenced
|
|
|
|
/// labels have a LabelStmt created for them with a null location & SubStmt.
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
|
2007-07-22 07:07:56 +00:00
|
|
|
|
|
|
|
llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
|
2007-07-29 16:33:31 +00:00
|
|
|
|
|
|
|
/// OCUVectorDecls - This is a list all the OCU vector types. This allows
|
|
|
|
/// us to associate a raw vector type with one of the OCU type names.
|
|
|
|
/// This is only necessary for issuing pretty diagnostics.
|
|
|
|
llvm::SmallVector<TypedefDecl*, 24> OCUVectorDecls;
|
2007-08-10 20:18:51 +00:00
|
|
|
|
|
|
|
// Enum values used by KnownFunctionIDs (see below).
|
|
|
|
enum {
|
|
|
|
id_printf,
|
|
|
|
id_fprintf,
|
|
|
|
id_sprintf,
|
|
|
|
id_snprintf,
|
|
|
|
id_asprintf,
|
2007-08-10 21:13:51 +00:00
|
|
|
id_vsnprintf,
|
2007-08-10 20:18:51 +00:00
|
|
|
id_vasprintf,
|
|
|
|
id_vfprintf,
|
|
|
|
id_vsprintf,
|
|
|
|
id_vprintf,
|
|
|
|
id_num_known_functions
|
|
|
|
};
|
|
|
|
|
|
|
|
/// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
|
|
|
|
/// of known functions used by the semantic analysis to do various
|
|
|
|
/// kinds of checking (e.g. checking format string errors in printf calls).
|
|
|
|
/// This list is populated upon the creation of a Sema object.
|
|
|
|
IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ];
|
|
|
|
|
2006-11-03 06:42:29 +00:00
|
|
|
public:
|
2007-02-28 19:32:13 +00:00
|
|
|
Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
|
2006-11-03 06:42:29 +00:00
|
|
|
|
2006-11-20 06:49:47 +00:00
|
|
|
const LangOptions &getLangOptions() const;
|
|
|
|
|
2007-05-18 22:53:50 +00:00
|
|
|
/// The primitive diagnostic helpers - always returns true, which simplifies
|
|
|
|
/// error handling (i.e. less code).
|
2007-05-16 17:56:50 +00:00
|
|
|
bool Diag(SourceLocation Loc, unsigned DiagID);
|
|
|
|
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
|
|
|
|
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
|
|
|
|
const std::string &Msg2);
|
2007-05-18 22:53:50 +00:00
|
|
|
|
|
|
|
/// More expressive diagnostic helpers for expressions (say that 6 times:-)
|
|
|
|
bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1);
|
|
|
|
bool Diag(SourceLocation Loc, unsigned DiagID,
|
|
|
|
SourceRange R1, SourceRange R2);
|
|
|
|
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
|
|
|
|
SourceRange R1);
|
|
|
|
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
|
|
|
|
SourceRange R1, SourceRange R2);
|
|
|
|
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
|
|
|
|
const std::string &Msg2, SourceRange R1);
|
|
|
|
bool Diag(SourceLocation Loc, unsigned DiagID,
|
|
|
|
const std::string &Msg1, const std::string &Msg2,
|
|
|
|
SourceRange R1, SourceRange R2);
|
2007-09-29 00:54:24 +00:00
|
|
|
|
2007-08-31 04:53:24 +00:00
|
|
|
virtual void DeleteExpr(ExprTy *E);
|
|
|
|
virtual void DeleteStmt(StmtTy *S);
|
|
|
|
|
2006-11-11 22:59:23 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Type Analysis / Processing: SemaType.cpp.
|
|
|
|
//
|
2007-04-05 22:36:20 +00:00
|
|
|
QualType GetTypeForDeclarator(Declarator &D, Scope *S);
|
2006-11-11 22:59:23 +00:00
|
|
|
|
2007-09-15 18:49:24 +00:00
|
|
|
virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
|
2006-11-11 22:59:23 +00:00
|
|
|
|
2007-09-15 18:49:24 +00:00
|
|
|
virtual TypeResult ActOnParamDeclaratorType(Scope *S, Declarator &D);
|
2007-03-21 21:08:52 +00:00
|
|
|
private:
|
2006-11-03 06:42:29 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
2006-11-10 05:29:30 +00:00
|
|
|
// Symbol table / Decl tracking callbacks: SemaDecl.cpp.
|
2006-11-03 06:42:29 +00:00
|
|
|
//
|
2006-11-20 01:29:42 +00:00
|
|
|
virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
|
2007-09-15 18:49:24 +00:00
|
|
|
virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup);
|
2007-09-12 14:07:44 +00:00
|
|
|
void AddInitializerToDecl(DeclTy *dcl, ExprTy *init);
|
2007-06-09 00:53:06 +00:00
|
|
|
virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
|
|
|
|
|
2007-01-21 07:42:07 +00:00
|
|
|
virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D);
|
2006-11-21 01:21:07 +00:00
|
|
|
virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body);
|
2006-11-03 06:42:29 +00:00
|
|
|
virtual void PopScope(SourceLocation Loc, Scope *S);
|
2007-01-27 19:27:06 +00:00
|
|
|
|
2006-11-19 02:43:37 +00:00
|
|
|
/// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
|
|
|
|
/// no declarator (e.g. "struct foo;") is parsed.
|
|
|
|
virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
|
|
|
|
|
2007-09-15 18:49:24 +00:00
|
|
|
virtual DeclTy *ActOnTag(Scope *S, unsigned TagType, TagKind TK,
|
2007-01-23 04:08:05 +00:00
|
|
|
SourceLocation KWLoc, IdentifierInfo *Name,
|
2007-06-09 03:47:53 +00:00
|
|
|
SourceLocation NameLoc, AttributeList *Attr);
|
2007-09-15 18:49:24 +00:00
|
|
|
virtual DeclTy *ActOnField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart,
|
2007-01-23 23:42:53 +00:00
|
|
|
Declarator &D, ExprTy *BitfieldWidth);
|
2007-09-14 23:09:53 +00:00
|
|
|
|
|
|
|
// This is used for both record definitions and ObjC interface declarations.
|
2007-09-29 00:54:24 +00:00
|
|
|
virtual void ActOnFields(Scope* S,
|
|
|
|
SourceLocation RecLoc, DeclTy *TagDecl,
|
2007-09-14 23:09:53 +00:00
|
|
|
DeclTy **Fields, unsigned NumFields,
|
|
|
|
tok::ObjCKeywordKind *visibility = 0);
|
2007-09-15 18:49:24 +00:00
|
|
|
virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
|
2007-06-11 01:28:17 +00:00
|
|
|
DeclTy *LastEnumConstant,
|
2007-01-25 07:29:02 +00:00
|
|
|
SourceLocation IdLoc, IdentifierInfo *Id,
|
|
|
|
SourceLocation EqualLoc, ExprTy *Val);
|
2007-09-15 18:49:24 +00:00
|
|
|
virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
|
2007-01-25 07:29:02 +00:00
|
|
|
DeclTy **Elements, unsigned NumElements);
|
2007-03-14 21:52:03 +00:00
|
|
|
private:
|
2007-09-15 18:49:24 +00:00
|
|
|
/// Subroutines of ActOnDeclarator()...
|
2007-09-13 23:52:58 +00:00
|
|
|
TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, ScopedDecl *LastDecl);
|
2007-09-13 21:41:19 +00:00
|
|
|
TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *Old);
|
|
|
|
FunctionDecl *MergeFunctionDecl(FunctionDecl *New, ScopedDecl *Old);
|
|
|
|
VarDecl *MergeVarDecl(VarDecl *New, ScopedDecl *Old);
|
2007-03-21 21:08:52 +00:00
|
|
|
/// AddTopLevelDecl - called after the decl has been fully processed.
|
|
|
|
/// Allows for bookkeeping and post-processing of each declaration.
|
|
|
|
void AddTopLevelDecl(Decl *current, Decl *last);
|
2007-03-16 00:33:25 +00:00
|
|
|
|
2007-03-14 21:52:03 +00:00
|
|
|
/// More parsing and symbol table subroutines...
|
2007-06-13 20:44:40 +00:00
|
|
|
ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo,
|
|
|
|
Scope *FnBodyScope);
|
2007-09-13 18:10:37 +00:00
|
|
|
ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
|
|
|
|
SourceLocation IdLoc, Scope *S);
|
2007-10-02 20:01:56 +00:00
|
|
|
ObjcInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
|
2007-09-29 17:04:06 +00:00
|
|
|
ObjcProtocolDecl *getObjCProtocolDecl(Scope *S,
|
|
|
|
IdentifierInfo *Id, SourceLocation IdLoc);
|
2007-09-13 18:10:37 +00:00
|
|
|
ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
|
2007-09-16 16:16:00 +00:00
|
|
|
ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
|
2007-03-14 21:52:03 +00:00
|
|
|
Scope *S);
|
2007-06-11 00:35:03 +00:00
|
|
|
// Decl attributes - this routine is the top level dispatcher.
|
|
|
|
void HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix,
|
|
|
|
AttributeList *declarator_postfix);
|
|
|
|
void HandleDeclAttribute(Decl *New, AttributeList *rawAttr);
|
|
|
|
|
|
|
|
// HandleVectorTypeAttribute - this attribute is only applicable to
|
|
|
|
// integral and float scalars, although arrays, pointers, and function
|
|
|
|
// return values are allowed in conjunction with this construct. Aggregates
|
|
|
|
// with this attribute are invalid, even if they are of the same size as a
|
|
|
|
// corresponding scalar.
|
|
|
|
// The raw attribute should contain precisely 1 argument, the vector size
|
|
|
|
// for the variable, measured in bytes. If curType and rawAttr are well
|
|
|
|
// formed, this routine will return a new vector type.
|
2007-07-06 23:09:18 +00:00
|
|
|
QualType HandleVectorTypeAttribute(QualType curType, AttributeList *rawAttr);
|
2007-07-29 16:33:31 +00:00
|
|
|
void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr);
|
2007-01-23 23:42:53 +00:00
|
|
|
|
2007-09-29 17:14:55 +00:00
|
|
|
/// CheckProtocolMethodDefs - This routine checks unimpletented methods
|
|
|
|
/// Declared in protocol, and those referenced by it.
|
|
|
|
void CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl,
|
2007-10-02 20:06:01 +00:00
|
|
|
bool& IncompleteImpl,
|
2007-09-29 17:14:55 +00:00
|
|
|
const llvm::DenseMap<void *, char>& InsMap,
|
|
|
|
const llvm::DenseMap<void *, char>& ClsMap);
|
|
|
|
|
2007-10-02 21:43:37 +00:00
|
|
|
/// CheckImplementationIvars - This routine checks if the instance variables
|
|
|
|
/// listed in the implelementation match those listed in the interface.
|
|
|
|
void CheckImplementationIvars(ObjcImplementationDecl *ImpDecl,
|
|
|
|
ObjcIvarDecl **Fields, unsigned nIvars);
|
|
|
|
|
2007-09-29 17:14:55 +00:00
|
|
|
/// ImplMethodsVsClassMethods - This is main routine to warn if any method
|
|
|
|
/// remains unimplemented in the @implementation class.
|
|
|
|
void ImplMethodsVsClassMethods(ObjcImplementationDecl* IMPDecl,
|
|
|
|
ObjcInterfaceDecl* IDecl);
|
|
|
|
|
2007-10-02 16:38:50 +00:00
|
|
|
/// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the
|
|
|
|
/// category interface is implemented in the category @implementation.
|
|
|
|
void ImplCategoryMethodsVsIntfMethods(ObjcCategoryImplDecl *CatImplDecl,
|
2007-10-02 20:06:01 +00:00
|
|
|
ObjcCategoryDecl *CatClassDecl);
|
2007-10-02 16:38:50 +00:00
|
|
|
|
2006-11-03 06:42:29 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
2006-11-10 05:29:30 +00:00
|
|
|
// Statement Parsing Callbacks: SemaStmt.cpp.
|
2007-03-14 21:52:03 +00:00
|
|
|
public:
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnExprStmt(ExprTy *Expr);
|
2007-06-27 05:38:08 +00:00
|
|
|
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnNullStmt(SourceLocation SemiLoc);
|
|
|
|
virtual StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
|
2007-08-31 21:49:55 +00:00
|
|
|
StmtTy **Elts, unsigned NumElts,
|
|
|
|
bool isStmtExpr);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnDeclStmt(DeclTy *Decl);
|
|
|
|
virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
|
2006-11-05 00:19:50 +00:00
|
|
|
SourceLocation DotDotDotLoc, ExprTy *RHSVal,
|
|
|
|
SourceLocation ColonLoc, StmtTy *SubStmt);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
|
2007-07-18 02:28:47 +00:00
|
|
|
SourceLocation ColonLoc, StmtTy *SubStmt,
|
|
|
|
Scope *CurScope);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
|
2006-11-05 00:19:50 +00:00
|
|
|
SourceLocation ColonLoc, StmtTy *SubStmt);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
|
2006-11-03 06:42:29 +00:00
|
|
|
StmtTy *ThenVal, SourceLocation ElseLoc,
|
|
|
|
StmtTy *ElseVal);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnStartOfSwitchStmt(ExprTy *Cond);
|
|
|
|
virtual StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
|
2007-07-22 07:07:56 +00:00
|
|
|
ExprTy *Body);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
|
2006-11-04 20:40:44 +00:00
|
|
|
StmtTy *Body);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
|
2006-11-04 20:40:44 +00:00
|
|
|
SourceLocation WhileLoc, ExprTy *Cond);
|
|
|
|
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnForStmt(SourceLocation ForLoc,
|
2006-11-04 20:18:38 +00:00
|
|
|
SourceLocation LParenLoc,
|
|
|
|
StmtTy *First, ExprTy *Second, ExprTy *Third,
|
|
|
|
SourceLocation RParenLoc, StmtTy *Body);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
|
2006-11-05 01:46:01 +00:00
|
|
|
SourceLocation LabelLoc,
|
|
|
|
IdentifierInfo *LabelII);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
|
2006-11-05 01:46:01 +00:00
|
|
|
SourceLocation StarLoc,
|
|
|
|
ExprTy *DestExp);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
|
2006-11-10 05:17:58 +00:00
|
|
|
Scope *CurScope);
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
|
2006-11-04 20:18:38 +00:00
|
|
|
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
|
2006-11-03 06:42:29 +00:00
|
|
|
ExprTy *RetValExp);
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2006-11-10 05:29:30 +00:00
|
|
|
// Expression Parsing Callbacks: SemaExpr.cpp.
|
2006-11-03 06:42:29 +00:00
|
|
|
|
|
|
|
// Primary Expressions.
|
2007-09-15 18:49:24 +00:00
|
|
|
virtual ExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
|
2006-11-20 06:49:47 +00:00
|
|
|
IdentifierInfo &II,
|
|
|
|
bool HasTrailingLParen);
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnPreDefinedExpr(SourceLocation Loc,
|
2006-11-03 06:42:29 +00:00
|
|
|
tok::TokenKind Kind);
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnNumericConstant(const Token &);
|
|
|
|
virtual ExprResult ActOnCharacterConstant(const Token &);
|
|
|
|
virtual ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
|
2006-11-03 06:42:29 +00:00
|
|
|
ExprTy *Val);
|
2006-11-09 06:32:27 +00:00
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
/// ActOnStringLiteral - The specified tokens were lexed as pasted string
|
2006-11-09 06:32:27 +00:00
|
|
|
/// fragments (e.g. "foo" "bar" L"baz").
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
|
2006-11-09 06:32:27 +00:00
|
|
|
|
2006-11-03 06:42:29 +00:00
|
|
|
// Binary/Unary Operators. 'Tok' is the token for the operator.
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
|
2006-11-03 06:42:29 +00:00
|
|
|
ExprTy *Input);
|
|
|
|
virtual ExprResult
|
2007-09-16 03:34:24 +00:00
|
|
|
ActOnSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
|
2006-11-03 06:42:29 +00:00
|
|
|
SourceLocation LParenLoc, TypeTy *Ty,
|
|
|
|
SourceLocation RParenLoc);
|
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnPostfixUnaryOp(SourceLocation OpLoc,
|
2006-11-03 06:42:29 +00:00
|
|
|
tok::TokenKind Kind, ExprTy *Input);
|
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
|
2006-11-03 06:42:29 +00:00
|
|
|
ExprTy *Idx, SourceLocation RLoc);
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
|
2006-11-03 06:42:29 +00:00
|
|
|
tok::TokenKind OpKind,
|
|
|
|
SourceLocation MemberLoc,
|
|
|
|
IdentifierInfo &Member);
|
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
/// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
|
2006-11-03 06:42:29 +00:00
|
|
|
/// This provides the location of the left/right parens and a list of comma
|
|
|
|
/// locations.
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
|
2006-11-03 06:42:29 +00:00
|
|
|
ExprTy **Args, unsigned NumArgs,
|
|
|
|
SourceLocation *CommaLocs,
|
|
|
|
SourceLocation RParenLoc);
|
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
|
2006-11-03 06:42:29 +00:00
|
|
|
SourceLocation RParenLoc, ExprTy *Op);
|
2007-07-19 01:06:55 +00:00
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
|
2007-07-19 01:06:55 +00:00
|
|
|
SourceLocation RParenLoc, ExprTy *Op);
|
2006-11-03 06:42:29 +00:00
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
|
2007-07-19 01:06:55 +00:00
|
|
|
ExprTy **InitList, unsigned NumInit,
|
|
|
|
SourceLocation RParenLoc);
|
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
|
2006-11-03 06:42:29 +00:00
|
|
|
ExprTy *LHS,ExprTy *RHS);
|
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
/// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
|
2006-11-03 06:42:29 +00:00
|
|
|
/// in the case of a the GNU conditional expr extension.
|
2007-09-16 03:34:24 +00:00
|
|
|
virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
|
2006-11-03 06:42:29 +00:00
|
|
|
SourceLocation ColonLoc,
|
|
|
|
ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
|
2006-12-04 18:06:35 +00:00
|
|
|
|
2007-09-16 14:56:35 +00:00
|
|
|
/// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
|
|
|
|
virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
|
2007-05-28 06:56:27 +00:00
|
|
|
IdentifierInfo *LabelII);
|
|
|
|
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
|
2007-07-24 16:58:17 +00:00
|
|
|
SourceLocation RPLoc); // "({..})"
|
2007-08-30 17:45:32 +00:00
|
|
|
|
|
|
|
/// __builtin_offsetof(type, a.b[123][456].c)
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual ExprResult ActOnBuiltinOffsetOf(SourceLocation BuiltinLoc,
|
2007-08-30 17:45:32 +00:00
|
|
|
SourceLocation TypeLoc, TypeTy *Arg1,
|
|
|
|
OffsetOfComponent *CompPtr,
|
|
|
|
unsigned NumComponents,
|
|
|
|
SourceLocation RParenLoc);
|
|
|
|
|
2007-08-01 22:05:33 +00:00
|
|
|
// __builtin_types_compatible_p(type1, type2)
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
|
2007-08-01 22:05:33 +00:00
|
|
|
TypeTy *arg1, TypeTy *arg2,
|
|
|
|
SourceLocation RPLoc);
|
2007-08-03 21:21:27 +00:00
|
|
|
|
|
|
|
// __builtin_choose_expr(constExpr, expr1, expr2)
|
2007-09-16 14:56:35 +00:00
|
|
|
virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
|
2007-08-03 21:21:27 +00:00
|
|
|
ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
|
|
|
|
SourceLocation RPLoc);
|
2007-07-24 16:58:17 +00:00
|
|
|
|
2007-09-16 14:56:35 +00:00
|
|
|
/// ActOnCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
|
|
|
|
virtual ExprResult ActOnCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
|
2006-12-04 18:06:35 +00:00
|
|
|
SourceLocation LAngleBracketLoc, TypeTy *Ty,
|
|
|
|
SourceLocation RAngleBracketLoc,
|
|
|
|
SourceLocation LParenLoc, ExprTy *E,
|
|
|
|
SourceLocation RParenLoc);
|
2007-02-13 01:51:42 +00:00
|
|
|
|
2007-09-16 14:56:35 +00:00
|
|
|
/// ActOnCXXBoolLiteral - Parse {true,false} literals.
|
|
|
|
virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
|
2007-02-13 20:09:46 +00:00
|
|
|
tok::TokenKind Kind);
|
2007-08-21 17:43:55 +00:00
|
|
|
|
|
|
|
// ParseObjCStringLiteral - Parse Objective-C string literals.
|
|
|
|
virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
|
2007-08-22 15:14:15 +00:00
|
|
|
virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
TypeTy *Ty,
|
|
|
|
SourceLocation RParenLoc);
|
|
|
|
|
2007-09-06 21:24:23 +00:00
|
|
|
// Objective-C declarations.
|
2007-10-03 21:00:46 +00:00
|
|
|
virtual DeclTy *ActOnStartClassInterface(Scope* S,
|
2007-09-25 18:38:09 +00:00
|
|
|
SourceLocation AtInterafceLoc,
|
2007-09-06 21:24:23 +00:00
|
|
|
IdentifierInfo *ClassName, SourceLocation ClassLoc,
|
|
|
|
IdentifierInfo *SuperName, SourceLocation SuperLoc,
|
|
|
|
IdentifierInfo **ProtocolNames, unsigned NumProtocols,
|
|
|
|
AttributeList *AttrList);
|
|
|
|
|
2007-10-03 21:00:46 +00:00
|
|
|
virtual DeclTy *ActOnStartProtocolInterface(Scope* S,
|
2007-09-25 18:38:09 +00:00
|
|
|
SourceLocation AtProtoInterfaceLoc,
|
2007-09-17 21:07:36 +00:00
|
|
|
IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
|
|
|
|
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
|
|
|
|
|
2007-10-03 21:00:46 +00:00
|
|
|
virtual DeclTy *ActOnStartCategoryInterface(Scope* S,
|
2007-09-29 00:54:24 +00:00
|
|
|
SourceLocation AtInterfaceLoc,
|
2007-09-18 20:26:58 +00:00
|
|
|
IdentifierInfo *ClassName, SourceLocation ClassLoc,
|
|
|
|
IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
|
|
|
|
IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
|
|
|
|
|
2007-10-03 21:00:46 +00:00
|
|
|
virtual DeclTy *ActOnStartClassImplementation(Scope* S,
|
2007-09-25 18:38:09 +00:00
|
|
|
SourceLocation AtClassImplLoc,
|
|
|
|
IdentifierInfo *ClassName, SourceLocation ClassLoc,
|
|
|
|
IdentifierInfo *SuperClassname,
|
|
|
|
SourceLocation SuperClassLoc);
|
|
|
|
|
2007-10-03 21:00:46 +00:00
|
|
|
virtual DeclTy *ActOnStartCategoryImplementation(Scope* S,
|
2007-10-02 16:38:50 +00:00
|
|
|
SourceLocation AtCatImplLoc,
|
|
|
|
IdentifierInfo *ClassName,
|
|
|
|
SourceLocation ClassLoc,
|
|
|
|
IdentifierInfo *CatName,
|
|
|
|
SourceLocation CatLoc);
|
|
|
|
|
2007-10-02 22:39:18 +00:00
|
|
|
virtual DeclTy *ActOnForwardClassDeclaration(Scope *S, SourceLocation Loc,
|
|
|
|
IdentifierInfo **IdentList,
|
|
|
|
unsigned NumElts);
|
|
|
|
|
|
|
|
virtual DeclTy *ActOnForwardProtocolDeclaration(Scope *S,
|
|
|
|
SourceLocation AtProtocolLoc,
|
|
|
|
IdentifierInfo **IdentList,
|
|
|
|
unsigned NumElts);
|
2007-09-06 21:24:23 +00:00
|
|
|
|
2007-10-03 21:00:46 +00:00
|
|
|
virtual void ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *ClassDecl,
|
|
|
|
DeclTy **allMethods, unsigned allNum);
|
2007-09-26 18:27:25 +00:00
|
|
|
|
2007-10-02 22:39:18 +00:00
|
|
|
virtual DeclTy *ActOnMethodDeclaration(SourceLocation MethodLoc,
|
2007-09-28 22:22:11 +00:00
|
|
|
tok::TokenKind MethodType, TypeTy *ReturnType, Selector Sel,
|
Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference is SelectorInfo is not string-oriented, it is a unique aggregate of IdentifierInfo's (using a folding set). SelectorInfo also has a richer API that simplifies the parser/action interface. 3 noteworthy benefits:
#1: It is cleaner. I never "liked" storing keyword selectors (i.e. foo:bar:baz) in the IdentifierTable.
#2: It is more space efficient. Since Cocoa keyword selectors can be quite long, this technique is space saving. For Cocoa.h, pulling the keyword selectors out saves ~180k. The cost of the SelectorInfo data is ~100k. Saves ~80k, or 43%.
#3: It results in many API simplifications. Here are some highlights:
- Removed 3 actions (ActOnKeywordMessage, ActOnUnaryMessage, & one flavor of ObjcBuildMethodDeclaration that was specific to unary messages).
- Removed 3 funky structs from DeclSpec.h (ObjcKeywordMessage, ObjcKeywordDecl, and ObjcKeywordInfo).
- Removed 2 ivars and 2 constructors from ObjCMessageExpr (fyi, this space savings has not been measured).
I am happy with the way it turned out (though it took a bit more hacking than I expected). Given the central role of selectors in ObjC, making sure this is "right" will pay dividends later.
Thanks to Chris for talking this through with me and suggesting this approach.
llvm-svn: 42395
2007-09-27 14:38:14 +00:00
|
|
|
// optional arguments. The number of types/arguments is obtained
|
|
|
|
// from the Sel.getNumArgs().
|
|
|
|
TypeTy **ArgTypes, IdentifierInfo **ArgNames,
|
|
|
|
AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind);
|
2007-09-17 21:01:15 +00:00
|
|
|
|
Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference is SelectorInfo is not string-oriented, it is a unique aggregate of IdentifierInfo's (using a folding set). SelectorInfo also has a richer API that simplifies the parser/action interface. 3 noteworthy benefits:
#1: It is cleaner. I never "liked" storing keyword selectors (i.e. foo:bar:baz) in the IdentifierTable.
#2: It is more space efficient. Since Cocoa keyword selectors can be quite long, this technique is space saving. For Cocoa.h, pulling the keyword selectors out saves ~180k. The cost of the SelectorInfo data is ~100k. Saves ~80k, or 43%.
#3: It results in many API simplifications. Here are some highlights:
- Removed 3 actions (ActOnKeywordMessage, ActOnUnaryMessage, & one flavor of ObjcBuildMethodDeclaration that was specific to unary messages).
- Removed 3 funky structs from DeclSpec.h (ObjcKeywordMessage, ObjcKeywordDecl, and ObjcKeywordInfo).
- Removed 2 ivars and 2 constructors from ObjCMessageExpr (fyi, this space savings has not been measured).
I am happy with the way it turned out (though it took a bit more hacking than I expected). Given the central role of selectors in ObjC, making sure this is "right" will pay dividends later.
Thanks to Chris for talking this through with me and suggesting this approach.
llvm-svn: 42395
2007-09-27 14:38:14 +00:00
|
|
|
// ActOnClassMessage - used for both unary and keyword messages.
|
|
|
|
// ArgExprs is optional - if it is present, the number of expressions
|
|
|
|
// is obtained from Sel.getNumArgs().
|
|
|
|
virtual ExprResult ActOnClassMessage(
|
2007-09-28 22:22:11 +00:00
|
|
|
IdentifierInfo *receivingClassName, Selector Sel,
|
2007-10-02 20:01:56 +00:00
|
|
|
SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
|
Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference is SelectorInfo is not string-oriented, it is a unique aggregate of IdentifierInfo's (using a folding set). SelectorInfo also has a richer API that simplifies the parser/action interface. 3 noteworthy benefits:
#1: It is cleaner. I never "liked" storing keyword selectors (i.e. foo:bar:baz) in the IdentifierTable.
#2: It is more space efficient. Since Cocoa keyword selectors can be quite long, this technique is space saving. For Cocoa.h, pulling the keyword selectors out saves ~180k. The cost of the SelectorInfo data is ~100k. Saves ~80k, or 43%.
#3: It results in many API simplifications. Here are some highlights:
- Removed 3 actions (ActOnKeywordMessage, ActOnUnaryMessage, & one flavor of ObjcBuildMethodDeclaration that was specific to unary messages).
- Removed 3 funky structs from DeclSpec.h (ObjcKeywordMessage, ObjcKeywordDecl, and ObjcKeywordInfo).
- Removed 2 ivars and 2 constructors from ObjCMessageExpr (fyi, this space savings has not been measured).
I am happy with the way it turned out (though it took a bit more hacking than I expected). Given the central role of selectors in ObjC, making sure this is "right" will pay dividends later.
Thanks to Chris for talking this through with me and suggesting this approach.
llvm-svn: 42395
2007-09-27 14:38:14 +00:00
|
|
|
|
|
|
|
// ActOnInstanceMessage - used for both unary and keyword messages.
|
|
|
|
// ArgExprs is optional - if it is present, the number of expressions
|
|
|
|
// is obtained from Sel.getNumArgs().
|
|
|
|
virtual ExprResult ActOnInstanceMessage(
|
2007-09-28 22:22:11 +00:00
|
|
|
ExprTy *receiver, Selector Sel,
|
Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference is SelectorInfo is not string-oriented, it is a unique aggregate of IdentifierInfo's (using a folding set). SelectorInfo also has a richer API that simplifies the parser/action interface. 3 noteworthy benefits:
#1: It is cleaner. I never "liked" storing keyword selectors (i.e. foo:bar:baz) in the IdentifierTable.
#2: It is more space efficient. Since Cocoa keyword selectors can be quite long, this technique is space saving. For Cocoa.h, pulling the keyword selectors out saves ~180k. The cost of the SelectorInfo data is ~100k. Saves ~80k, or 43%.
#3: It results in many API simplifications. Here are some highlights:
- Removed 3 actions (ActOnKeywordMessage, ActOnUnaryMessage, & one flavor of ObjcBuildMethodDeclaration that was specific to unary messages).
- Removed 3 funky structs from DeclSpec.h (ObjcKeywordMessage, ObjcKeywordDecl, and ObjcKeywordInfo).
- Removed 2 ivars and 2 constructors from ObjCMessageExpr (fyi, this space savings has not been measured).
I am happy with the way it turned out (though it took a bit more hacking than I expected). Given the central role of selectors in ObjC, making sure this is "right" will pay dividends later.
Thanks to Chris for talking this through with me and suggesting this approach.
llvm-svn: 42395
2007-09-27 14:38:14 +00:00
|
|
|
SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
|
2007-03-21 21:08:52 +00:00
|
|
|
private:
|
2007-06-04 22:22:31 +00:00
|
|
|
// UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
|
2007-07-16 21:54:35 +00:00
|
|
|
// functions and arrays to their respective pointers (C99 6.3.2.1).
|
|
|
|
void UsualUnaryConversions(Expr *&expr);
|
|
|
|
|
|
|
|
// DefaultFunctionArrayConversion - converts functions and arrays
|
|
|
|
// to their respective pointers (C99 6.3.2.1).
|
|
|
|
void DefaultFunctionArrayConversion(Expr *&expr);
|
2007-07-13 23:32:42 +00:00
|
|
|
|
2007-08-28 23:30:39 +00:00
|
|
|
// DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
|
|
|
|
// do not have a prototype. Integer promotions are performed on each
|
|
|
|
// argument, and arguments that have type float are promoted to double.
|
|
|
|
void DefaultArgumentPromotion(Expr *&expr);
|
|
|
|
|
2007-06-04 22:22:31 +00:00
|
|
|
// UsualArithmeticConversions - performs the UsualUnaryConversions on it's
|
|
|
|
// operands and then handles various conversions that are common to binary
|
|
|
|
// operators (C99 6.3.1.8). If both operands aren't arithmetic, this
|
|
|
|
// routine returns the first non-arithmetic type found. The client is
|
|
|
|
// responsible for emitting appropriate error diagnostics.
|
2007-08-24 19:07:16 +00:00
|
|
|
QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
|
|
|
|
bool isCompAssign = false);
|
2007-06-06 18:38:38 +00:00
|
|
|
enum AssignmentCheckResult {
|
2007-05-03 21:03:48 +00:00
|
|
|
Compatible,
|
|
|
|
Incompatible,
|
|
|
|
PointerFromInt,
|
|
|
|
IntFromPointer,
|
2007-05-11 04:00:31 +00:00
|
|
|
IncompatiblePointer,
|
|
|
|
CompatiblePointerDiscardsQualifiers
|
2007-05-03 21:03:48 +00:00
|
|
|
};
|
2007-07-13 23:32:42 +00:00
|
|
|
// CheckAssignmentConstraints - Perform type checking for assignment,
|
|
|
|
// argument passing, variable initialization, and function return values.
|
|
|
|
// This routine is only used by the following two methods. C99 6.5.16.
|
2007-06-06 18:38:38 +00:00
|
|
|
AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs);
|
2007-07-13 23:32:42 +00:00
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
// CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
|
2007-09-16 14:56:35 +00:00
|
|
|
// CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
|
2007-07-13 23:32:42 +00:00
|
|
|
// this routine performs the default function/array converions.
|
|
|
|
AssignmentCheckResult CheckSingleAssignmentConstraints(QualType lhs,
|
|
|
|
Expr *&rExpr);
|
|
|
|
// CheckCompoundAssignmentConstraints - Type check without performing any
|
|
|
|
// conversions. For compound assignments, the "Check...Operands" methods
|
|
|
|
// perform the necessary conversions.
|
|
|
|
AssignmentCheckResult CheckCompoundAssignmentConstraints(QualType lhs,
|
|
|
|
QualType rhs);
|
|
|
|
|
2007-06-06 18:38:38 +00:00
|
|
|
// Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
|
|
|
|
AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType,
|
|
|
|
QualType rhsType);
|
2007-05-02 21:58:15 +00:00
|
|
|
|
2007-05-08 21:09:37 +00:00
|
|
|
/// the following "Check" methods will return a valid/converted QualType
|
|
|
|
/// or a null QualType (indicating an error diagnostic was issued).
|
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
/// type checking binary operators (subroutines of ActOnBinOp).
|
2007-07-13 16:58:59 +00:00
|
|
|
inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
|
|
|
|
inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
|
Bug #:
Submitted by:
Reviewed by:
Implemented type checking for compound assignments (*=, /=, etc.).
This encouraged me to do a fairly dramatic refactoring of the Check* functions.
(since I wanted to reuse the existing work, rather than duplicate the logic).
For example, I changed all the Check* functions to return a QualType (instead
of returning an Expr). This had a very nice side benefit...there is now
only one instantiation point for BinaryOperator()! (A property I've always
wanted...separating type checking from AST building is *much* nicer). Another
change is to remove "code" from all the Check* functions (this allowed
me to remove the weird comment about enums/unsigned:-). Removing the
code forced me to add a few functions, however. For example,
< ExprResult CheckAdditiveOperands( // C99 6.5.6
< Expr *lex, Expr *rex, SourceLocation OpLoc, unsigned OpCode);
> inline QualType CheckAdditionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
> inline QualType CheckSubtractionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
While this isn't as terse, it more closely reflects the differences in
the typechecking logic. For example, I disliked having to check the code again
in CheckMultiplicativeOperands/CheckAdditiveOperands.
Created the following helper functions:
- Expr::isNullPointerConstant().
- SemaExpr.cpp: static inline BinaryOperator::Opcode ConvertTokenKindToBinaryOpcode().
This was purely asethetic, since ParseBinOp() is now larger. I didn't feel
like looking at 2 huge switch statements. ParseBinOp() now avoids using
any of the BinaryOperator predicates (since I switched to a switch statement:-)
Only one regret (minor). I couldn't figure out how to avoid having two assign functions,
CheckCompoundAssignmentOperands, CheckSimpleAssignmentOperands. Conceptually,
the two functions make sense. Unfortunately, their implementation contains a lot of
duplication (thought they aren't that be in the first place).
llvm-svn: 39433
2007-05-04 21:54:46 +00:00
|
|
|
inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
|
2007-08-24 19:07:16 +00:00
|
|
|
Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
|
Bug #:
Submitted by:
Reviewed by:
Implemented type checking for compound assignments (*=, /=, etc.).
This encouraged me to do a fairly dramatic refactoring of the Check* functions.
(since I wanted to reuse the existing work, rather than duplicate the logic).
For example, I changed all the Check* functions to return a QualType (instead
of returning an Expr). This had a very nice side benefit...there is now
only one instantiation point for BinaryOperator()! (A property I've always
wanted...separating type checking from AST building is *much* nicer). Another
change is to remove "code" from all the Check* functions (this allowed
me to remove the weird comment about enums/unsigned:-). Removing the
code forced me to add a few functions, however. For example,
< ExprResult CheckAdditiveOperands( // C99 6.5.6
< Expr *lex, Expr *rex, SourceLocation OpLoc, unsigned OpCode);
> inline QualType CheckAdditionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
> inline QualType CheckSubtractionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
While this isn't as terse, it more closely reflects the differences in
the typechecking logic. For example, I disliked having to check the code again
in CheckMultiplicativeOperands/CheckAdditiveOperands.
Created the following helper functions:
- Expr::isNullPointerConstant().
- SemaExpr.cpp: static inline BinaryOperator::Opcode ConvertTokenKindToBinaryOpcode().
This was purely asethetic, since ParseBinOp() is now larger. I didn't feel
like looking at 2 huge switch statements. ParseBinOp() now avoids using
any of the BinaryOperator predicates (since I switched to a switch statement:-)
Only one regret (minor). I couldn't figure out how to avoid having two assign functions,
CheckCompoundAssignmentOperands, CheckSimpleAssignmentOperands. Conceptually,
the two functions make sense. Unfortunately, their implementation contains a lot of
duplication (thought they aren't that be in the first place).
llvm-svn: 39433
2007-05-04 21:54:46 +00:00
|
|
|
inline QualType CheckRemainderOperands( // C99 6.5.5
|
2007-08-24 19:07:16 +00:00
|
|
|
Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
|
Bug #:
Submitted by:
Reviewed by:
Implemented type checking for compound assignments (*=, /=, etc.).
This encouraged me to do a fairly dramatic refactoring of the Check* functions.
(since I wanted to reuse the existing work, rather than duplicate the logic).
For example, I changed all the Check* functions to return a QualType (instead
of returning an Expr). This had a very nice side benefit...there is now
only one instantiation point for BinaryOperator()! (A property I've always
wanted...separating type checking from AST building is *much* nicer). Another
change is to remove "code" from all the Check* functions (this allowed
me to remove the weird comment about enums/unsigned:-). Removing the
code forced me to add a few functions, however. For example,
< ExprResult CheckAdditiveOperands( // C99 6.5.6
< Expr *lex, Expr *rex, SourceLocation OpLoc, unsigned OpCode);
> inline QualType CheckAdditionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
> inline QualType CheckSubtractionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
While this isn't as terse, it more closely reflects the differences in
the typechecking logic. For example, I disliked having to check the code again
in CheckMultiplicativeOperands/CheckAdditiveOperands.
Created the following helper functions:
- Expr::isNullPointerConstant().
- SemaExpr.cpp: static inline BinaryOperator::Opcode ConvertTokenKindToBinaryOpcode().
This was purely asethetic, since ParseBinOp() is now larger. I didn't feel
like looking at 2 huge switch statements. ParseBinOp() now avoids using
any of the BinaryOperator predicates (since I switched to a switch statement:-)
Only one regret (minor). I couldn't figure out how to avoid having two assign functions,
CheckCompoundAssignmentOperands, CheckSimpleAssignmentOperands. Conceptually,
the two functions make sense. Unfortunately, their implementation contains a lot of
duplication (thought they aren't that be in the first place).
llvm-svn: 39433
2007-05-04 21:54:46 +00:00
|
|
|
inline QualType CheckAdditionOperands( // C99 6.5.6
|
2007-08-24 19:07:16 +00:00
|
|
|
Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
|
Bug #:
Submitted by:
Reviewed by:
Implemented type checking for compound assignments (*=, /=, etc.).
This encouraged me to do a fairly dramatic refactoring of the Check* functions.
(since I wanted to reuse the existing work, rather than duplicate the logic).
For example, I changed all the Check* functions to return a QualType (instead
of returning an Expr). This had a very nice side benefit...there is now
only one instantiation point for BinaryOperator()! (A property I've always
wanted...separating type checking from AST building is *much* nicer). Another
change is to remove "code" from all the Check* functions (this allowed
me to remove the weird comment about enums/unsigned:-). Removing the
code forced me to add a few functions, however. For example,
< ExprResult CheckAdditiveOperands( // C99 6.5.6
< Expr *lex, Expr *rex, SourceLocation OpLoc, unsigned OpCode);
> inline QualType CheckAdditionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
> inline QualType CheckSubtractionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
While this isn't as terse, it more closely reflects the differences in
the typechecking logic. For example, I disliked having to check the code again
in CheckMultiplicativeOperands/CheckAdditiveOperands.
Created the following helper functions:
- Expr::isNullPointerConstant().
- SemaExpr.cpp: static inline BinaryOperator::Opcode ConvertTokenKindToBinaryOpcode().
This was purely asethetic, since ParseBinOp() is now larger. I didn't feel
like looking at 2 huge switch statements. ParseBinOp() now avoids using
any of the BinaryOperator predicates (since I switched to a switch statement:-)
Only one regret (minor). I couldn't figure out how to avoid having two assign functions,
CheckCompoundAssignmentOperands, CheckSimpleAssignmentOperands. Conceptually,
the two functions make sense. Unfortunately, their implementation contains a lot of
duplication (thought they aren't that be in the first place).
llvm-svn: 39433
2007-05-04 21:54:46 +00:00
|
|
|
inline QualType CheckSubtractionOperands( // C99 6.5.6
|
2007-08-24 19:07:16 +00:00
|
|
|
Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
|
Bug #:
Submitted by:
Reviewed by:
Implemented type checking for compound assignments (*=, /=, etc.).
This encouraged me to do a fairly dramatic refactoring of the Check* functions.
(since I wanted to reuse the existing work, rather than duplicate the logic).
For example, I changed all the Check* functions to return a QualType (instead
of returning an Expr). This had a very nice side benefit...there is now
only one instantiation point for BinaryOperator()! (A property I've always
wanted...separating type checking from AST building is *much* nicer). Another
change is to remove "code" from all the Check* functions (this allowed
me to remove the weird comment about enums/unsigned:-). Removing the
code forced me to add a few functions, however. For example,
< ExprResult CheckAdditiveOperands( // C99 6.5.6
< Expr *lex, Expr *rex, SourceLocation OpLoc, unsigned OpCode);
> inline QualType CheckAdditionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
> inline QualType CheckSubtractionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
While this isn't as terse, it more closely reflects the differences in
the typechecking logic. For example, I disliked having to check the code again
in CheckMultiplicativeOperands/CheckAdditiveOperands.
Created the following helper functions:
- Expr::isNullPointerConstant().
- SemaExpr.cpp: static inline BinaryOperator::Opcode ConvertTokenKindToBinaryOpcode().
This was purely asethetic, since ParseBinOp() is now larger. I didn't feel
like looking at 2 huge switch statements. ParseBinOp() now avoids using
any of the BinaryOperator predicates (since I switched to a switch statement:-)
Only one regret (minor). I couldn't figure out how to avoid having two assign functions,
CheckCompoundAssignmentOperands, CheckSimpleAssignmentOperands. Conceptually,
the two functions make sense. Unfortunately, their implementation contains a lot of
duplication (thought they aren't that be in the first place).
llvm-svn: 39433
2007-05-04 21:54:46 +00:00
|
|
|
inline QualType CheckShiftOperands( // C99 6.5.7
|
2007-08-24 19:07:16 +00:00
|
|
|
Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
|
2007-08-26 01:18:55 +00:00
|
|
|
inline QualType CheckCompareOperands( // C99 6.5.8/9
|
|
|
|
Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
|
Bug #:
Submitted by:
Reviewed by:
Implemented type checking for compound assignments (*=, /=, etc.).
This encouraged me to do a fairly dramatic refactoring of the Check* functions.
(since I wanted to reuse the existing work, rather than duplicate the logic).
For example, I changed all the Check* functions to return a QualType (instead
of returning an Expr). This had a very nice side benefit...there is now
only one instantiation point for BinaryOperator()! (A property I've always
wanted...separating type checking from AST building is *much* nicer). Another
change is to remove "code" from all the Check* functions (this allowed
me to remove the weird comment about enums/unsigned:-). Removing the
code forced me to add a few functions, however. For example,
< ExprResult CheckAdditiveOperands( // C99 6.5.6
< Expr *lex, Expr *rex, SourceLocation OpLoc, unsigned OpCode);
> inline QualType CheckAdditionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
> inline QualType CheckSubtractionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
While this isn't as terse, it more closely reflects the differences in
the typechecking logic. For example, I disliked having to check the code again
in CheckMultiplicativeOperands/CheckAdditiveOperands.
Created the following helper functions:
- Expr::isNullPointerConstant().
- SemaExpr.cpp: static inline BinaryOperator::Opcode ConvertTokenKindToBinaryOpcode().
This was purely asethetic, since ParseBinOp() is now larger. I didn't feel
like looking at 2 huge switch statements. ParseBinOp() now avoids using
any of the BinaryOperator predicates (since I switched to a switch statement:-)
Only one regret (minor). I couldn't figure out how to avoid having two assign functions,
CheckCompoundAssignmentOperands, CheckSimpleAssignmentOperands. Conceptually,
the two functions make sense. Unfortunately, their implementation contains a lot of
duplication (thought they aren't that be in the first place).
llvm-svn: 39433
2007-05-04 21:54:46 +00:00
|
|
|
inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
|
2007-08-24 19:07:16 +00:00
|
|
|
Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
|
Bug #:
Submitted by:
Reviewed by:
Implemented type checking for compound assignments (*=, /=, etc.).
This encouraged me to do a fairly dramatic refactoring of the Check* functions.
(since I wanted to reuse the existing work, rather than duplicate the logic).
For example, I changed all the Check* functions to return a QualType (instead
of returning an Expr). This had a very nice side benefit...there is now
only one instantiation point for BinaryOperator()! (A property I've always
wanted...separating type checking from AST building is *much* nicer). Another
change is to remove "code" from all the Check* functions (this allowed
me to remove the weird comment about enums/unsigned:-). Removing the
code forced me to add a few functions, however. For example,
< ExprResult CheckAdditiveOperands( // C99 6.5.6
< Expr *lex, Expr *rex, SourceLocation OpLoc, unsigned OpCode);
> inline QualType CheckAdditionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
> inline QualType CheckSubtractionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
While this isn't as terse, it more closely reflects the differences in
the typechecking logic. For example, I disliked having to check the code again
in CheckMultiplicativeOperands/CheckAdditiveOperands.
Created the following helper functions:
- Expr::isNullPointerConstant().
- SemaExpr.cpp: static inline BinaryOperator::Opcode ConvertTokenKindToBinaryOpcode().
This was purely asethetic, since ParseBinOp() is now larger. I didn't feel
like looking at 2 huge switch statements. ParseBinOp() now avoids using
any of the BinaryOperator predicates (since I switched to a switch statement:-)
Only one regret (minor). I couldn't figure out how to avoid having two assign functions,
CheckCompoundAssignmentOperands, CheckSimpleAssignmentOperands. Conceptually,
the two functions make sense. Unfortunately, their implementation contains a lot of
duplication (thought they aren't that be in the first place).
llvm-svn: 39433
2007-05-04 21:54:46 +00:00
|
|
|
inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
|
2007-07-13 16:58:59 +00:00
|
|
|
Expr *&lex, Expr *&rex, SourceLocation OpLoc);
|
2007-05-07 00:24:15 +00:00
|
|
|
// CheckAssignmentOperands is used for both simple and compound assignment.
|
|
|
|
// For simple assignment, pass both expressions and a null converted type.
|
|
|
|
// For compound assignment, pass both expressions and the converted type.
|
|
|
|
inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
|
2007-08-24 22:33:52 +00:00
|
|
|
Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
|
Bug #:
Submitted by:
Reviewed by:
Implemented type checking for compound assignments (*=, /=, etc.).
This encouraged me to do a fairly dramatic refactoring of the Check* functions.
(since I wanted to reuse the existing work, rather than duplicate the logic).
For example, I changed all the Check* functions to return a QualType (instead
of returning an Expr). This had a very nice side benefit...there is now
only one instantiation point for BinaryOperator()! (A property I've always
wanted...separating type checking from AST building is *much* nicer). Another
change is to remove "code" from all the Check* functions (this allowed
me to remove the weird comment about enums/unsigned:-). Removing the
code forced me to add a few functions, however. For example,
< ExprResult CheckAdditiveOperands( // C99 6.5.6
< Expr *lex, Expr *rex, SourceLocation OpLoc, unsigned OpCode);
> inline QualType CheckAdditionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
> inline QualType CheckSubtractionOperands( // C99 6.5.6
> Expr *lex, Expr *rex, SourceLocation OpLoc);
While this isn't as terse, it more closely reflects the differences in
the typechecking logic. For example, I disliked having to check the code again
in CheckMultiplicativeOperands/CheckAdditiveOperands.
Created the following helper functions:
- Expr::isNullPointerConstant().
- SemaExpr.cpp: static inline BinaryOperator::Opcode ConvertTokenKindToBinaryOpcode().
This was purely asethetic, since ParseBinOp() is now larger. I didn't feel
like looking at 2 huge switch statements. ParseBinOp() now avoids using
any of the BinaryOperator predicates (since I switched to a switch statement:-)
Only one regret (minor). I couldn't figure out how to avoid having two assign functions,
CheckCompoundAssignmentOperands, CheckSimpleAssignmentOperands. Conceptually,
the two functions make sense. Unfortunately, their implementation contains a lot of
duplication (thought they aren't that be in the first place).
llvm-svn: 39433
2007-05-04 21:54:46 +00:00
|
|
|
inline QualType CheckCommaOperands( // C99 6.5.17
|
2007-07-13 16:58:59 +00:00
|
|
|
Expr *&lex, Expr *&rex, SourceLocation OpLoc);
|
2007-05-15 20:29:32 +00:00
|
|
|
inline QualType CheckConditionalOperands( // C99 6.5.15
|
2007-07-13 16:58:59 +00:00
|
|
|
Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
|
2007-03-30 23:47:58 +00:00
|
|
|
|
2007-09-16 03:34:24 +00:00
|
|
|
/// type checking unary operators (subroutines of ActOnUnaryOp).
|
2007-05-27 23:58:33 +00:00
|
|
|
/// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
|
2007-05-18 22:53:50 +00:00
|
|
|
QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
|
|
|
|
QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
|
|
|
|
QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
|
|
|
|
QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
|
|
|
|
bool isSizeof);
|
2007-08-24 21:41:10 +00:00
|
|
|
QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
|
2007-07-27 22:15:19 +00:00
|
|
|
|
|
|
|
/// type checking primary expressions.
|
|
|
|
QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
|
|
|
|
IdentifierInfo &Comp, SourceLocation CmpLoc);
|
|
|
|
|
2007-09-02 02:04:30 +00:00
|
|
|
/// type checking declaration initializers (C99 6.7.8)
|
2007-09-04 14:36:54 +00:00
|
|
|
bool CheckInitializer(Expr *&simpleInit_or_initList, QualType &declType,
|
2007-09-03 01:24:23 +00:00
|
|
|
bool isStatic);
|
2007-09-04 14:36:54 +00:00
|
|
|
bool CheckSingleInitializer(Expr *&simpleInit, QualType declType);
|
|
|
|
bool CheckInitExpr(Expr *expr, InitListExpr *IList, unsigned slot,
|
|
|
|
bool isStatic, QualType ElementType);
|
2007-09-04 02:20:04 +00:00
|
|
|
void CheckVariableInitList(QualType DeclType, InitListExpr *IList,
|
|
|
|
QualType ElementType, bool isStatic,
|
|
|
|
int &nInitializers, bool &hadError);
|
|
|
|
void CheckConstantInitList(QualType DeclType, InitListExpr *IList,
|
|
|
|
QualType ElementType, bool isStatic,
|
|
|
|
int &nInitializers, bool &hadError);
|
|
|
|
|
2007-08-23 05:46:52 +00:00
|
|
|
/// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
|
|
|
|
/// the specified width and sign. If an overflow occurs, detect it and emit
|
|
|
|
/// the specified diagnostic.
|
|
|
|
void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
|
|
|
|
unsigned NewWidth, bool NewSign,
|
|
|
|
SourceLocation Loc, unsigned DiagID);
|
|
|
|
|
2007-08-10 20:18:51 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Extra semantic analysis beyond the C type system
|
|
|
|
private:
|
|
|
|
|
2007-08-17 05:31:46 +00:00
|
|
|
bool CheckFunctionCall(Expr *Fn,
|
2007-08-14 17:39:48 +00:00
|
|
|
SourceLocation LParenLoc, SourceLocation RParenLoc,
|
|
|
|
FunctionDecl *FDecl,
|
2007-08-10 20:18:51 +00:00
|
|
|
Expr** Args, unsigned NumArgsInCall);
|
|
|
|
|
2007-08-14 17:39:48 +00:00
|
|
|
void CheckPrintfArguments(Expr *Fn,
|
|
|
|
SourceLocation LParenLoc, SourceLocation RParenLoc,
|
|
|
|
bool HasVAListArg, FunctionDecl *FDecl,
|
2007-08-10 21:21:05 +00:00
|
|
|
unsigned format_idx, Expr** Args,
|
|
|
|
unsigned NumArgsInCall);
|
2007-08-17 16:46:58 +00:00
|
|
|
|
|
|
|
void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
|
|
|
|
SourceLocation ReturnLoc);
|
|
|
|
|
2007-08-17 05:31:46 +00:00
|
|
|
|
|
|
|
bool CheckBuiltinCFStringArgument(Expr* Arg);
|
2006-11-03 06:42:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|