Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
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
open-source
jadx
Commits
3ccab60f
Commit
3ccab60f
authored
Mar 09, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: remove redundant parenthesis for arithmetic operations
parent
ed64b8c1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
14 deletions
+53
-14
InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+11
-14
AttributeFlag.java
...src/main/java/jadx/core/dex/attributes/AttributeFlag.java
+1
-0
PrepareForCodeGen.java
...c/main/java/jadx/core/dex/visitors/PrepareForCodeGen.java
+34
-0
TestArith2.java
...e/src/test/java/jadx/tests/internal/arith/TestArith2.java
+7
-0
No files found.
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
View file @
3ccab60f
...
...
@@ -720,22 +720,19 @@ public class InsnGen {
}
private
void
makeArith
(
ArithNode
insn
,
CodeWriter
code
,
EnumSet
<
Flags
>
state
)
throws
CodegenException
{
ArithOp
op
=
insn
.
getOp
();
if
(
state
.
contains
(
Flags
.
BODY_ONLY
))
{
// wrap insn in brackets for save correct operation order
// wrap insn in brackets for save correct operation order
boolean
wrap
=
state
.
contains
(
Flags
.
BODY_ONLY
)
&&
!
insn
.
getAttributes
().
contains
(
AttributeFlag
.
DONT_WRAP
);
if
(
wrap
)
{
code
.
add
(
'('
);
addArg
(
code
,
insn
.
getArg
(
0
));
code
.
add
(
' '
);
code
.
add
(
op
.
getSymbol
());
code
.
add
(
' '
);
addArg
(
code
,
insn
.
getArg
(
1
));
}
addArg
(
code
,
insn
.
getArg
(
0
));
code
.
add
(
' '
);
code
.
add
(
insn
.
getOp
().
getSymbol
());
code
.
add
(
' '
);
addArg
(
code
,
insn
.
getArg
(
1
));
if
(
wrap
)
{
code
.
add
(
')'
);
}
else
{
addArg
(
code
,
insn
.
getArg
(
0
));
code
.
add
(
' '
);
code
.
add
(
op
.
getSymbol
());
code
.
add
(
' '
);
addArg
(
code
,
insn
.
getArg
(
1
));
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/attributes/AttributeFlag.java
View file @
3ccab60f
...
...
@@ -13,6 +13,7 @@ public enum AttributeFlag {
RETURN
,
// block contains only return instruction
DECLARE_VAR
,
DONT_WRAP
,
DONT_SHRINK
,
DONT_GENERATE
,
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/PrepareForCodeGen.java
View file @
3ccab60f
package
jadx
.
core
.
dex
.
visitors
;
import
jadx.core.dex.attributes.AttributeFlag
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.ArithOp
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.InsnWrapArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.mods.ConstructorInsn
;
import
jadx.core.dex.nodes.BlockNode
;
...
...
@@ -23,6 +26,7 @@ public class PrepareForCodeGen extends AbstractVisitor {
}
for
(
BlockNode
block
:
blocks
)
{
removeInstructions
(
block
);
removeBrackets
(
block
);
modifyArith
(
block
);
}
}
...
...
@@ -48,6 +52,36 @@ public class PrepareForCodeGen extends AbstractVisitor {
}
}
private
static
void
removeBrackets
(
BlockNode
block
)
{
for
(
InsnNode
insn
:
block
.
getInstructions
())
{
checkInsn
(
insn
);
}
}
private
static
void
checkInsn
(
InsnNode
insn
)
{
if
(
insn
.
getType
()
==
InsnType
.
ARITH
)
{
ArithNode
arith
=
(
ArithNode
)
insn
;
ArithOp
op
=
arith
.
getOp
();
if
(
op
==
ArithOp
.
ADD
||
op
==
ArithOp
.
SUB
)
{
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
InsnArg
arg
=
arith
.
getArg
(
i
);
if
(
arg
.
isInsnWrap
())
{
InsnNode
wrapInsn
=
((
InsnWrapArg
)
arg
).
getWrapInsn
();
wrapInsn
.
getAttributes
().
add
(
AttributeFlag
.
DONT_WRAP
);
checkInsn
(
wrapInsn
);
}
}
}
}
else
{
for
(
InsnArg
arg
:
insn
.
getArguments
())
{
if
(
arg
.
isInsnWrap
())
{
InsnNode
wrapInsn
=
((
InsnWrapArg
)
arg
).
getWrapInsn
();
checkInsn
(
wrapInsn
);
}
}
}
}
private
static
void
modifyArith
(
BlockNode
block
)
{
List
<
InsnNode
>
list
=
block
.
getInstructions
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
...
...
jadx-core/src/test/java/jadx/tests/internal/arith/TestArith2.java
View file @
3ccab60f
...
...
@@ -16,6 +16,10 @@ public class TestArith2 extends InternalJadxTest {
public
int
test1
(
int
a
)
{
return
(
a
+
2
)
*
3
;
}
public
int
test2
(
int
a
,
int
b
,
int
c
)
{
return
a
+
b
+
c
;
}
}
@Test
...
...
@@ -26,5 +30,8 @@ public class TestArith2 extends InternalJadxTest {
assertThat
(
code
,
containsString
(
"return (a + 2) * 3;"
));
assertThat
(
code
,
not
(
containsString
(
"a + 2 * 3"
)));
assertThat
(
code
,
containsString
(
"return a + b + c;"
));
assertThat
(
code
,
not
(
containsString
(
"return (a + b) + c;"
)));
}
}
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