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
e4f07e9f
Commit
e4f07e9f
authored
15 years ago
by
Erik Verbruggen
Browse files
Options
Downloads
Patches
Plain Diff
Added AST node constructor generation.
parent
33d59283
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/tools/cplusplus/generate-ast.cpp
+86
-6
86 additions, 6 deletions
src/tools/cplusplus/generate-ast.cpp
with
86 additions
and
6 deletions
src/tools/cplusplus/generate-ast.cpp
+
86
−
6
View file @
e4f07e9f
...
...
@@ -769,6 +769,72 @@ private:
Overview
oo
;
};
static
QList
<
QTextCursor
>
removeConstructors
(
ClassSpecifierAST
*
classAST
,
TranslationUnit
*
translationUnit
,
QTextDocument
*
document
)
{
Overview
oo
;
QList
<
QTextCursor
>
cursors
;
const
QString
className
=
oo
(
classAST
->
symbol
->
name
());
for
(
DeclarationListAST
*
iter
=
classAST
->
member_specifier_list
;
iter
;
iter
=
iter
->
next
)
{
if
(
FunctionDefinitionAST
*
funDef
=
iter
->
value
->
asFunctionDefinition
())
{
if
(
oo
(
funDef
->
symbol
->
name
())
==
className
)
{
// found it:
QTextCursor
tc
=
createCursor
(
translationUnit
,
funDef
,
document
);
tc
.
movePosition
(
QTextCursor
::
EndOfBlock
,
QTextCursor
::
KeepAnchor
);
tc
.
setPosition
(
tc
.
position
()
+
1
,
QTextCursor
::
KeepAnchor
);
cursors
.
append
(
tc
);
}
}
}
return
cursors
;
}
static
QStringList
collectFields
(
ClassSpecifierAST
*
classAST
)
{
QStringList
fields
;
Overview
oo
;
Class
*
clazz
=
classAST
->
symbol
;
for
(
unsigned
i
=
0
;
i
<
clazz
->
memberCount
();
++
i
)
{
Symbol
*
s
=
clazz
->
memberAt
(
i
);
if
(
Declaration
*
decl
=
s
->
asDeclaration
())
{
FullySpecifiedType
ty
=
decl
->
type
();
if
(
ty
->
isPointerType
())
fields
.
append
(
oo
(
decl
->
name
()));
else
if
(
ty
.
isUnsigned
())
fields
.
append
(
oo
(
decl
->
name
()));
}
}
return
fields
;
}
static
QString
createConstructor
(
ClassSpecifierAST
*
classAST
)
{
Overview
oo
;
Class
*
clazz
=
classAST
->
symbol
;
QString
result
(
QLatin1String
(
" "
));
result
.
append
(
oo
(
clazz
->
name
()));
result
.
append
(
QLatin1String
(
"()
\n
"
));
QStringList
classFields
=
collectFields
(
classAST
);
for
(
int
i
=
0
;
i
<
classFields
.
size
();
++
i
)
{
if
(
i
==
0
)
{
result
.
append
(
QLatin1String
(
" : "
));
result
.
append
(
classFields
.
at
(
i
));
result
.
append
(
QLatin1String
(
"(0)
\n
"
));
}
else
{
result
.
append
(
QLatin1String
(
" , "
));
result
.
append
(
classFields
.
at
(
i
));
result
.
append
(
QLatin1String
(
"(0)
\n
"
));
}
}
result
.
append
(
QLatin1String
(
" {}
\n
"
));
return
result
;
}
QStringList
generateAST_H
(
const
Snapshot
&
snapshot
,
const
QDir
&
cplusplusDir
)
{
...
...
@@ -802,6 +868,8 @@ QStringList generateAST_H(const Snapshot &snapshot, const QDir &cplusplusDir)
QList
<
QTextCursor
>
baseCastMethodCursors
=
removeCastMethods
(
astNodes
.
base
);
QMap
<
ClassSpecifierAST
*
,
QList
<
QTextCursor
>
>
cursors
;
QMap
<
ClassSpecifierAST
*
,
QString
>
replacementCastMethods
;
QMap
<
ClassSpecifierAST
*
,
QList
<
QTextCursor
>
>
constructors
;
QMap
<
ClassSpecifierAST
*
,
QString
>
replacementConstructors
;
Overview
oo
;
...
...
@@ -812,8 +880,10 @@ QStringList generateAST_H(const Snapshot &snapshot, const QDir &cplusplusDir)
const
QString
methodName
=
QLatin1String
(
"as"
)
+
className
.
mid
(
0
,
className
.
length
()
-
3
);
replacementCastMethods
[
classAST
]
=
QString
(
" virtual %1 *%2() { return this; }
\n
"
).
arg
(
className
,
methodName
);
castMethods
.
append
(
QString
(
" virtual %1 *%2() { return 0; }
\n
"
).
arg
(
className
,
methodName
));
astDerivedClasses
.
append
(
className
);
constructors
[
classAST
]
=
removeConstructors
(
classAST
,
AST_h_document
->
translationUnit
(),
&
document
);
replacementConstructors
[
classAST
]
=
createConstructor
(
classAST
);
}
if
(
!
baseCastMethodCursors
.
isEmpty
())
{
...
...
@@ -828,13 +898,23 @@ QStringList generateAST_H(const Snapshot &snapshot, const QDir &cplusplusDir)
for
(
int
classIndex
=
0
;
classIndex
<
astNodes
.
deriveds
.
size
();
++
classIndex
)
{
ClassSpecifierAST
*
classAST
=
astNodes
.
deriveds
.
at
(
classIndex
);
// remove the cast methods.
QList
<
QTextCursor
>
c
=
cursors
.
value
(
classAST
);
for
(
int
i
=
0
;
i
<
c
.
length
();
++
i
)
{
c
[
i
].
removeSelectedText
();
{
// remove the cast methods.
QList
<
QTextCursor
>
c
=
cursors
.
value
(
classAST
);
for
(
int
i
=
0
;
i
<
c
.
length
();
++
i
)
{
c
[
i
].
removeSelectedText
();
}
}
{
// remove the constructors.
QList
<
QTextCursor
>
c
=
constructors
.
value
(
classAST
);
for
(
int
i
=
0
;
i
<
c
.
length
();
++
i
)
{
c
[
i
].
removeSelectedText
();
}
}
astNodes
.
endOfPublicClassSpecifiers
[
classIndex
].
insertText
(
replacementCastMethods
.
value
(
classAST
));
astNodes
.
endOfPublicClassSpecifiers
[
classIndex
].
insertText
(
replacementConstructors
.
value
(
classAST
)
+
QLatin1String
(
"
\n
"
)
+
replacementCastMethods
.
value
(
classAST
));
}
if
(
file
.
open
(
QFile
::
WriteOnly
))
{
...
...
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