Skip to content
Snippets Groups Projects
Select Git revision
  • b8f10df3679b36f51e1de7c4351b82d297825089
  • inf4_40 default protected
2 results

SemaChecking.cpp

Blame
  • SemaChecking.cpp 413.27 KiB
    //===--- SemaChecking.cpp - Extra Semantic Checking -----------------------===//
    //
    //                     The LLVM Compiler Infrastructure
    //
    // This file is distributed under the University of Illinois Open Source
    // License. See LICENSE.TXT for details.
    //
    //===----------------------------------------------------------------------===//
    //
    //  This file implements extra semantic analysis beyond what is enforced
    //  by the C type system.
    //
    //===----------------------------------------------------------------------===//
    
    #include "clang/AST/ASTContext.h"
    #include "clang/AST/CharUnits.h"
    #include "clang/AST/DeclCXX.h"
    #include "clang/AST/DeclObjC.h"
    #include "clang/AST/EvaluatedExprVisitor.h"
    #include "clang/AST/Expr.h"
    #include "clang/AST/ExprCXX.h"
    #include "clang/AST/ExprObjC.h"
    #include "clang/AST/ExprOpenMP.h"
    #include "clang/AST/StmtCXX.h"
    #include "clang/AST/StmtObjC.h"
    #include "clang/Analysis/Analyses/FormatString.h"
    #include "clang/Basic/CharInfo.h"
    #include "clang/Basic/TargetBuiltins.h"
    #include "clang/Basic/TargetInfo.h"
    #include "clang/Lex/Lexer.h" // TODO: Extract static functions to fix layering.
    #include "clang/Sema/Initialization.h"
    #include "clang/Sema/Lookup.h"
    #include "clang/Sema/ScopeInfo.h"
    #include "clang/Sema/Sema.h"
    #include "clang/Sema/SemaInternal.h"
    #include "llvm/ADT/STLExtras.h"
    #include "llvm/ADT/SmallBitVector.h"
    #include "llvm/ADT/SmallString.h"
    #include "llvm/Support/ConvertUTF.h"
    #include "llvm/Support/Format.h"
    #include "llvm/Support/Locale.h"
    #include "llvm/Support/raw_ostream.h"
    
    using namespace clang;
    using namespace sema;
    
    SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
                                                        unsigned ByteNo) const {
      return SL->getLocationOfByte(ByteNo, getSourceManager(), LangOpts,
                                   Context.getTargetInfo());
    }
    
    /// Checks that a call expression's argument count is the desired number.
    /// This is useful when doing custom type-checking.  Returns true on error.
    static bool checkArgCount(Sema &S, CallExpr *call, unsigned desiredArgCount) {
      unsigned argCount = call->getNumArgs();
      if (argCount == desiredArgCount) return false;
    
      if (argCount < desiredArgCount)
        return S.Diag(call->getLocEnd(), diag::err_typecheck_call_too_few_args)
            << 0 /*function call*/ << desiredArgCount << argCount
            << call->getSourceRange();
    
      // Highlight all the excess arguments.
      SourceRange range(call->getArg(desiredArgCount)->getLocStart(),
                        call->getArg(argCount - 1)->getLocEnd());
        
      return S.Diag(range.getBegin(), diag::err_typecheck_call_too_many_args)
        << 0 /*function call*/ << desiredArgCount << argCount
        << call->getArg(1)->getSourceRange();