Skip to content

Commit d70e388

Browse files
committed
Cpp analyser working perfect
1 parent d0b3f89 commit d70e388

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

app/src/main/java/com/duy/ccppcompiler/compiler/analyze/CppCheckAnalyzer.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
import android.text.Editable;
2727
import android.text.TextWatcher;
2828

29+
import com.duy.ccppcompiler.R;
2930
import com.duy.ccppcompiler.compiler.shell.CommandBuilder;
3031
import com.duy.ccppcompiler.compiler.shell.CommandResult;
3132
import com.duy.ccppcompiler.compiler.shell.Shell;
3233
import com.duy.common.DLog;
3334
import com.duy.ide.diagnostic.Diagnostic;
3435
import com.duy.ide.diagnostic.DiagnosticPresenter;
3536
import com.duy.ide.diagnostic.DiagnosticsCollector;
37+
import com.jecelyin.editor.v2.Preferences;
3638
import com.jecelyin.editor.v2.editor.IEditorDelegate;
3739
import com.jecelyin.editor.v2.io.LocalFileWriter;
3840

@@ -157,7 +159,25 @@ protected ArrayList<Diagnostic> doInBackground(Void... voids) {
157159
CommandBuilder builder = new CommandBuilder(CPPCHECK_PROGRAM);
158160
builder.addFlags(CppCheckOutputParser.TEMPLATE);
159161
builder.addFlags(tmpFile.getAbsolutePath());
160-
builder.addFlags("--enable=warning,performance,information");
162+
163+
String enableFlags = "";
164+
//flags
165+
Preferences setting = Preferences.getInstance(mContext);
166+
boolean warn = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_warning), true);
167+
if (warn) enableFlags += "warning";
168+
boolean performance = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_performance), true);
169+
if (performance) {
170+
if (!enableFlags.isEmpty()) enableFlags += ",";
171+
enableFlags += "performance";
172+
}
173+
boolean information = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_information), true);
174+
if (information) {
175+
if (!enableFlags.isEmpty()) enableFlags += ",";
176+
enableFlags += "information";
177+
}
178+
if (!enableFlags.isEmpty()) {
179+
builder.addFlags("--enable=" + enableFlags);
180+
}
161181

162182
String cmd = builder.build();
163183
CommandResult result = Shell.exec(mContext, tmpFile.getParent(), cmd);

app/src/main/res/values/do_not_translate.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@
99
<string name="pref_c_options_traditional_cpp">pref_c_options_traditional_cpp</string>
1010
<string name="pref_option_optimization_level">pref_option_optimization_level</string>
1111
<string name="pref_option_language_standard">pref_option_language_standard</string>
12+
13+
<string name="pref_key_cpp_check">pref_key_cpp_check</string>
14+
<string name="pref_key_cpp_check_warning">pref_key_cpp_check_warning</string>
15+
<string name="pref_key_cpp_check_performance">pref_key_cpp_check_performance</string>
16+
<string name="pref_key_cpp_check_information">pref_key_cpp_check_information</string>
1217
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@
4444
<string name="compiler">Compiler</string>
4545
<string name="code_analysis">Code analysis</string>
4646

47+
4748
</resources>

app/src/main/res/xml/preferences_cppcheck.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
<CheckBoxPreference
2323
android:defaultValue="true"
24+
android:key="@string/pref_key_cpp_check"
2425
android:summary="Static analysis of C/C++ code. Checks for: memory leaks, mismatching allocation-deallocation, buffer overrun, and many more."
2526
android:title="Static code analysis" />
2627

@@ -29,16 +30,19 @@
2930
<PreferenceCategory android:title="Flags">
3031
<CheckBoxPreference
3132
android:defaultValue="true"
33+
android:key="@string/pref_key_cpp_check_warning"
3234
android:summary="enable warning messages"
3335
android:title="--enable=warning" />
3436

3537
<CheckBoxPreference
3638
android:defaultValue="true"
39+
android:key="@string/pref_key_cpp_check_performance"
3740
android:summary="enable performance messages"
3841
android:title="--enable=performance" />
3942

4043
<CheckBoxPreference
4144
android:defaultValue="true"
45+
android:key="@string/pref_key_cpp_check_information"
4246
android:summary="enable information messages"
4347
android:title="--enable=information" />
4448

libeditor/src/main/java/com/jecelyin/editor/v2/Preferences.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public boolean isAutoSave() {
219219
return getBoolean(context.getString(R.string.pref_auto_save), true);
220220
}
221221

222-
private boolean getBoolean(String key, boolean def) {
222+
public boolean getBoolean(String key, boolean def) {
223223
try {
224224
return preferences.getBoolean(key, def);
225225
} catch (ClassCastException e) {

0 commit comments

Comments
 (0)