Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
56e13ae0
Commit
56e13ae0
authored
Jan 31, 2014
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compiler: Use backend interface for conditional expressions.
From-SVN: r207330
parent
8fec1e9b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
1 deletions
+103
-1
gcc/go/gofrontend/expressions.cc
+97
-0
gcc/go/gofrontend/expressions.h
+6
-1
No files found.
gcc/go/gofrontend/expressions.cc
View file @
56e13ae0
...
@@ -15040,6 +15040,103 @@ Expression::make_label_addr(Label* label, Location location)
...
@@ -15040,6 +15040,103 @@ Expression::make_label_addr(Label* label, Location location)
return
new
Label_addr_expression
(
label
,
location
);
return
new
Label_addr_expression
(
label
,
location
);
}
}
// Conditional expressions.
class
Conditional_expression
:
public
Expression
{
public
:
Conditional_expression
(
Expression
*
cond
,
Expression
*
then_expr
,
Expression
*
else_expr
,
Location
location
)
:
Expression
(
EXPRESSION_CONDITIONAL
,
location
),
cond_
(
cond
),
then_
(
then_expr
),
else_
(
else_expr
)
{}
protected
:
Type
*
do_type
();
void
do_determine_type
(
const
Type_context
*
)
{
}
Expression
*
do_copy
()
{
return
new
Conditional_expression
(
this
->
cond_
->
copy
(),
this
->
then_
->
copy
(),
this
->
else_
->
copy
(),
this
->
location
());
}
tree
do_get_tree
(
Translate_context
*
context
);
void
do_dump_expression
(
Ast_dump_context
*
)
const
;
private
:
// The condition to be checked.
Expression
*
cond_
;
// The expression to execute if the condition is true.
Expression
*
then_
;
// The expression to execute if the condition is false.
Expression
*
else_
;
};
// Return the type of the conditional expression.
Type
*
Conditional_expression
::
do_type
()
{
Type
*
result_type
=
Type
::
make_void_type
();
if
(
this
->
then_
->
type
()
==
this
->
else_
->
type
())
result_type
=
this
->
then_
->
type
();
else
if
(
this
->
then_
->
is_nil_expression
()
||
this
->
else_
->
is_nil_expression
())
result_type
=
(
!
this
->
then_
->
is_nil_expression
()
?
this
->
then_
->
type
()
:
this
->
else_
->
type
());
return
result_type
;
}
// Get the backend representation of a conditional expression.
tree
Conditional_expression
::
do_get_tree
(
Translate_context
*
context
)
{
Gogo
*
gogo
=
context
->
gogo
();
Btype
*
result_btype
=
this
->
type
()
->
get_backend
(
gogo
);
Bexpression
*
cond
=
tree_to_expr
(
this
->
cond_
->
get_tree
(
context
));
Bexpression
*
then
=
tree_to_expr
(
this
->
then_
->
get_tree
(
context
));
Bexpression
*
belse
=
tree_to_expr
(
this
->
else_
->
get_tree
(
context
));
Bexpression
*
ret
=
gogo
->
backend
()
->
conditional_expression
(
result_btype
,
cond
,
then
,
belse
,
this
->
location
());
return
expr_to_tree
(
ret
);
}
// Dump ast representation of a conditional expression.
void
Conditional_expression
::
do_dump_expression
(
Ast_dump_context
*
ast_dump_context
)
const
{
ast_dump_context
->
ostream
()
<<
"("
;
ast_dump_context
->
dump_expression
(
this
->
cond_
);
ast_dump_context
->
ostream
()
<<
" ? "
;
ast_dump_context
->
dump_expression
(
this
->
then_
);
ast_dump_context
->
ostream
()
<<
" : "
;
ast_dump_context
->
dump_expression
(
this
->
else_
);
ast_dump_context
->
ostream
()
<<
") "
;
}
// Make a conditional expression.
Expression
*
Expression
::
make_conditional
(
Expression
*
cond
,
Expression
*
then
,
Expression
*
else_expr
,
Location
location
)
{
return
new
Conditional_expression
(
cond
,
then
,
else_expr
,
location
);
}
// Import an expression. This comes at the end in order to see the
// Import an expression. This comes at the end in order to see the
// various class definitions.
// various class definitions.
...
...
gcc/go/gofrontend/expressions.h
View file @
56e13ae0
...
@@ -106,7 +106,8 @@ class Expression
...
@@ -106,7 +106,8 @@ class Expression
EXPRESSION_INTERFACE_INFO
,
EXPRESSION_INTERFACE_INFO
,
EXPRESSION_STRUCT_FIELD_OFFSET
,
EXPRESSION_STRUCT_FIELD_OFFSET
,
EXPRESSION_MAP_DESCRIPTOR
,
EXPRESSION_MAP_DESCRIPTOR
,
EXPRESSION_LABEL_ADDR
EXPRESSION_LABEL_ADDR
,
EXPRESSION_CONDITIONAL
};
};
Expression
(
Expression_classification
,
Location
);
Expression
(
Expression_classification
,
Location
);
...
@@ -388,6 +389,10 @@ class Expression
...
@@ -388,6 +389,10 @@ class Expression
static
Expression
*
static
Expression
*
make_label_addr
(
Label
*
,
Location
);
make_label_addr
(
Label
*
,
Location
);
// Make a conditional expression.
static
Expression
*
make_conditional
(
Expression
*
,
Expression
*
,
Expression
*
,
Location
);
// Return the expression classification.
// Return the expression classification.
Expression_classification
Expression_classification
classification
()
const
classification
()
const
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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