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
908d73f0
Commit
908d73f0
authored
May 09, 2011
by
Erik Verbruggen
Browse files
Added the Enumerator class as a special Declaration.
Reviewed-by: Roberto Raggi
parent
49814d9e
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/shared/cplusplus/Bind.cpp
View file @
908d73f0
...
...
@@ -475,12 +475,17 @@ void Bind::enumerator(EnumeratorAST *ast, Enum *symbol)
// unsigned identifier_token = ast->identifier_token;
// unsigned equal_token = ast->equal_token;
ExpressionTy
expression
=
this
->
expression
(
ast
->
expression
);
/*
ExpressionTy expression =
*/
this
->
expression
(
ast
->
expression
);
if
(
ast
->
identifier_token
)
{
const
Name
*
name
=
identifier
(
ast
->
identifier_token
);
Declaration
*
e
=
control
()
->
newDeclaration
(
ast
->
identifier_token
,
name
);
Enumerator
Declaration
*
e
=
control
()
->
new
Enumerator
Declaration
(
ast
->
identifier_token
,
name
);
e
->
setType
(
control
()
->
integerType
(
IntegerType
::
Int
));
// ### introduce IntegerType::Enumerator
if
(
ExpressionAST
*
expr
=
ast
->
expression
)
{
e
->
setConstantValue
(
asStringLiteral
(
expr
->
firstToken
(),
expr
->
lastToken
()));
}
symbol
->
addMember
(
e
);
}
}
...
...
@@ -1146,6 +1151,17 @@ FullySpecifiedType Bind::trailingReturnType(TrailingReturnTypeAST *ast, const Fu
return
type
;
}
const
StringLiteral
*
Bind
::
asStringLiteral
(
unsigned
firstToken
,
unsigned
lastToken
)
{
std
::
string
buffer
;
for
(
unsigned
index
=
firstToken
;
index
!=
lastToken
;
++
index
)
{
const
Token
&
tk
=
tokenAt
(
index
);
if
(
tk
.
whitespace
()
||
tk
.
newline
())
buffer
+=
' '
;
buffer
+=
tk
.
spell
();
}
return
control
()
->
stringLiteral
(
buffer
.
c_str
(),
buffer
.
size
());
}
// StatementAST
bool
Bind
::
visit
(
QtMemberDeclarationAST
*
ast
)
...
...
@@ -2140,15 +2156,7 @@ bool Bind::visit(ParameterDeclarationAST *ast)
if
(
ast
->
expression
)
{
unsigned
startOfExpression
=
ast
->
expression
->
firstToken
();
unsigned
endOfExpression
=
ast
->
expression
->
lastToken
();
std
::
string
buffer
;
for
(
unsigned
index
=
startOfExpression
;
index
!=
endOfExpression
;
++
index
)
{
const
Token
&
tk
=
tokenAt
(
index
);
if
(
tk
.
whitespace
()
||
tk
.
newline
())
buffer
+=
' '
;
buffer
+=
tk
.
spell
();
}
const
StringLiteral
*
initializer
=
control
()
->
stringLiteral
(
buffer
.
c_str
(),
buffer
.
size
());
arg
->
setInitializer
(
initializer
);
arg
->
setInitializer
(
asStringLiteral
(
startOfExpression
,
endOfExpression
));
}
_scope
->
addMember
(
arg
);
...
...
src/shared/cplusplus/Bind.h
View file @
908d73f0
...
...
@@ -136,6 +136,7 @@ protected:
void
capture
(
CaptureAST
*
ast
);
void
lambdaDeclarator
(
LambdaDeclaratorAST
*
ast
);
FullySpecifiedType
trailingReturnType
(
TrailingReturnTypeAST
*
ast
,
const
FullySpecifiedType
&
init
);
const
StringLiteral
*
asStringLiteral
(
unsigned
firstToken
,
unsigned
lastToken
);
virtual
bool
preVisit
(
AST
*
);
virtual
void
postVisit
(
AST
*
);
...
...
src/shared/cplusplus/CPlusPlusForwardDeclarations.h
View file @
908d73f0
...
...
@@ -126,6 +126,7 @@ class BaseClass;
class
Block
;
class
Class
;
class
Enum
;
class
EnumeratorDeclaration
;
class
ForwardClassDeclaration
;
class
Token
;
...
...
src/shared/cplusplus/Control.cpp
View file @
908d73f0
...
...
@@ -326,6 +326,13 @@ public:
return
declaration
;
}
EnumeratorDeclaration
*
newEnumeratorDeclaration
(
unsigned
sourceLocation
,
const
Name
*
name
)
{
EnumeratorDeclaration
*
decl
=
new
EnumeratorDeclaration
(
translationUnit
,
sourceLocation
,
name
);
symbols
.
push_back
(
decl
);
return
decl
;
}
Argument
*
newArgument
(
unsigned
sourceLocation
,
const
Name
*
name
)
{
Argument
*
argument
=
new
Argument
(
translationUnit
,
sourceLocation
,
name
);
...
...
@@ -713,6 +720,9 @@ Block *Control::newBlock(unsigned sourceLocation)
Declaration
*
Control
::
newDeclaration
(
unsigned
sourceLocation
,
const
Name
*
name
)
{
return
d
->
newDeclaration
(
sourceLocation
,
name
);
}
EnumeratorDeclaration
*
Control
::
newEnumeratorDeclaration
(
unsigned
sourceLocation
,
const
Name
*
name
)
{
return
d
->
newEnumeratorDeclaration
(
sourceLocation
,
name
);
}
UsingNamespaceDirective
*
Control
::
newUsingNamespaceDirective
(
unsigned
sourceLocation
,
const
Name
*
name
)
{
return
d
->
newUsingNamespaceDirective
(
sourceLocation
,
name
);
}
...
...
src/shared/cplusplus/Control.h
View file @
908d73f0
...
...
@@ -129,6 +129,9 @@ public:
/// Creates a new Declaration symbol.
Declaration
*
newDeclaration
(
unsigned
sourceLocation
,
const
Name
*
name
);
/// Creates a new EnumeratorDeclaration symbol.
EnumeratorDeclaration
*
newEnumeratorDeclaration
(
unsigned
sourceLocation
,
const
Name
*
name
);
/// Creates a new Argument symbol.
Argument
*
newArgument
(
unsigned
sourceLocation
,
const
Name
*
name
=
0
);
...
...
src/shared/cplusplus/Symbols.cpp
View file @
908d73f0
...
...
@@ -123,6 +123,20 @@ FullySpecifiedType Declaration::type() const
void
Declaration
::
visitSymbol0
(
SymbolVisitor
*
visitor
)
{
visitor
->
visit
(
this
);
}
EnumeratorDeclaration
::
EnumeratorDeclaration
(
TranslationUnit
*
translationUnit
,
unsigned
sourceLocation
,
const
Name
*
name
)
:
Declaration
(
translationUnit
,
sourceLocation
,
name
)
,
_constantValue
(
0
)
{}
EnumeratorDeclaration
::~
EnumeratorDeclaration
()
{}
const
StringLiteral
*
EnumeratorDeclaration
::
constantValue
()
const
{
return
_constantValue
;
}
void
EnumeratorDeclaration
::
setConstantValue
(
const
StringLiteral
*
constantValue
)
{
_constantValue
=
constantValue
;
}
Argument
::
Argument
(
TranslationUnit
*
translationUnit
,
unsigned
sourceLocation
,
const
Name
*
name
)
:
Symbol
(
translationUnit
,
sourceLocation
,
name
),
_initializer
(
0
)
...
...
src/shared/cplusplus/Symbols.h
View file @
908d73f0
...
...
@@ -141,6 +141,12 @@ public:
virtual
Declaration
*
asDeclaration
()
{
return
this
;
}
virtual
EnumeratorDeclaration
*
asEnumeratorDeclarator
()
{
return
0
;
}
virtual
const
EnumeratorDeclaration
*
asEnumeratorDeclarator
()
const
{
return
0
;
}
protected:
virtual
void
visitSymbol0
(
SymbolVisitor
*
visitor
);
...
...
@@ -148,6 +154,25 @@ private:
FullySpecifiedType
_type
;
};
class
CPLUSPLUS_EXPORT
EnumeratorDeclaration
:
public
Declaration
{
public:
EnumeratorDeclaration
(
TranslationUnit
*
translationUnit
,
unsigned
sourceLocation
,
const
Name
*
name
);
virtual
~
EnumeratorDeclaration
();
const
StringLiteral
*
constantValue
()
const
;
void
setConstantValue
(
const
StringLiteral
*
constantValue
);
virtual
EnumeratorDeclaration
*
asEnumeratorDeclarator
()
{
return
this
;
}
virtual
const
EnumeratorDeclaration
*
asEnumeratorDeclarator
()
const
{
return
this
;
}
private:
const
StringLiteral
*
_constantValue
;
};
class
CPLUSPLUS_EXPORT
Argument
:
public
Symbol
{
public:
...
...
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