Skip to content

Commit 451f7b6

Browse files
committed
Add checks for identifiers
1 parent f2b98ec commit 451f7b6

6 files changed

+74
-12
lines changed

src/Parsers/CppParser/cppdocumentparser.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ CppDocumentParser::CppDocumentParser( QObject* parent )
398398
modelManager->disconnect( this );
399399
SpellCheckerCore::instance()->disconnect( this );
400400
this->disconnect( SpellCheckerCore::instance() ); }, Qt::DirectConnection );
401-
402401
Core::Context context( CppEditor::Constants::CPPEDITOR_ID );
403402
Core::ActionContainer* cppEditorContextMenu = Core::ActionManager::createMenu( CppEditor::Constants::M_CONTEXT );
404403
Core::ActionContainer* contextMenu = Core::ActionManager::createMenu( Constants::CONTEXT_MENU_ID );

src/Parsers/CppParser/cppdocumentprocessor.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ void CppDocumentProcessor::process( CppDocumentProcessor::Promise& promise )
155155
return;
156156
}
157157

158+
if (d->settings.whatToCheck.testFlag(CppParserSettings::CheckIdentifiers)) {
159+
/* Parse identifiers (consider merging all the 3 loops, because we now touch each token) */
160+
unsigned int tokenCount = d->trUnit->tokenCount();
161+
for ( unsigned int tokenIndex = 0; tokenIndex < tokenCount; ++tokenIndex ) {
162+
const CPlusPlus::Token &token{ d->trUnit->tokenAt( tokenIndex ) };
163+
const CPlusPlus::Identifier *identifier{ token.identifier };
164+
if ( identifier ) {
165+
wordTokens.push_back( parseToken( token, WordTokens::Type::Identifier ) );
166+
}
167+
}
168+
}
169+
170+
if (promise.isCanceled() == true) {
171+
promise.future().cancel();
172+
return;
173+
}
174+
158175
/* At this point the DocPtr can be released since it will no longer be
159176
* Used */
160177
d->docPtr->releaseSourceAndAST();

src/Parsers/CppParser/cppdocumentprocessor.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ struct WordTokens
5656
enum class Type {
5757
Comment = 0,
5858
Doxygen,
59-
Literal
59+
Literal,
60+
Identifier,
6061
};
6162

6263
HashWords::key_type hash;

src/Parsers/CppParser/cppparseroptionswidget.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ CppParserOptionsWidget::CppParserOptionsWidget( const CppParserSettings* const s
3939
/* Set up the options for What to Check */
4040
ui->checkBoxWhatComments->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CheckComments );
4141
ui->checkBoxWhatLiterals->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CheckStringLiterals );
42+
ui->checkBoxWhatIdentifiers->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CheckIdentifiers );
4243
connect( ui->checkBoxWhatComments, &QAbstractButton::toggled, this, &CppParserOptionsWidget::checkBoxWhatToggled );
4344
connect( ui->checkBoxWhatLiterals, &QAbstractButton::toggled, this, &CppParserOptionsWidget::checkBoxWhatToggled );
45+
connect( ui->checkBoxWhatIdentifiers, &QAbstractButton::toggled, this, &CppParserOptionsWidget::checkBoxWhatToggled );
4446
/* Set up the options for Comments to Check */
4547
ui->radioButtonCommentsC->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CommentsC );
4648
ui->radioButtonCommentsCpp->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CommentsCpp );
@@ -152,6 +154,7 @@ void CppParserOptionsWidget::updateWithSettings( const CppParserSettings* const
152154
ui->checkBoxIgnoreCaps->setChecked( !settings->checkAllCapsWords );
153155
ui->checkBoxWhatComments->setChecked(settings->whatToCheck.testFlag(CppParserSettings::CheckComments));
154156
ui->checkBoxWhatLiterals->setChecked(settings->whatToCheck.testFlag(CppParserSettings::CheckStringLiterals));
157+
ui->checkBoxWhatIdentifiers->setChecked(settings->whatToCheck.testFlag(CppParserSettings::CheckIdentifiers));
155158
QRadioButton* commentButtons[] = { nullptr, ui->radioButtonCommentsC, ui->radioButtonCommentsCpp, ui->radioButtonCommentsBoth };
156159
commentButtons[settings->commentsToCheck]->setChecked( true );
157160
QRadioButton* numberButtons[] = { ui->radioButtonNumbersRemove, ui->radioButtonNumbersSplit, ui->radioButtonNumbersLeave };

src/Parsers/CppParser/cppparseroptionswidget.ui

+48-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<x>0</x>
6969
<y>0</y>
7070
<width>801</width>
71-
<height>1803</height>
71+
<height>1843</height>
7272
</rect>
7373
</property>
7474
<property name="sizePolicy">
@@ -111,6 +111,13 @@
111111
<property name="verticalSpacing">
112112
<number>0</number>
113113
</property>
114+
<item row="0" column="0" colspan="2">
115+
<widget class="QCheckBox" name="checkBoxWhatComments">
116+
<property name="text">
117+
<string>Comments</string>
118+
</property>
119+
</widget>
120+
</item>
114121
<item row="1" column="0">
115122
<spacer name="horizontalSpacer_19">
116123
<property name="orientation">
@@ -148,6 +155,13 @@
148155
</property>
149156
</widget>
150157
</item>
158+
<item row="2" column="0" colspan="2">
159+
<widget class="QCheckBox" name="checkBoxWhatLiterals">
160+
<property name="text">
161+
<string>String Literals</string>
162+
</property>
163+
</widget>
164+
</item>
151165
<item row="3" column="0">
152166
<spacer name="horizontalSpacer_20">
153167
<property name="orientation">
@@ -201,20 +215,47 @@
201215
</property>
202216
</spacer>
203217
</item>
204-
<item row="0" column="0" colspan="2">
205-
<widget class="QCheckBox" name="checkBoxWhatComments">
218+
<item row="5" column="0" colspan="2">
219+
<widget class="QCheckBox" name="checkBoxWhatIdentifiers">
206220
<property name="text">
207-
<string>Comments</string>
221+
<string>Identifiers</string>
208222
</property>
209223
</widget>
210224
</item>
211-
<item row="2" column="0" colspan="2">
212-
<widget class="QCheckBox" name="checkBoxWhatLiterals">
225+
<item row="7" column="1">
226+
<widget class="QLabel" name="label">
227+
<property name="sizePolicy">
228+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
229+
<horstretch>0</horstretch>
230+
<verstretch>0</verstretch>
231+
</sizepolicy>
232+
</property>
233+
<property name="font">
234+
<font>
235+
<italic>true</italic>
236+
</font>
237+
</property>
213238
<property name="text">
214-
<string>String Literals</string>
239+
<string>Identifiers, such as variable, type, and function names.</string>
215240
</property>
216241
</widget>
217242
</item>
243+
<item row="7" column="0">
244+
<spacer name="horizontalSpacer_25">
245+
<property name="orientation">
246+
<enum>Qt::Orientation::Horizontal</enum>
247+
</property>
248+
<property name="sizeType">
249+
<enum>QSizePolicy::Policy::Fixed</enum>
250+
</property>
251+
<property name="sizeHint" stdset="0">
252+
<size>
253+
<width>40</width>
254+
<height>0</height>
255+
</size>
256+
</property>
257+
</spacer>
258+
</item>
218259
</layout>
219260
</widget>
220261
</item>

src/Parsers/CppParser/cppparsersettings.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ class CppParserSettings
4040
~CppParserSettings();
4141

4242
enum WhatToCheck {
43-
Tokens_NONE = 0, /*!< Invalid option needed for QFLAGS. */
44-
CheckComments = 1 << 0, /*!< Check Comments. */
45-
CheckStringLiterals = 1 << 1, /*!< Check String Literals */
43+
Tokens_NONE = 0, /*!< Invalid option needed for QFLAGS. */
44+
CheckComments = 1 << 0, /*!< Check Comments. */
45+
CheckStringLiterals = 1 << 1, /*!< Check String Literals */
46+
CheckIdentifiers = 1 << 2, /*!< Check Identifiers */
4647
};
4748
Q_DECLARE_FLAGS( WhatToCheckOptions, WhatToCheck )
4849

0 commit comments

Comments
 (0)