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
69faf7cc
Commit
69faf7cc
authored
1 year ago
by
dgelessus
Browse files
Options
Downloads
Patches
Plain Diff
Simplify variable name creation in alternative code generation
parent
bc72a662
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
+13
-25
13 additions, 25 deletions
...org/sablecc/sablecc/GenerateAlternativeCodeForParser.java
with
13 additions
and
25 deletions
src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java
+
13
−
25
View file @
69faf7cc
...
@@ -92,6 +92,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
...
@@ -92,6 +92,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
}
}
}
}
private
String
getVariableName
(
Node
term
)
{
return
getVariableName
(
lookupInternalTypeName
(
term
),
CG
.
getTermNumbers
().
get
(
term
));
}
private
static
String
variableTypeFromInternalType
(
String
typeName
)
private
static
String
variableTypeFromInternalType
(
String
typeName
)
{
{
if
(
"null"
.
equals
(
typeName
))
if
(
"null"
.
equals
(
typeName
))
...
@@ -110,11 +115,10 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
...
@@ -110,11 +115,10 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
private
void
generateVariableDeclaration
(
Node
term
)
throws
IOException
{
private
void
generateVariableDeclaration
(
Node
term
)
throws
IOException
{
String
typeName
=
lookupInternalTypeName
(
term
);
String
typeName
=
lookupInternalTypeName
(
term
);
int
position
=
CG
.
getTermNumbers
().
get
(
term
);
if
(
typeName
.
startsWith
(
"L"
))
if
(
typeName
.
startsWith
(
"L"
))
{
{
macros
.
apply
(
file
,
"ParserListVariableDeclaration"
,
new
String
[]
{
getVariableName
(
t
ypeName
,
position
)});
macros
.
apply
(
file
,
"ParserListVariableDeclaration"
,
new
String
[]
{
getVariableName
(
t
erm
)});
}
}
else
if
(
typeName
.
equals
(
"null"
))
else
if
(
typeName
.
equals
(
"null"
))
{
{
...
@@ -122,7 +126,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
...
@@ -122,7 +126,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
}
}
else
else
{
{
macros
.
apply
(
file
,
"ParserSimpleVariableDeclaration"
,
new
String
[]
{
typeName
,
getVariableName
(
t
ypeName
,
position
)});
macros
.
apply
(
file
,
"ParserSimpleVariableDeclaration"
,
new
String
[]
{
typeName
,
getVariableName
(
t
erm
)});
}
}
}
}
...
@@ -146,17 +150,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
...
@@ -146,17 +150,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
@Override
@Override
public
void
outAAltTransform
(
AAltTransform
node
)
public
void
outAAltTransform
(
AAltTransform
node
)
{
{
int
position
;
try
try
{
{
for
(
PTerm
term
:
node
.
getTerms
())
for
(
PTerm
term
:
node
.
getTerms
())
{
{
String
type_name
=
lookupInternalTypeName
(
term
);
macros
.
apply
(
file
,
"ParserNewBodyListAdd"
,
new
String
[]
{
getVariableName
(
term
)});
position
=
CG
.
getTermNumbers
().
get
(
term
);
macros
.
apply
(
file
,
"ParserNewBodyListAdd"
,
new
String
[]
{
getVariableName
(
type_name
,
position
)});
}
}
if
(
popCount
>
0
)
{
if
(
popCount
>
0
)
{
// The nodeArrayList variables are numbered starting at 1, so the first popped variable has the number popCount and not popCount-1.
// The nodeArrayList variables are numbered starting at 1, so the first popped variable has the number popCount and not popCount-1.
...
@@ -193,7 +191,6 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
...
@@ -193,7 +191,6 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
try
try
{
{
String
type_name
=
lookupInternalTypeName
(
node
);
String
type_name
=
lookupInternalTypeName
(
node
);
int
position
=
CG
.
getTermNumbers
().
get
(
node
).
intValue
();
String
termKey
=
currentAlt
+
"."
+
id
.
getText
();
String
termKey
=
currentAlt
+
"."
+
id
.
getText
();
int
elemPosition
=
CTP
.
elems_position
.
get
(
termKey
);
int
elemPosition
=
CTP
.
elems_position
.
get
(
termKey
);
int
positionMap
=
0
;
int
positionMap
=
0
;
...
@@ -229,7 +226,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
...
@@ -229,7 +226,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
macros
.
apply
(
file
,
"ParserSimpleTerm"
,
new
String
[]
macros
.
apply
(
file
,
"ParserSimpleTerm"
,
new
String
[]
{
{
getVariableName
(
type_name
,
position
),
getVariableName
(
node
),
variableTypeFromInternalType
(
type_name
),
""
+
elemPosition
,
""
+
positionMap
variableTypeFromInternalType
(
type_name
),
""
+
elemPosition
,
""
+
positionMap
}
}
);
);
...
@@ -288,23 +285,19 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
...
@@ -288,23 +285,19 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
{
{
try
try
{
{
String
listTypeName
=
lookupInternalTypeName
(
node
);
int
listPosition
=
CG
.
getTermNumbers
().
get
(
node
);
for
(
PListTerm
listTerm
:
node
.
getListTerms
())
for
(
PListTerm
listTerm
:
node
.
getListTerms
())
{
{
String
type_name
=
lookupInternalTypeName
(
listTerm
);
String
type_name
=
lookupInternalTypeName
(
listTerm
);
int
position
=
CG
.
getTermNumbers
().
get
(
listTerm
);
if
(!
type_name
.
equals
(
"null"
))
if
(!
type_name
.
equals
(
"null"
))
{
{
if
(
type_name
.
startsWith
(
"L"
))
if
(
type_name
.
startsWith
(
"L"
))
{
{
macros
.
apply
(
file
,
"ParserTypedLinkedListAddAll"
,
new
String
[]
{
getVariableName
(
listTypeName
,
listPosition
),
getVariableName
(
type_name
,
position
)});
macros
.
apply
(
file
,
"ParserTypedLinkedListAddAll"
,
new
String
[]
{
getVariableName
(
node
),
getVariableName
(
listTerm
)});
}
}
else
else
{
{
macros
.
apply
(
file
,
"ParserTypedLinkedListAdd"
,
new
String
[]
{
getVariableName
(
listTypeName
,
listPosition
),
getVariableName
(
type_name
,
position
)});
macros
.
apply
(
file
,
"ParserTypedLinkedListAdd"
,
new
String
[]
{
getVariableName
(
node
),
getVariableName
(
listTerm
)});
}
}
}
}
}
}
...
@@ -319,13 +312,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
...
@@ -319,13 +312,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
private
void
generateNewTerm
(
Node
node
,
AProdName
prodName
,
List
<
PTerm
>
params
)
private
void
generateNewTerm
(
Node
node
,
AProdName
prodName
,
List
<
PTerm
>
params
)
{
{
String
type_name
=
lookupInternalTypeName
(
node
);
int
position
=
CG
.
getTermNumbers
().
get
(
node
);
String
newAltName
=
name
(
prodName
);
String
newAltName
=
name
(
prodName
);
try
try
{
{
macros
.
apply
(
file
,
"ParserNewBodyNew"
,
new
String
[]
{
getVariableName
(
type_name
,
position
),
newAltName
});
macros
.
apply
(
file
,
"ParserNewBodyNew"
,
new
String
[]
{
getVariableName
(
node
),
newAltName
});
if
(!
params
.
isEmpty
())
if
(!
params
.
isEmpty
())
{
{
...
@@ -333,10 +324,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
...
@@ -333,10 +324,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
for
(
PTerm
term
:
params
)
for
(
PTerm
term
:
params
)
{
{
type_name
=
lookupInternalTypeName
(
term
);
macros
.
apply
(
file
,
"ParserNewBodyParam"
,
new
String
[]
{
isNotTheFirstParam
+
getVariableName
(
term
)});
position
=
CG
.
getTermNumbers
().
get
(
term
);
macros
.
apply
(
file
,
"ParserNewBodyParam"
,
new
String
[]
{
isNotTheFirstParam
+
getVariableName
(
type_name
,
position
)});
isNotTheFirstParam
=
", "
;
isNotTheFirstParam
=
", "
;
}
}
...
...
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