Skip to content

Commit

Permalink
Cpp analyser working perfect
Browse files Browse the repository at this point in the history
  • Loading branch information
tranleduy2000 committed May 30, 2018
1 parent d0b3f89 commit d70e388
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
import android.text.Editable;
import android.text.TextWatcher;

import com.duy.ccppcompiler.R;
import com.duy.ccppcompiler.compiler.shell.CommandBuilder;
import com.duy.ccppcompiler.compiler.shell.CommandResult;
import com.duy.ccppcompiler.compiler.shell.Shell;
import com.duy.common.DLog;
import com.duy.ide.diagnostic.Diagnostic;
import com.duy.ide.diagnostic.DiagnosticPresenter;
import com.duy.ide.diagnostic.DiagnosticsCollector;
import com.jecelyin.editor.v2.Preferences;
import com.jecelyin.editor.v2.editor.IEditorDelegate;
import com.jecelyin.editor.v2.io.LocalFileWriter;

Expand Down Expand Up @@ -157,7 +159,25 @@ protected ArrayList<Diagnostic> doInBackground(Void... voids) {
CommandBuilder builder = new CommandBuilder(CPPCHECK_PROGRAM);
builder.addFlags(CppCheckOutputParser.TEMPLATE);
builder.addFlags(tmpFile.getAbsolutePath());
builder.addFlags("--enable=warning,performance,information");

String enableFlags = "";
//flags
Preferences setting = Preferences.getInstance(mContext);
boolean warn = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_warning), true);
if (warn) enableFlags += "warning";
boolean performance = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_performance), true);
if (performance) {
if (!enableFlags.isEmpty()) enableFlags += ",";
enableFlags += "performance";
}
boolean information = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_information), true);
if (information) {
if (!enableFlags.isEmpty()) enableFlags += ",";
enableFlags += "information";
}
if (!enableFlags.isEmpty()) {
builder.addFlags("--enable=" + enableFlags);
}

String cmd = builder.build();
CommandResult result = Shell.exec(mContext, tmpFile.getParent(), cmd);
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/do_not_translate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
<string name="pref_c_options_traditional_cpp">pref_c_options_traditional_cpp</string>
<string name="pref_option_optimization_level">pref_option_optimization_level</string>
<string name="pref_option_language_standard">pref_option_language_standard</string>

<string name="pref_key_cpp_check">pref_key_cpp_check</string>
<string name="pref_key_cpp_check_warning">pref_key_cpp_check_warning</string>
<string name="pref_key_cpp_check_performance">pref_key_cpp_check_performance</string>
<string name="pref_key_cpp_check_information">pref_key_cpp_check_information</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@
<string name="compiler">Compiler</string>
<string name="code_analysis">Code analysis</string>


</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/xml/preferences_cppcheck.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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

Expand All @@ -29,16 +30,19 @@
<PreferenceCategory android:title="Flags">
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key_cpp_check_warning"
android:summary="enable warning messages"
android:title="--enable=warning" />

<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key_cpp_check_performance"
android:summary="enable performance messages"
android:title="--enable=performance" />

<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key_cpp_check_information"
android:summary="enable information messages"
android:title="--enable=information" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public boolean isAutoSave() {
return getBoolean(context.getString(R.string.pref_auto_save), true);
}

private boolean getBoolean(String key, boolean def) {
public boolean getBoolean(String key, boolean def) {
try {
return preferences.getBoolean(key, def);
} catch (ClassCastException e) {
Expand Down

0 comments on commit d70e388

Please sign in to comment.