Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
864f07d4
Commit
864f07d4
authored
Dec 22, 2008
by
Roberto Raggi
Browse files
Initial work on the test suite for the C++ front-end semantic pass.
parent
286e45b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/auto/cplusplus/semantic/semantic.pro
0 → 100644
View file @
864f07d4
load
(
qttest_p4
)
include
(..
/
shared
/
shared
.
pri
)
QT
=
core
SOURCES
+=
tst_semantic
.
cpp
tests/auto/cplusplus/semantic/tst_semantic.cpp
0 → 100644
View file @
864f07d4
#include
<QtTest>
#include
<QtDebug>
#include
<Control.h>
#include
<Parser.h>
#include
<AST.h>
#include
<Semantic.h>
#include
<Scope.h>
#include
<Symbols.h>
#include
<Names.h>
#include
<Literals.h>
CPLUSPLUS_USE_NAMESPACE
class
tst_Semantic
:
public
QObject
{
Q_OBJECT
Control
control
;
public:
TranslationUnit
*
parse
(
const
QByteArray
&
source
,
TranslationUnit
::
ParseMode
mode
)
{
StringLiteral
*
fileId
=
control
.
findOrInsertFileName
(
"<stdin>"
);
TranslationUnit
*
unit
=
new
TranslationUnit
(
&
control
,
fileId
);
unit
->
setSource
(
source
.
constData
(),
source
.
length
());
unit
->
parse
(
mode
);
return
unit
;
}
class
Document
{
Q_DISABLE_COPY
(
Document
)
public:
Document
(
TranslationUnit
*
unit
)
:
unit
(
unit
),
globals
(
new
Scope
())
{
}
~
Document
()
{
delete
globals
;
}
void
check
()
{
QVERIFY
(
unit
);
QVERIFY
(
unit
->
ast
());
Semantic
sem
(
unit
->
control
());
TranslationUnitAST
*
ast
=
unit
->
ast
()
->
asTranslationUnit
();
QVERIFY
(
ast
);
for
(
DeclarationAST
*
decl
=
ast
->
declarations
;
decl
;
decl
=
decl
->
next
)
{
sem
.
check
(
decl
,
globals
);
}
}
TranslationUnit
*
unit
;
Scope
*
globals
;
};
QSharedPointer
<
Document
>
document
(
const
QByteArray
&
source
)
{
TranslationUnit
*
unit
=
parse
(
source
,
TranslationUnit
::
ParseTranlationUnit
);
QSharedPointer
<
Document
>
doc
(
new
Document
(
unit
));
doc
->
check
();
return
doc
;
}
private
slots
:
void
function_declarations
();
};
void
tst_Semantic
::
function_declarations
()
{
QSharedPointer
<
Document
>
doc
=
document
(
"void foo();"
);
QCOMPARE
(
doc
->
globals
->
symbolCount
(),
1U
);
Declaration
*
decl
=
doc
->
globals
->
symbolAt
(
0
)
->
asDeclaration
();
QVERIFY
(
decl
);
FullySpecifiedType
declTy
=
decl
->
type
();
Function
*
funTy
=
declTy
->
asFunction
();
QVERIFY
(
funTy
);
QVERIFY
(
funTy
->
returnType
()
->
isVoidType
());
QCOMPARE
(
funTy
->
argumentCount
(),
0U
);
QVERIFY
(
decl
->
name
()
->
isNameId
());
Identifier
*
funId
=
decl
->
name
()
->
asNameId
()
->
identifier
();
QVERIFY
(
funId
);
const
QByteArray
foo
(
funId
->
chars
(),
funId
->
size
());
QCOMPARE
(
foo
,
QByteArray
(
"foo"
));
}
QTEST_APPLESS_MAIN
(
tst_Semantic
)
#include
"tst_semantic.moc"
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment