@@ -2989,8 +2989,10 @@ reformat(const FormatStyle &Style, StringRef Code,
2989
2989
if (Style.isJson ()) {
2990
2990
std::vector<tooling::Range> Ranges (1 , tooling::Range (0 , Code.size ()));
2991
2991
auto Env =
2992
- std::make_unique<Environment> (Code, FileName, Ranges, FirstStartColumn,
2992
+ Environment::make (Code, FileName, Ranges, FirstStartColumn,
2993
2993
NextStartColumn, LastStartColumn);
2994
+ if (!Env)
2995
+ return {};
2994
2996
// Perform the actual formatting pass.
2995
2997
tooling::Replacements Replaces =
2996
2998
Formatter (*Env, Style, Status).process ().first ;
@@ -3046,9 +3048,10 @@ reformat(const FormatStyle &Style, StringRef Code,
3046
3048
return TrailingCommaInserter (Env, Expanded).process ();
3047
3049
});
3048
3050
3049
- auto Env =
3050
- std::make_unique<Environment>(Code, FileName, Ranges, FirstStartColumn,
3051
- NextStartColumn, LastStartColumn);
3051
+ auto Env = Environment::make (Code, FileName, Ranges, FirstStartColumn,
3052
+ NextStartColumn, LastStartColumn);
3053
+ if (!Env)
3054
+ return {};
3052
3055
llvm::Optional<std::string> CurrentCode = None;
3053
3056
tooling::Replacements Fixes;
3054
3057
unsigned Penalty = 0 ;
@@ -3061,10 +3064,12 @@ reformat(const FormatStyle &Style, StringRef Code,
3061
3064
Penalty += PassFixes.second ;
3062
3065
if (I + 1 < E) {
3063
3066
CurrentCode = std::move (*NewCode);
3064
- Env = std::make_unique<Environment> (
3067
+ Env = Environment::make (
3065
3068
*CurrentCode, FileName,
3066
3069
tooling::calculateRangesAfterReplacements (Fixes, Ranges),
3067
3070
FirstStartColumn, NextStartColumn, LastStartColumn);
3071
+ if (!Env)
3072
+ return {};
3068
3073
}
3069
3074
}
3070
3075
}
@@ -3090,7 +3095,10 @@ tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
3090
3095
// cleanups only apply to C++ (they mostly concern ctor commas etc.)
3091
3096
if (Style.Language != FormatStyle::LK_Cpp)
3092
3097
return tooling::Replacements ();
3093
- return Cleaner (Environment (Code, FileName, Ranges), Style).process ().first ;
3098
+ auto Env = Environment::make (Code, FileName, Ranges);
3099
+ if (!Env)
3100
+ return {};
3101
+ return Cleaner (*Env, Style).process ().first ;
3094
3102
}
3095
3103
3096
3104
tooling::Replacements reformat (const FormatStyle &Style, StringRef Code,
@@ -3107,7 +3115,10 @@ tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style,
3107
3115
StringRef Code,
3108
3116
ArrayRef<tooling::Range> Ranges,
3109
3117
StringRef FileName) {
3110
- return NamespaceEndCommentsFixer (Environment (Code, FileName, Ranges), Style)
3118
+ auto Env = Environment::make (Code, FileName, Ranges);
3119
+ if (!Env)
3120
+ return {};
3121
+ return NamespaceEndCommentsFixer (*Env, Style)
3111
3122
.process ()
3112
3123
.first ;
3113
3124
}
@@ -3116,7 +3127,10 @@ tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
3116
3127
StringRef Code,
3117
3128
ArrayRef<tooling::Range> Ranges,
3118
3129
StringRef FileName) {
3119
- return UsingDeclarationsSorter (Environment (Code, FileName, Ranges), Style)
3130
+ auto Env = Environment::make (Code, FileName, Ranges);
3131
+ if (!Env)
3132
+ return {};
3133
+ return UsingDeclarationsSorter (*Env, Style)
3120
3134
.process ()
3121
3135
.first ;
3122
3136
}
0 commit comments