From 5c53298c1eca22b512c43b2cf02e5e9f05c136a1 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Mon, 7 Jul 2014 22:42:03 +0000 Subject: [PATCH] libclang: pass return code out argument by reference r212427 formalized the message-passing pattern by making these argument structures const. This commit changes output arguments to get passed by reference so we can eliminate mutable fields. llvm-svn: 212497 --- clang/tools/libclang/CIndex.cpp | 21 ++++++++++----------- clang/tools/libclang/Indexing.cpp | 14 ++++++-------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index bb9ba0b..93c3657 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -2736,7 +2736,7 @@ struct ParseTranslationUnitInfo { ArrayRef unsaved_files; unsigned options; CXTranslationUnit *out_TU; - mutable CXErrorCode result; + CXErrorCode &result; }; static void clang_parseTranslationUnit_Impl(void *UserData) { const ParseTranslationUnitInfo *PTUI = @@ -2751,7 +2751,6 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { // Set up the initial return values. if (out_TU) *out_TU = nullptr; - PTUI->result = CXError_Failure; // Check arguments. if (!CIdx || !out_TU) { @@ -2898,6 +2897,7 @@ enum CXErrorCode clang_parseTranslationUnit2( if (num_unsaved_files && !unsaved_files) return CXError_InvalidArguments; + CXErrorCode result = CXError_Failure; ParseTranslationUnitInfo PTUI = { CIdx, source_filename, @@ -2906,7 +2906,7 @@ enum CXErrorCode clang_parseTranslationUnit2( llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, out_TU, - CXError_Failure}; + result}; llvm::CrashRecoveryContext CRC; if (!RunSafely(CRC, clang_parseTranslationUnit_Impl, &PTUI)) { @@ -2935,8 +2935,8 @@ enum CXErrorCode clang_parseTranslationUnit2( if (CXTranslationUnit *TU = PTUI.out_TU) PrintLibclangResourceUsage(*TU); } - - return PTUI.result; + + return result; } unsigned clang_defaultSaveOptions(CXTranslationUnit TU) { @@ -3039,14 +3039,12 @@ struct ReparseTranslationUnitInfo { CXTranslationUnit TU; ArrayRef unsaved_files; unsigned options; - mutable int result; + CXErrorCode &result; }; static void clang_reparseTranslationUnit_Impl(void *UserData) { const ReparseTranslationUnitInfo *RTUI = static_cast(UserData); - RTUI->result = CXError_Failure; - CXTranslationUnit TU = RTUI->TU; unsigned options = RTUI->options; (void) options; @@ -3099,13 +3097,14 @@ int clang_reparseTranslationUnit(CXTranslationUnit TU, if (num_unsaved_files && !unsaved_files) return CXError_InvalidArguments; + CXErrorCode result = CXError_Failure; ReparseTranslationUnitInfo RTUI = { TU, llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, - CXError_Failure}; + result}; if (getenv("LIBCLANG_NOTHREADS")) { clang_reparseTranslationUnit_Impl(&RTUI); - return RTUI.result; + return result; } llvm::CrashRecoveryContext CRC; @@ -3117,7 +3116,7 @@ int clang_reparseTranslationUnit(CXTranslationUnit TU, } else if (getenv("LIBCLANG_RESOURCE_USAGE")) PrintLibclangResourceUsage(TU); - return RTUI.result; + return result; } diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index 05a18b7..58af618 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -475,7 +475,7 @@ struct IndexSourceFileInfo { ArrayRef unsaved_files; CXTranslationUnit *out_TU; unsigned TU_options; - mutable int result; + CXErrorCode &result; }; } // anonymous namespace @@ -494,9 +494,6 @@ static void clang_indexSourceFile_Impl(void *UserData) { CXTranslationUnit *out_TU = ITUI->out_TU; unsigned TU_options = ITUI->TU_options; - // Set up the initial return value. - ITUI->result = CXError_Failure; - if (out_TU) *out_TU = nullptr; bool requestedToGetTU = (out_TU != nullptr); @@ -982,6 +979,7 @@ int clang_indexSourceFile(CXIndexAction idxAction, if (num_unsaved_files && !unsaved_files) return CXError_InvalidArguments; + CXErrorCode result = CXError_Failure; IndexSourceFileInfo ITUI = { idxAction, client_data, @@ -994,11 +992,11 @@ int clang_indexSourceFile(CXIndexAction idxAction, llvm::makeArrayRef(unsaved_files, num_unsaved_files), out_TU, TU_options, - CXError_Failure}; + result}; if (getenv("LIBCLANG_NOTHREADS")) { clang_indexSourceFile_Impl(&ITUI); - return ITUI.result; + return result; } llvm::CrashRecoveryContext CRC; @@ -1029,8 +1027,8 @@ int clang_indexSourceFile(CXIndexAction idxAction, if (out_TU) PrintLibclangResourceUsage(*out_TU); } - - return ITUI.result; + + return result; } int clang_indexTranslationUnit(CXIndexAction idxAction, -- 2.7.4