Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SableCC STUPS
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
SableCC STUPS
Commits
6ffadb8a
Commit
6ffadb8a
authored
Jul 20, 2023
by
dgelessus
Browse files
Options
Downloads
Patches
Plain Diff
Refactor generating variable declarations in alternative codegen
parent
c0911fb8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java
+30
-75
30 additions, 75 deletions
...org/sablecc/sablecc/GenerateAlternativeCodeForParser.java
with
30 additions
and
75 deletions
src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java
+
30
−
75
View file @
6ffadb8a
...
...
@@ -64,40 +64,41 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
popCount
++;
}
@Override
public
void
inAAltTransform
(
AAltTransform
node
)
{
String
type_name
;
int
position
;
for
(
PTerm
term
:
node
.
getTerms
())
{
private
void
generateVariableDeclaration
(
Node
term
)
throws
IOException
{
String
typeName
;
if
(
simpleTermTransformMap
.
get
(
term
)
!=
null
)
{
type
_n
ame
=
simpleTermTransformMap
.
get
(
term
);
type
N
ame
=
simpleTermTransformMap
.
get
(
term
);
}
else
{
type
_n
ame
=
CG
.
getAltTransformElemTypes
().
get
(
term
);
type
N
ame
=
CG
.
getAltTransformElemTypes
().
get
(
term
);
}
int
position
=
CG
.
getTermNumbers
().
get
(
term
);
position
=
CG
.
getTermNumbers
().
get
(
term
);
try
{
if
(
type_name
.
startsWith
(
"L"
))
if
(
typeName
.
startsWith
(
"L"
))
{
macros
.
apply
(
file
,
"ParserListVariableDeclaration"
,
new
String
[]
{
""
+
position
});
}
else
if
(
type
_n
ame
.
equals
(
"null"
))
else
if
(
type
N
ame
.
equals
(
"null"
))
{
// No intermediate variable needed for null arguments
}
else
{
macros
.
apply
(
file
,
"ParserSimpleVariableDeclaration"
,
new
String
[]
{
type
_n
ame
,
type
_n
ame
.
toLowerCase
(),
""
+
position
});
macros
.
apply
(
file
,
"ParserSimpleVariableDeclaration"
,
new
String
[]
{
type
N
ame
,
type
N
ame
.
toLowerCase
(),
""
+
position
});
}
}
@Override
public
void
inAAltTransform
(
AAltTransform
node
)
{
for
(
PTerm
term
:
node
.
getTerms
())
{
try
{
generateVariableDeclaration
(
term
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"An error occured while writing to "
+
...
...
@@ -157,35 +158,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
public
void
inAParams
(
List
<
PTerm
>
list_param
)
{
String
type_name
;
int
position
;
for
(
PTerm
term
:
list_param
)
{
if
(
simpleTermTransformMap
.
get
(
term
)
!=
null
)
{
type_name
=
simpleTermTransformMap
.
get
(
term
);
}
else
{
type_name
=
CG
.
getAltTransformElemTypes
().
get
(
term
);
}
position
=
CG
.
getTermNumbers
().
get
(
term
);
try
{
if
(
type_name
.
startsWith
(
"L"
))
{
macros
.
apply
(
file
,
"ParserListVariableDeclaration"
,
new
String
[]
{
""
+
position
});
}
else
if
(
type_name
.
equals
(
"null"
))
{
// No intermediate variable needed for null arguments
}
else
{
macros
.
apply
(
file
,
"ParserSimpleVariableDeclaration"
,
new
String
[]
{
type_name
,
type_name
.
toLowerCase
(),
""
+
position
});
}
generateVariableDeclaration
(
term
);
}
catch
(
IOException
e
)
{
...
...
@@ -380,31 +357,9 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
try
{
macros
.
apply
(
file
,
"ParserBraceOpening"
);
for
(
PListTerm
listTerm
:
node
.
getListTerms
())
{
String
type_name
;
if
(
simpleTermTransformMap
.
get
(
listTerm
)
!=
null
)
{
type_name
=
simpleTermTransformMap
.
get
(
listTerm
);
}
else
{
type_name
=
CG
.
getAltTransformElemTypes
().
get
(
listTerm
);
}
int
position
=
CG
.
getTermNumbers
().
get
(
listTerm
);
if
(
type_name
.
startsWith
(
"L"
))
for
(
Node
term
:
node
.
getListTerms
())
{
macros
.
apply
(
file
,
"ParserListVariableDeclaration"
,
new
String
[]
{
""
+
position
});
}
else
if
(
type_name
.
equals
(
"null"
))
{
// No intermediate variable needed for null arguments
}
else
{
macros
.
apply
(
file
,
"ParserSimpleVariableDeclaration"
,
new
String
[]
{
type_name
,
type_name
.
toLowerCase
(),
""
+
position
});
}
generateVariableDeclaration
(
term
);
}
}
catch
(
IOException
e
)
...
...
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