clang 20.0.0git
Public Member Functions | List of all members
clang::PreferredTypeBuilder Class Reference

Tracks expected type during expression parsing, for use in code completion. More...

#include "clang/Sema/Sema.h"

Public Member Functions

 PreferredTypeBuilder (bool Enabled)
 
void enterCondition (Sema &S, SourceLocation Tok)
 
void enterReturn (Sema &S, SourceLocation Tok)
 
void enterVariableInit (SourceLocation Tok, Decl *D)
 
void enterDesignatedInitializer (SourceLocation Tok, QualType BaseType, const Designation &D)
 Handles e.g. BaseType{ .D = Tok...
 
void enterFunctionArgument (SourceLocation Tok, llvm::function_ref< QualType()> ComputeType)
 Computing a type for the function argument may require running overloading, so we postpone its computation until it is actually needed.
 
void enterParenExpr (SourceLocation Tok, SourceLocation LParLoc)
 
void enterUnary (Sema &S, SourceLocation Tok, tok::TokenKind OpKind, SourceLocation OpLoc)
 
void enterBinary (Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op)
 
void enterMemAccess (Sema &S, SourceLocation Tok, Expr *Base)
 
void enterSubscript (Sema &S, SourceLocation Tok, Expr *LHS)
 
void enterTypeCast (SourceLocation Tok, QualType CastType)
 Handles all type casts, including C-style cast, C++ casts, etc.
 
QualType get (SourceLocation Tok) const
 Get the expected type associated with this location, if any.
 

Detailed Description

Tracks expected type during expression parsing, for use in code completion.

The type is tied to a particular token, all functions that update or consume the type take a start location of the token they are looking at as a parameter. This avoids updating the type on hot paths in the parser.

Definition at line 289 of file Sema.h.

Constructor & Destructor Documentation

◆ PreferredTypeBuilder()

clang::PreferredTypeBuilder::PreferredTypeBuilder ( bool  Enabled)
inline

Definition at line 291 of file Sema.h.

Member Function Documentation

◆ enterBinary()

void PreferredTypeBuilder::enterBinary ( Sema S,
SourceLocation  Tok,
Expr LHS,
tok::TokenKind  Op 
)

Definition at line 578 of file SemaCodeComplete.cpp.

References getPreferredTypeOfBinaryRHS().

◆ enterCondition()

void PreferredTypeBuilder::enterCondition ( Sema S,
SourceLocation  Tok 
)

◆ enterDesignatedInitializer()

void PreferredTypeBuilder::enterDesignatedInitializer ( SourceLocation  Tok,
QualType  BaseType,
const Designation D 
)

Handles e.g. BaseType{ .D = Tok...

Definition at line 441 of file SemaCodeComplete.cpp.

References D, and getDesignatedType().

◆ enterFunctionArgument()

void PreferredTypeBuilder::enterFunctionArgument ( SourceLocation  Tok,
llvm::function_ref< QualType()>  ComputeType 
)

Computing a type for the function argument may require running overloading, so we postpone its computation until it is actually needed.

Clients should be very careful when using this function, as it stores a function_ref, clients should make sure all calls to get() with the same location happen while function_ref is alive.

The callback should also emit signature help as a side-effect, but only if the completion point has been reached.

Definition at line 451 of file SemaCodeComplete.cpp.

◆ enterMemAccess()

void PreferredTypeBuilder::enterMemAccess ( Sema S,
SourceLocation  Tok,
Expr Base 
)

Definition at line 587 of file SemaCodeComplete.cpp.

◆ enterParenExpr()

void PreferredTypeBuilder::enterParenExpr ( SourceLocation  Tok,
SourceLocation  LParLoc 
)

Definition at line 460 of file SemaCodeComplete.cpp.

◆ enterReturn()

void PreferredTypeBuilder::enterReturn ( Sema S,
SourceLocation  Tok 
)

◆ enterSubscript()

void PreferredTypeBuilder::enterSubscript ( Sema S,
SourceLocation  Tok,
Expr LHS 
)

Definition at line 608 of file SemaCodeComplete.cpp.

References clang::Sema::getASTContext(), and clang::ASTContext::IntTy.

◆ enterTypeCast()

void PreferredTypeBuilder::enterTypeCast ( SourceLocation  Tok,
QualType  CastType 
)

Handles all type casts, including C-style cast, C++ casts, etc.

Definition at line 617 of file SemaCodeComplete.cpp.

◆ enterUnary()

void PreferredTypeBuilder::enterUnary ( Sema S,
SourceLocation  Tok,
tok::TokenKind  OpKind,
SourceLocation  OpLoc 
)

Definition at line 598 of file SemaCodeComplete.cpp.

References get(), and getPreferredTypeOfUnaryArg().

◆ enterVariableInit()

void PreferredTypeBuilder::enterVariableInit ( SourceLocation  Tok,
Decl D 
)

Definition at line 430 of file SemaCodeComplete.cpp.

References D.

◆ get()

QualType clang::PreferredTypeBuilder::get ( SourceLocation  Tok) const
inline

Get the expected type associated with this location, if any.

If the location is a function argument, determining the expected type involves considering all function overloads and the arguments so far. In this case, signature help for these function overloads will be reported as a side-effect (only if the completion point has been reached).

Definition at line 326 of file Sema.h.

Referenced by enterUnary(), clang::Parser::ParseAssignmentExpression(), and clang::Parser::ParseConditionalExpression().


The documentation for this class was generated from the following files: