mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-09-08 17:54:40 +00:00
Prepared parser for inline word expressions.
This commit is contained in:
parent
10b8431833
commit
eb6ee9bff8
@ -159,9 +159,10 @@ public class AsmFragmentSignature {
|
|||||||
ControlFlowBlock destinationBlock = graph.getBlock(destination);
|
ControlFlowBlock destinationBlock = graph.getBlock(destination);
|
||||||
String destinationLabel;
|
String destinationLabel;
|
||||||
if (destinationBlock.hasPhiBlock()) {
|
if (destinationBlock.hasPhiBlock()) {
|
||||||
destinationLabel = (destinationBlock.getLabel().getLocalName() + "_from_" + block.getLabel().getLocalName()).replace(
|
destinationLabel =
|
||||||
'@',
|
(destinationBlock.getLabel().getLocalName() +
|
||||||
'b').replace(':', '_');
|
"_from_" +
|
||||||
|
block.getLabel().getLocalName()).replace('@', 'b').replace(':', '_');
|
||||||
} else {
|
} else {
|
||||||
destinationLabel = destination.getLocalName();
|
destinationLabel = destination.getLocalName();
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ parameterDecl
|
|||||||
: typeDecl NAME ;
|
: typeDecl NAME ;
|
||||||
|
|
||||||
declVar
|
declVar
|
||||||
: ('const')? typeDecl NAME ('=' initializer)? ';'
|
: ('const')? typeDecl NAME ('=' expr)? ';'
|
||||||
;
|
;
|
||||||
|
|
||||||
stmtSeq
|
stmtSeq
|
||||||
@ -54,7 +54,7 @@ stmt
|
|||||||
;
|
;
|
||||||
|
|
||||||
forDeclaration
|
forDeclaration
|
||||||
: typeDecl? NAME ('=' initializer)? #forDecl
|
: typeDecl? NAME ('=' expr)? #forDecl
|
||||||
;
|
;
|
||||||
|
|
||||||
forIteration
|
forIteration
|
||||||
@ -69,11 +69,6 @@ typeDecl
|
|||||||
| typeDecl '[' (expr)? ']' #typeArray
|
| typeDecl '[' (expr)? ']' #typeArray
|
||||||
;
|
;
|
||||||
|
|
||||||
initializer
|
|
||||||
: expr #initExpr
|
|
||||||
| '{' initializer (',' initializer )* '}' #initList
|
|
||||||
;
|
|
||||||
|
|
||||||
lvalue
|
lvalue
|
||||||
: NAME #lvalueName
|
: NAME #lvalueName
|
||||||
| '*' NAME #lvaluePtr
|
| '*' NAME #lvaluePtr
|
||||||
@ -99,6 +94,7 @@ expr
|
|||||||
| expr ( '|' ) expr #exprBinary
|
| expr ( '|' ) expr #exprBinary
|
||||||
| expr ( '&&' ) expr #exprBinary
|
| expr ( '&&' ) expr #exprBinary
|
||||||
| expr ( '||' ) expr #exprBinary
|
| expr ( '||' ) expr #exprBinary
|
||||||
|
| '{' expr (',' expr )* '}' #initList
|
||||||
| NAME #exprId
|
| NAME #exprId
|
||||||
| NUMBER #exprNumber
|
| NUMBER #exprNumber
|
||||||
| STRING #exprString
|
| STRING #exprString
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from /Users/jespergravgaard/c64/src/kickc/src/main/java/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
|
// Generated from C:/c64/src/kickc/src/main/java/dk/camelot64/kickc/parser\KickC.g4 by ANTLR 4.7
|
||||||
package dk.camelot64.kickc.parser;
|
package dk.camelot64.kickc.parser;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.ParserRuleContext;
|
import org.antlr.v4.runtime.ParserRuleContext;
|
||||||
@ -347,30 +347,6 @@ public class KickCBaseListener implements KickCListener {
|
|||||||
* <p>The default implementation does nothing.</p>
|
* <p>The default implementation does nothing.</p>
|
||||||
*/
|
*/
|
||||||
@Override public void exitTypeSignedSimple(KickCParser.TypeSignedSimpleContext ctx) { }
|
@Override public void exitTypeSignedSimple(KickCParser.TypeSignedSimpleContext ctx) { }
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* <p>The default implementation does nothing.</p>
|
|
||||||
*/
|
|
||||||
@Override public void enterInitExpr(KickCParser.InitExprContext ctx) { }
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* <p>The default implementation does nothing.</p>
|
|
||||||
*/
|
|
||||||
@Override public void exitInitExpr(KickCParser.InitExprContext ctx) { }
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* <p>The default implementation does nothing.</p>
|
|
||||||
*/
|
|
||||||
@Override public void enterInitList(KickCParser.InitListContext ctx) { }
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* <p>The default implementation does nothing.</p>
|
|
||||||
*/
|
|
||||||
@Override public void exitInitList(KickCParser.InitListContext ctx) { }
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
@ -503,6 +479,18 @@ public class KickCBaseListener implements KickCListener {
|
|||||||
* <p>The default implementation does nothing.</p>
|
* <p>The default implementation does nothing.</p>
|
||||||
*/
|
*/
|
||||||
@Override public void exitExprChar(KickCParser.ExprCharContext ctx) { }
|
@Override public void exitExprChar(KickCParser.ExprCharContext ctx) { }
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p>The default implementation does nothing.</p>
|
||||||
|
*/
|
||||||
|
@Override public void enterInitList(KickCParser.InitListContext ctx) { }
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p>The default implementation does nothing.</p>
|
||||||
|
*/
|
||||||
|
@Override public void exitInitList(KickCParser.InitListContext ctx) { }
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from /Users/jespergravgaard/c64/src/kickc/src/main/java/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
|
// Generated from C:/c64/src/kickc/src/main/java/dk/camelot64/kickc/parser\KickC.g4 by ANTLR 4.7
|
||||||
package dk.camelot64.kickc.parser;
|
package dk.camelot64.kickc.parser;
|
||||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||||
|
|
||||||
@ -207,20 +207,6 @@ public class KickCBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements
|
|||||||
* {@link #visitChildren} on {@code ctx}.</p>
|
* {@link #visitChildren} on {@code ctx}.</p>
|
||||||
*/
|
*/
|
||||||
@Override public T visitTypeSignedSimple(KickCParser.TypeSignedSimpleContext ctx) { return visitChildren(ctx); }
|
@Override public T visitTypeSignedSimple(KickCParser.TypeSignedSimpleContext ctx) { return visitChildren(ctx); }
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* <p>The default implementation returns the result of calling
|
|
||||||
* {@link #visitChildren} on {@code ctx}.</p>
|
|
||||||
*/
|
|
||||||
@Override public T visitInitExpr(KickCParser.InitExprContext ctx) { return visitChildren(ctx); }
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* <p>The default implementation returns the result of calling
|
|
||||||
* {@link #visitChildren} on {@code ctx}.</p>
|
|
||||||
*/
|
|
||||||
@Override public T visitInitList(KickCParser.InitListContext ctx) { return visitChildren(ctx); }
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
@ -298,6 +284,13 @@ public class KickCBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements
|
|||||||
* {@link #visitChildren} on {@code ctx}.</p>
|
* {@link #visitChildren} on {@code ctx}.</p>
|
||||||
*/
|
*/
|
||||||
@Override public T visitExprChar(KickCParser.ExprCharContext ctx) { return visitChildren(ctx); }
|
@Override public T visitExprChar(KickCParser.ExprCharContext ctx) { return visitChildren(ctx); }
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p>The default implementation returns the result of calling
|
||||||
|
* {@link #visitChildren} on {@code ctx}.</p>
|
||||||
|
*/
|
||||||
|
@Override public T visitInitList(KickCParser.InitListContext ctx) { return visitChildren(ctx); }
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from /Users/jespergravgaard/c64/src/kickc/src/main/java/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
|
// Generated from C:/c64/src/kickc/src/main/java/dk/camelot64/kickc/parser\KickC.g4 by ANTLR 4.7
|
||||||
package dk.camelot64.kickc.parser;
|
package dk.camelot64.kickc.parser;
|
||||||
import org.antlr.v4.runtime.Lexer;
|
import org.antlr.v4.runtime.Lexer;
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import org.antlr.v4.runtime.CharStream;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from /Users/jespergravgaard/c64/src/kickc/src/main/java/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
|
// Generated from C:/c64/src/kickc/src/main/java/dk/camelot64/kickc/parser\KickC.g4 by ANTLR 4.7
|
||||||
package dk.camelot64.kickc.parser;
|
package dk.camelot64.kickc.parser;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||||
|
|
||||||
@ -325,30 +325,6 @@ public interface KickCListener extends ParseTreeListener {
|
|||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
*/
|
*/
|
||||||
void exitTypeSignedSimple(KickCParser.TypeSignedSimpleContext ctx);
|
void exitTypeSignedSimple(KickCParser.TypeSignedSimpleContext ctx);
|
||||||
/**
|
|
||||||
* Enter a parse tree produced by the {@code initExpr}
|
|
||||||
* labeled alternative in {@link KickCParser#initializer}.
|
|
||||||
* @param ctx the parse tree
|
|
||||||
*/
|
|
||||||
void enterInitExpr(KickCParser.InitExprContext ctx);
|
|
||||||
/**
|
|
||||||
* Exit a parse tree produced by the {@code initExpr}
|
|
||||||
* labeled alternative in {@link KickCParser#initializer}.
|
|
||||||
* @param ctx the parse tree
|
|
||||||
*/
|
|
||||||
void exitInitExpr(KickCParser.InitExprContext ctx);
|
|
||||||
/**
|
|
||||||
* Enter a parse tree produced by the {@code initList}
|
|
||||||
* labeled alternative in {@link KickCParser#initializer}.
|
|
||||||
* @param ctx the parse tree
|
|
||||||
*/
|
|
||||||
void enterInitList(KickCParser.InitListContext ctx);
|
|
||||||
/**
|
|
||||||
* Exit a parse tree produced by the {@code initList}
|
|
||||||
* labeled alternative in {@link KickCParser#initializer}.
|
|
||||||
* @param ctx the parse tree
|
|
||||||
*/
|
|
||||||
void exitInitList(KickCParser.InitListContext ctx);
|
|
||||||
/**
|
/**
|
||||||
* Enter a parse tree produced by the {@code lvalueName}
|
* Enter a parse tree produced by the {@code lvalueName}
|
||||||
* labeled alternative in {@link KickCParser#lvalue}.
|
* labeled alternative in {@link KickCParser#lvalue}.
|
||||||
@ -481,6 +457,18 @@ public interface KickCListener extends ParseTreeListener {
|
|||||||
* @param ctx the parse tree
|
* @param ctx the parse tree
|
||||||
*/
|
*/
|
||||||
void exitExprChar(KickCParser.ExprCharContext ctx);
|
void exitExprChar(KickCParser.ExprCharContext ctx);
|
||||||
|
/**
|
||||||
|
* Enter a parse tree produced by the {@code initList}
|
||||||
|
* labeled alternative in {@link KickCParser#expr}.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
void enterInitList(KickCParser.InitListContext ctx);
|
||||||
|
/**
|
||||||
|
* Exit a parse tree produced by the {@code initList}
|
||||||
|
* labeled alternative in {@link KickCParser#expr}.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
*/
|
||||||
|
void exitInitList(KickCParser.InitListContext ctx);
|
||||||
/**
|
/**
|
||||||
* Enter a parse tree produced by the {@code exprCast}
|
* Enter a parse tree produced by the {@code exprCast}
|
||||||
* labeled alternative in {@link KickCParser#expr}.
|
* labeled alternative in {@link KickCParser#expr}.
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
|||||||
// Generated from /Users/jespergravgaard/c64/src/kickc/src/main/java/dk/camelot64/kickc/parser/KickC.g4 by ANTLR 4.7
|
// Generated from C:/c64/src/kickc/src/main/java/dk/camelot64/kickc/parser\KickC.g4 by ANTLR 4.7
|
||||||
package dk.camelot64.kickc.parser;
|
package dk.camelot64.kickc.parser;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||||
|
|
||||||
@ -197,20 +197,6 @@ public interface KickCVisitor<T> extends ParseTreeVisitor<T> {
|
|||||||
* @return the visitor result
|
* @return the visitor result
|
||||||
*/
|
*/
|
||||||
T visitTypeSignedSimple(KickCParser.TypeSignedSimpleContext ctx);
|
T visitTypeSignedSimple(KickCParser.TypeSignedSimpleContext ctx);
|
||||||
/**
|
|
||||||
* Visit a parse tree produced by the {@code initExpr}
|
|
||||||
* labeled alternative in {@link KickCParser#initializer}.
|
|
||||||
* @param ctx the parse tree
|
|
||||||
* @return the visitor result
|
|
||||||
*/
|
|
||||||
T visitInitExpr(KickCParser.InitExprContext ctx);
|
|
||||||
/**
|
|
||||||
* Visit a parse tree produced by the {@code initList}
|
|
||||||
* labeled alternative in {@link KickCParser#initializer}.
|
|
||||||
* @param ctx the parse tree
|
|
||||||
* @return the visitor result
|
|
||||||
*/
|
|
||||||
T visitInitList(KickCParser.InitListContext ctx);
|
|
||||||
/**
|
/**
|
||||||
* Visit a parse tree produced by the {@code lvalueName}
|
* Visit a parse tree produced by the {@code lvalueName}
|
||||||
* labeled alternative in {@link KickCParser#lvalue}.
|
* labeled alternative in {@link KickCParser#lvalue}.
|
||||||
@ -288,6 +274,13 @@ public interface KickCVisitor<T> extends ParseTreeVisitor<T> {
|
|||||||
* @return the visitor result
|
* @return the visitor result
|
||||||
*/
|
*/
|
||||||
T visitExprChar(KickCParser.ExprCharContext ctx);
|
T visitExprChar(KickCParser.ExprCharContext ctx);
|
||||||
|
/**
|
||||||
|
* Visit a parse tree produced by the {@code initList}
|
||||||
|
* labeled alternative in {@link KickCParser#expr}.
|
||||||
|
* @param ctx the parse tree
|
||||||
|
* @return the visitor result
|
||||||
|
*/
|
||||||
|
T visitInitList(KickCParser.InitListContext ctx);
|
||||||
/**
|
/**
|
||||||
* Visit a parse tree produced by the {@code exprCast}
|
* Visit a parse tree produced by the {@code exprCast}
|
||||||
* labeled alternative in {@link KickCParser#expr}.
|
* labeled alternative in {@link KickCParser#expr}.
|
||||||
|
@ -64,11 +64,6 @@ public class ParseTreeConstantEvaluator extends KickCBaseVisitor<ConstantValue>
|
|||||||
throw new NotConstantException();
|
throw new NotConstantException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConstantValue visitInitExpr(KickCParser.InitExprContext ctx) {
|
|
||||||
return visit(ctx.expr());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConstantValue visitInitList(KickCParser.InitListContext ctx) {
|
public ConstantValue visitInitList(KickCParser.InitListContext ctx) {
|
||||||
throw new NotConstantException();
|
throw new NotConstantException();
|
||||||
|
@ -138,11 +138,11 @@ public class StatementSequenceGenerator extends KickCBaseVisitor<Object> {
|
|||||||
public Object visitDeclVar(KickCParser.DeclVarContext ctx) {
|
public Object visitDeclVar(KickCParser.DeclVarContext ctx) {
|
||||||
SymbolType type = (SymbolType) visit(ctx.typeDecl());
|
SymbolType type = (SymbolType) visit(ctx.typeDecl());
|
||||||
String varName = ctx.NAME().getText();
|
String varName = ctx.NAME().getText();
|
||||||
KickCParser.InitializerContext initializer = ctx.initializer();
|
|
||||||
VariableUnversioned lValue = getCurrentSymbols().addVariable(varName, type);
|
VariableUnversioned lValue = getCurrentSymbols().addVariable(varName, type);
|
||||||
if (ctx.getChild(0).getText().equals("const")) {
|
if (ctx.getChild(0).getText().equals("const")) {
|
||||||
lValue.setDeclaredConstant(true);
|
lValue.setDeclaredConstant(true);
|
||||||
}
|
}
|
||||||
|
KickCParser.ExprContext initializer = ctx.expr();
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
addInitialAssignment(initializer, lValue);
|
addInitialAssignment(initializer, lValue);
|
||||||
}
|
}
|
||||||
@ -269,7 +269,7 @@ public class StatementSequenceGenerator extends KickCBaseVisitor<Object> {
|
|||||||
} else {
|
} else {
|
||||||
lValue = getCurrentSymbols().getVariable(varName);
|
lValue = getCurrentSymbols().getVariable(varName);
|
||||||
}
|
}
|
||||||
KickCParser.InitializerContext initializer = forDeclCtx.initializer();
|
KickCParser.ExprContext initializer = forDeclCtx.expr();
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
addInitialAssignment(initializer, lValue);
|
addInitialAssignment(initializer, lValue);
|
||||||
}
|
}
|
||||||
@ -388,7 +388,7 @@ public class StatementSequenceGenerator extends KickCBaseVisitor<Object> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addInitialAssignment(KickCParser.InitializerContext initializer, Variable lValue) {
|
private void addInitialAssignment(KickCParser.ExprContext initializer, Variable lValue) {
|
||||||
PrePostModifierHandler.addPreModifiers(this, initializer);
|
PrePostModifierHandler.addPreModifiers(this, initializer);
|
||||||
RValue rValue = (RValue) visit(initializer);
|
RValue rValue = (RValue) visit(initializer);
|
||||||
Statement stmt = new StatementAssignment(lValue, rValue);
|
Statement stmt = new StatementAssignment(lValue, rValue);
|
||||||
@ -448,15 +448,10 @@ public class StatementSequenceGenerator extends KickCBaseVisitor<Object> {
|
|||||||
return new PointerDereferenceIndexed(lval, index);
|
return new PointerDereferenceIndexed(lval, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public RValue visitInitExpr(KickCParser.InitExprContext ctx) {
|
|
||||||
return (RValue) visit(ctx.expr());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RValue visitInitList(KickCParser.InitListContext ctx) {
|
public RValue visitInitList(KickCParser.InitListContext ctx) {
|
||||||
List<RValue> initValues = new ArrayList<>();
|
List<RValue> initValues = new ArrayList<>();
|
||||||
for (KickCParser.InitializerContext initializer : ctx.initializer()) {
|
for (KickCParser.ExprContext initializer : ctx.expr()) {
|
||||||
RValue rValue = (RValue) visit(initializer);
|
RValue rValue = (RValue) visit(initializer);
|
||||||
initValues.add(rValue);
|
initValues.add(rValue);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user