clang API Documentation
00001 //===--- SemaFixItUtils.h - Sema FixIts -----------------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines helper classes for generation of Sema FixItHints. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 #ifndef LLVM_CLANG_SEMA_SEMAFIXITUTILS_H 00014 #define LLVM_CLANG_SEMA_SEMAFIXITUTILS_H 00015 00016 #include "clang/AST/Expr.h" 00017 00018 namespace clang { 00019 00020 enum OverloadFixItKind { 00021 OFIK_Undefined = 0, 00022 OFIK_Dereference, 00023 OFIK_TakeAddress, 00024 OFIK_RemoveDereference, 00025 OFIK_RemoveTakeAddress 00026 }; 00027 00028 class Sema; 00029 00030 /// The class facilities generation and storage of conversion FixIts. Hints for 00031 /// new conversions are added using TryToFixConversion method. The default type 00032 /// conversion checker can be reset. 00033 struct ConversionFixItGenerator { 00034 /// Performs a simple check to see if From type can be converted to To type. 00035 static bool compareTypesSimple(CanQualType From, 00036 CanQualType To, 00037 Sema &S, 00038 SourceLocation Loc, 00039 ExprValueKind FromVK); 00040 00041 /// The list of Hints generated so far. 00042 std::vector<FixItHint> Hints; 00043 00044 /// The number of Conversions fixed. This can be different from the size 00045 /// of the Hints vector since we allow multiple FixIts per conversion. 00046 unsigned NumConversionsFixed; 00047 00048 /// The type of fix applied. If multiple conversions are fixed, corresponds 00049 /// to the kid of the very first conversion. 00050 OverloadFixItKind Kind; 00051 00052 typedef bool (*TypeComparisonFuncTy) (const CanQualType FromTy, 00053 const CanQualType ToTy, 00054 Sema &S, 00055 SourceLocation Loc, 00056 ExprValueKind FromVK); 00057 /// The type comparison function used to decide if expression FromExpr of 00058 /// type FromTy can be converted to ToTy. For example, one could check if 00059 /// an implicit conversion exists. Returns true if comparison exists. 00060 TypeComparisonFuncTy CompareTypes; 00061 00062 ConversionFixItGenerator(TypeComparisonFuncTy Foo): NumConversionsFixed(0), 00063 Kind(OFIK_Undefined), 00064 CompareTypes(Foo) {} 00065 00066 ConversionFixItGenerator(): NumConversionsFixed(0), 00067 Kind(OFIK_Undefined), 00068 CompareTypes(compareTypesSimple) {} 00069 00070 /// Resets the default conversion checker method. 00071 void setConversionChecker(TypeComparisonFuncTy Foo) { 00072 CompareTypes = Foo; 00073 } 00074 00075 /// If possible, generates and stores a fix for the given conversion. 00076 bool tryToFixConversion(const Expr *FromExpr, 00077 const QualType FromQTy, const QualType ToQTy, 00078 Sema &S); 00079 00080 void clear() { 00081 Hints.clear(); 00082 NumConversionsFixed = 0; 00083 } 00084 00085 bool isNull() { 00086 return (NumConversionsFixed == 0); 00087 } 00088 }; 00089 00090 } // endof namespace clang 00091 #endif