Skip to content

Commit fb3b2f1

Browse files
committed
applied patch from Uwe Siems (print correct file location in parser)
1 parent 6128744 commit fb3b2f1

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

generator/parser/binder.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ FileModelItem Binder::run(AST *node)
9191
return result;
9292
}
9393

94-
ScopeModelItem Binder::currentScope()
94+
ScopeModelItem Binder::currentScope() const
9595
{
9696
if (_M_current_class)
9797
return model_static_cast<ScopeModelItem>(_M_current_class);
@@ -175,6 +175,7 @@ CodeModel::ClassType Binder::decode_class_type(std::size_t index) const
175175
case Token_union:
176176
return CodeModel::Union;
177177
default:
178+
warnHere();
178179
std::cerr << "** WARNING unrecognized class type" << std::endl;
179180
}
180181
return CodeModel::Class;
@@ -254,6 +255,7 @@ void Binder::declare_symbol(SimpleDeclarationAST *node, InitDeclaratorAST *init_
254255
NameAST *id = declarator->id;
255256
if (! declarator->id)
256257
{
258+
warnHere();
257259
std::cerr << "** WARNING expected a declarator id" << std::endl;
258260
return;
259261
}
@@ -263,6 +265,7 @@ void Binder::declare_symbol(SimpleDeclarationAST *node, InitDeclaratorAST *init_
263265
if (! symbolScope)
264266
{
265267
name_cc.run(id);
268+
warnHere();
266269
std::cerr << "** WARNING scope not found for symbol:"
267270
<< qPrintable(name_cc.name()) << std::endl;
268271
return;
@@ -371,7 +374,8 @@ void Binder::visitFunctionDefinition(FunctionDefinitionAST *node)
371374
declarator = declarator->sub_declarator;
372375
//Q_ASSERT(declarator->id);
373376
if (!declarator->id) {
374-
std::cerr << "** SHIT" << qPrintable(name_cc.name()) << std::endl
377+
warnHere();
378+
std::cerr << "** SHIT " << qPrintable(name_cc.name()) << std::endl
375379
<< "\tdefinition *ignored*"
376380
<< std::endl;
377381
return;
@@ -381,8 +385,9 @@ void Binder::visitFunctionDefinition(FunctionDefinitionAST *node)
381385
ScopeModelItem functionScope = finder.resolveScope(declarator->id, scope);
382386
if (! functionScope)
383387
{
388+
warnHere();
384389
name_cc.run(declarator->id);
385-
std::cerr << "** WARNING scope not found for function definition:"
390+
std::cerr << "** WARNING scope not found for function definition: "
386391
<< qPrintable(name_cc.name()) << std::endl
387392
<< "\tdefinition *ignored*"
388393
<< std::endl;
@@ -392,6 +397,7 @@ void Binder::visitFunctionDefinition(FunctionDefinitionAST *node)
392397
decl_cc.run(declarator);
393398
foreach (DeclaratorCompiler::Parameter p, decl_cc.parameters()) {
394399
if (p.type.isRvalueReference()) {
400+
//warnHere();
395401
//std::cerr << "** Skipping function with rvalue reference parameter: "
396402
// << qPrintable(name_cc.name()) << std::endl;
397403
return;
@@ -565,6 +571,7 @@ void Binder::visitTypedef(TypedefAST *node)
565571

566572
if (alias_name.isEmpty ())
567573
{
574+
warnHere();
568575
std::cerr << "** WARNING anonymous typedef not supported! ``";
569576
Token const &tk = _M_token_stream->token ((int) node->start_token);
570577
Token const &end_tk = _M_token_stream->token ((int) node->end_token);
@@ -830,6 +837,16 @@ void Binder::visitQProperty(QPropertyAST *node)
830837
_M_current_class->addPropertyDeclaration(property);
831838
}
832839

840+
void Binder::warnHere() const
841+
{
842+
ScopeModelItem scope = currentScope();
843+
QString fileName = scope ? scope->fileName() : QString("<unknown>");
844+
if (fileName != _M_lastWarnedFile) {
845+
_M_lastWarnedFile = fileName;
846+
std::cerr << "In file " << fileName.toLatin1().constData() << ":" << std::endl;
847+
}
848+
}
849+
833850
void Binder::applyStorageSpecifiers(const ListNode<std::size_t> *it, MemberModelItem item)
834851
{
835852
if (it == 0)

generator/parser/binder.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Binder: protected DefaultVisitor
6262

6363
inline TokenStream *tokenStream() const { return _M_token_stream; }
6464
inline CodeModel *model() const { return _M_model; }
65-
ScopeModelItem currentScope();
65+
ScopeModelItem currentScope() const;
6666

6767
FileModelItem run(AST *node);
6868

@@ -86,6 +86,8 @@ class Binder: protected DefaultVisitor
8686
virtual void visitForwardDeclarationSpecifier(ForwardDeclarationSpecifierAST *);
8787
virtual void visitQEnums(QEnumsAST *);
8888

89+
void warnHere() const;
90+
8991
private:
9092

9193
int decode_token(std::size_t index) const;
@@ -126,6 +128,7 @@ class Binder: protected DefaultVisitor
126128
TemplateParameterList _M_current_template_parameters; // ### check me
127129
QHash<QString, QString> _M_qualified_types;
128130
QHash<QString, int> _M_anonymous_enums;
131+
mutable QString _M_lastWarnedFile;
129132

130133
protected:
131134
TypeCompiler type_cc;

generator/parser/codemodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ FileModelItem _CodeModelItem::file() const
313313
return model()->findFile(fileName());
314314
}
315315

316-
void _CodeModelItem::getStartPosition(int *line, int *column)
316+
void _CodeModelItem::getStartPosition(int *line, int *column) const
317317
{
318318
*line = _M_startLine;
319319
*column = _M_startColumn;
@@ -325,7 +325,7 @@ void _CodeModelItem::setStartPosition(int line, int column)
325325
_M_startColumn = column;
326326
}
327327

328-
void _CodeModelItem::getEndPosition(int *line, int *column)
328+
void _CodeModelItem::getEndPosition(int *line, int *column) const
329329
{
330330
*line = _M_endLine;
331331
*column = _M_endColumn;

generator/parser/codemodel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ class _CodeModelItem: public QSharedData
242242

243243
FileModelItem file() const;
244244

245-
void getStartPosition(int *line, int *column);
245+
void getStartPosition(int *line, int *column) const;
246246
void setStartPosition(int line, int column);
247247

248-
void getEndPosition(int *line, int *column);
248+
void getEndPosition(int *line, int *column) const;
249249
void setEndPosition(int line, int column);
250250

251251
inline std::size_t creationId() const { return _M_creation_id; }

0 commit comments

Comments
 (0)