Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
28ab85b1
Commit
28ab85b1
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Removed obsolete code.
parent
3e9d4358
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/manual/cplusplus/main.cpp
+2
-284
2 additions, 284 deletions
tests/manual/cplusplus/main.cpp
with
2 additions
and
284 deletions
tests/manual/cplusplus/main.cpp
+
2
−
284
View file @
28ab85b1
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#include
<AST.h>
#include
<AST.h>
#include
<ASTVisitor.h>
#include
<ASTVisitor.h>
#include
<ASTMatcher.h>
#include
<Control.h>
#include
<Control.h>
#include
<Scope.h>
#include
<Scope.h>
#include
<Semantic.h>
#include
<Semantic.h>
...
@@ -53,289 +54,6 @@
...
@@ -53,289 +54,6 @@
using
namespace
CPlusPlus
;
using
namespace
CPlusPlus
;
class
CloneCG
:
protected
ASTVisitor
{
public:
CloneCG
(
Control
*
control
)
:
ASTVisitor
(
control
)
{
}
void
operator
()(
AST
*
ast
)
{
std
::
cout
<<
"/**************************************************************************
\n
"
"**
\n
"
"** This file is part of Qt Creator
\n
"
"**
\n
"
"** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
\n
"
"**
\n
"
"** Contact: Nokia Corporation (qt-info@nokia.com)
\n
"
"**
\n
"
"** Commercial Usage
\n
"
"**
\n
"
"** Licensees holding valid Qt Commercial licenses may use this file in
\n
"
"** accordance with the Qt Commercial License Agreement provided with the
\n
"
"** Software or, alternatively, in accordance with the terms contained in
\n
"
"** a written agreement between you and Nokia.
\n
"
"**
\n
"
"** GNU Lesser General Public License Usage
\n
"
"**
\n
"
"** Alternatively, this file may be used under the terms of the GNU Lesser
\n
"
"** General Public License version 2.1 as published by the Free Software
\n
"
"** Foundation and appearing in the file LICENSE.LGPL included in the
\n
"
"** packaging of this file. Please review the following information to
\n
"
"** ensure the GNU Lesser General Public License version 2.1 requirements
\n
"
"** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
\n
"
"**
\n
"
"** If you are unsure which license is appropriate for your use, please
\n
"
"** contact the sales department at http://qt.nokia.com/contact.
\n
"
"**
\n
"
"**************************************************************************/
\n
"
"
\n
"
"#include
\"
AST.h
\"\n
"
"#include
\"
ASTVisitor.h
\"\n
"
"
\n
"
"using namespace CPlusPlus;
\n
"
<<
std
::
endl
;
accept
(
ast
);
}
protected
:
using
ASTVisitor
::
visit
;
QMap
<
QByteArray
,
ClassSpecifierAST
*>
classMap
;
QByteArray
id_cast
(
NameAST
*
name
)
{
if
(
!
name
)
return
QByteArray
();
Identifier
*
id
=
identifier
(
name
->
asSimpleName
()
->
identifier_token
);
return
QByteArray
::
fromRawData
(
id
->
chars
(),
id
->
size
());
}
void
copyMembers
(
Class
*
klass
)
{
for
(
unsigned
i
=
0
;
i
<
klass
->
baseClassCount
();
++
i
)
{
const
QByteArray
baseClassName
=
klass
->
baseClassAt
(
i
)
->
identifier
()
->
chars
();
if
(
ClassSpecifierAST
*
baseClassSpec
=
classMap
.
value
(
baseClassName
,
0
))
{
copyMembers
(
baseClassSpec
->
symbol
);
}
}
const
QByteArray
className
=
klass
->
name
()
->
identifier
()
->
chars
();
std
::
cout
<<
" // copy "
<<
className
.
constData
()
<<
std
::
endl
;
for
(
unsigned
i
=
0
;
i
<
klass
->
memberCount
();
++
i
)
{
Symbol
*
member
=
klass
->
memberAt
(
i
);
Identifier
*
id
=
member
->
name
()
->
identifier
();
if
(
!
id
)
continue
;
const
QByteArray
memberName
=
QByteArray
::
fromRawData
(
id
->
chars
(),
id
->
size
());
if
(
member
->
type
().
isUnsigned
()
&&
memberName
.
endsWith
(
"_token"
))
{
std
::
cout
<<
" ast->"
<<
id
->
chars
()
<<
" = "
<<
id
->
chars
()
<<
";"
<<
std
::
endl
;
}
else
if
(
PointerType
*
ptrTy
=
member
->
type
()
->
asPointerType
())
{
if
(
NamedType
*
namedTy
=
ptrTy
->
elementType
()
->
asNamedType
())
{
QByteArray
typeName
=
namedTy
->
name
()
->
identifier
()
->
chars
();
if
(
typeName
.
endsWith
(
"AST"
))
{
std
::
cout
<<
" if ("
<<
memberName
.
constData
()
<<
") ast->"
<<
memberName
.
constData
()
<<
" = "
<<
memberName
.
constData
()
<<
"->clone(pool);"
<<
std
::
endl
;
}
}
}
}
}
virtual
bool
visit
(
ClassSpecifierAST
*
ast
)
{
Class
*
klass
=
ast
->
symbol
;
const
QByteArray
className
=
id_cast
(
ast
->
name
);
classMap
.
insert
(
className
,
ast
);
Identifier
*
clone_id
=
control
()
->
findOrInsertIdentifier
(
"clone"
);
if
(
!
klass
->
members
()
->
lookat
(
clone_id
))
return
true
;
std
::
cout
<<
className
.
constData
()
<<
" *"
<<
className
.
constData
()
<<
"::clone(MemoryPool *pool) const"
<<
std
::
endl
<<
"{"
<<
std
::
endl
;
std
::
cout
<<
" "
<<
className
.
constData
()
<<
" *ast = new (pool) "
<<
className
.
constData
()
<<
";"
<<
std
::
endl
;
copyMembers
(
klass
);
std
::
cout
<<
" return ast;"
<<
std
::
endl
<<
"}"
<<
std
::
endl
<<
std
::
endl
;
return
true
;
}
};
class
SearchListNodes
:
protected
ASTVisitor
{
QList
<
QByteArray
>
_listNodes
;
public:
SearchListNodes
(
Control
*
control
)
:
ASTVisitor
(
control
)
{
}
QList
<
QByteArray
>
operator
()(
AST
*
ast
)
{
_listNodes
.
clear
();
accept
(
ast
);
return
_listNodes
;
}
protected
:
virtual
bool
visit
(
ClassSpecifierAST
*
ast
)
{
for
(
unsigned
i
=
0
;
i
<
ast
->
symbol
->
memberCount
();
++
i
)
{
Symbol
*
member
=
ast
->
symbol
->
memberAt
(
i
);
if
(
!
qstrcmp
(
"next"
,
member
->
name
()
->
identifier
()
->
chars
()))
{
_listNodes
.
append
(
ast
->
symbol
->
name
()
->
identifier
()
->
chars
());
break
;
}
}
return
true
;
}
};
class
VisitCG
:
protected
ASTVisitor
{
QList
<
QByteArray
>
_listNodes
;
public:
VisitCG
(
Control
*
control
)
:
ASTVisitor
(
control
)
{
}
void
operator
()(
AST
*
ast
)
{
std
::
cout
<<
"/**************************************************************************
\n
"
"**
\n
"
"** This file is part of Qt Creator
\n
"
"**
\n
"
"** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
\n
"
"**
\n
"
"** Contact: Nokia Corporation (qt-info@nokia.com)
\n
"
"**
\n
"
"** Commercial Usage
\n
"
"**
\n
"
"** Licensees holding valid Qt Commercial licenses may use this file in
\n
"
"** accordance with the Qt Commercial License Agreement provided with the
\n
"
"** Software or, alternatively, in accordance with the terms contained in
\n
"
"** a written agreement between you and Nokia.
\n
"
"**
\n
"
"** GNU Lesser General Public License Usage
\n
"
"**
\n
"
"** Alternatively, this file may be used under the terms of the GNU Lesser
\n
"
"** General Public License version 2.1 as published by the Free Software
\n
"
"** Foundation and appearing in the file LICENSE.LGPL included in the
\n
"
"** packaging of this file. Please review the following information to
\n
"
"** ensure the GNU Lesser General Public License version 2.1 requirements
\n
"
"** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
\n
"
"**
\n
"
"** If you are unsure which license is appropriate for your use, please
\n
"
"** contact the sales department at http://qt.nokia.com/contact.
\n
"
"**
\n
"
"**************************************************************************/
\n
"
"
\n
"
"#include
\"
AST.h
\"\n
"
"
\n
"
"using namespace CPlusPlus;
\n
"
<<
std
::
endl
;
SearchListNodes
listNodes
(
control
());
_listNodes
=
listNodes
(
ast
);
accept
(
ast
);
}
protected
:
using
ASTVisitor
::
visit
;
QMap
<
QByteArray
,
ClassSpecifierAST
*>
classMap
;
QByteArray
id_cast
(
NameAST
*
name
)
{
if
(
!
name
)
return
QByteArray
();
Identifier
*
id
=
identifier
(
name
->
asSimpleName
()
->
identifier_token
);
return
QByteArray
::
fromRawData
(
id
->
chars
(),
id
->
size
());
}
void
visitMembers
(
Class
*
klass
)
{
const
QByteArray
className
=
klass
->
name
()
->
identifier
()
->
chars
();
std
::
cout
<<
" // visit "
<<
className
.
constData
()
<<
std
::
endl
;
for
(
unsigned
i
=
0
;
i
<
klass
->
memberCount
();
++
i
)
{
Symbol
*
member
=
klass
->
memberAt
(
i
);
Identifier
*
id
=
member
->
name
()
->
identifier
();
if
(
!
id
)
continue
;
const
QByteArray
memberName
=
QByteArray
::
fromRawData
(
id
->
chars
(),
id
->
size
());
if
(
member
->
type
().
isUnsigned
()
&&
memberName
.
endsWith
(
"_token"
))
{
// nothing to do. The member is a token.
}
else
if
(
PointerType
*
ptrTy
=
member
->
type
()
->
asPointerType
())
{
if
(
NamedType
*
namedTy
=
ptrTy
->
elementType
()
->
asNamedType
())
{
QByteArray
typeName
=
namedTy
->
name
()
->
identifier
()
->
chars
();
if
(
_listNodes
.
contains
(
typeName
)
&&
memberName
!=
"next"
)
{
std
::
cout
<<
" for ("
<<
typeName
.
constData
()
<<
" *it = "
<<
memberName
.
constData
()
<<
"; it; it = it->next)"
<<
std
::
endl
<<
" accept(it, visitor);"
<<
std
::
endl
;
}
else
if
(
typeName
.
endsWith
(
"AST"
)
&&
memberName
!=
"next"
)
{
std
::
cout
<<
" accept("
<<
memberName
.
constData
()
<<
", visitor);"
<<
std
::
endl
;
}
}
}
}
for
(
unsigned
i
=
0
;
i
<
klass
->
baseClassCount
();
++
i
)
{
const
QByteArray
baseClassName
=
klass
->
baseClassAt
(
i
)
->
identifier
()
->
chars
();
if
(
ClassSpecifierAST
*
baseClassSpec
=
classMap
.
value
(
baseClassName
,
0
))
{
visitMembers
(
baseClassSpec
->
symbol
);
}
}
}
virtual
bool
visit
(
ClassSpecifierAST
*
ast
)
{
Class
*
klass
=
ast
->
symbol
;
const
QByteArray
className
=
id_cast
(
ast
->
name
);
classMap
.
insert
(
className
,
ast
);
Identifier
*
visit_id
=
control
()
->
findOrInsertIdentifier
(
"accept0"
);
if
(
!
klass
->
members
()
->
lookat
(
visit_id
))
return
true
;
std
::
cout
<<
"void "
<<
className
.
constData
()
<<
"::accept0(ASTVisitor *visitor)"
<<
std
::
endl
<<
"{"
<<
std
::
endl
<<
" if (visitor->visit(this)) {"
<<
std
::
endl
;
visitMembers
(
klass
);
std
::
cout
<<
" }"
<<
std
::
endl
<<
" visitor->endVisit(this);"
<<
std
::
endl
<<
"}"
<<
std
::
endl
<<
std
::
endl
;
return
true
;
}
};
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
QCoreApplication
app
(
argc
,
argv
);
QCoreApplication
app
(
argc
,
argv
);
...
@@ -377,7 +95,7 @@ int main(int argc, char *argv[])
...
@@ -377,7 +95,7 @@ int main(int argc, char *argv[])
Namespace
*
globalNamespace
=
control
.
newNamespace
(
0
,
0
);
Namespace
*
globalNamespace
=
control
.
newNamespace
(
0
,
0
);
Semantic
sem
(
&
control
);
Semantic
sem
(
&
control
);
for
(
DeclarationListAST
*
it
=
ast
->
declaration
s
;
it
;
it
=
it
->
next
)
{
for
(
DeclarationListAST
*
it
=
ast
->
declaration
_list
;
it
;
it
=
it
->
next
)
{
DeclarationAST
*
declaration
=
it
->
value
;
DeclarationAST
*
declaration
=
it
->
value
;
sem
.
check
(
declaration
,
globalNamespace
->
members
());
sem
.
check
(
declaration
,
globalNamespace
->
members
());
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment