1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-14 23:04:57 +00:00

Prepared parser for inline word expressions.

This commit is contained in:
Jesper Gravgaard 2017-12-23 15:35:13 +01:00
parent 10b8431833
commit eb6ee9bff8
10 changed files with 585 additions and 715 deletions

View File

@ -159,9 +159,10 @@ public class AsmFragmentSignature {
ControlFlowBlock destinationBlock = graph.getBlock(destination);
String destinationLabel;
if (destinationBlock.hasPhiBlock()) {
destinationLabel = (destinationBlock.getLabel().getLocalName() + "_from_" + block.getLabel().getLocalName()).replace(
'@',
'b').replace(':', '_');
destinationLabel =
(destinationBlock.getLabel().getLocalName() +
"_from_" +
block.getLabel().getLocalName()).replace('@', 'b').replace(':', '_');
} else {
destinationLabel = destination.getLocalName();
}

View File

@ -33,7 +33,7 @@ parameterDecl
: typeDecl NAME ;
declVar
: ('const')? typeDecl NAME ('=' initializer)? ';'
: ('const')? typeDecl NAME ('=' expr)? ';'
;
stmtSeq
@ -54,7 +54,7 @@ stmt
;
forDeclaration
: typeDecl? NAME ('=' initializer)? #forDecl
: typeDecl? NAME ('=' expr)? #forDecl
;
forIteration
@ -69,11 +69,6 @@ typeDecl
| typeDecl '[' (expr)? ']' #typeArray
;
initializer
: expr #initExpr
| '{' initializer (',' initializer )* '}' #initList
;
lvalue
: NAME #lvalueName
| '*' NAME #lvaluePtr
@ -99,6 +94,7 @@ expr
| expr ( '|' ) expr #exprBinary
| expr ( '&&' ) expr #exprBinary
| expr ( '||' ) expr #exprBinary
| '{' expr (',' expr )* '}' #initList
| NAME #exprId
| NUMBER #exprNumber
| STRING #exprString

View File

@ -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;
import org.antlr.v4.runtime.ParserRuleContext;
@ -347,30 +347,6 @@ public class KickCBaseListener implements KickCListener {
* <p>The default implementation does nothing.</p>
*/
@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}
*
@ -503,6 +479,18 @@ public class KickCBaseListener implements KickCListener {
* <p>The default implementation does nothing.</p>
*/
@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}
*

View File

@ -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;
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>
*/
@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}
*
@ -298,6 +284,13 @@ public class KickCBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements
* {@link #visitChildren} on {@code ctx}.</p>
*/
@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}
*

View File

@ -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;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;

View File

@ -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;
import org.antlr.v4.runtime.tree.ParseTreeListener;
@ -325,30 +325,6 @@ public interface KickCListener extends ParseTreeListener {
* @param ctx the parse tree
*/
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}
* labeled alternative in {@link KickCParser#lvalue}.
@ -481,6 +457,18 @@ public interface KickCListener extends ParseTreeListener {
* @param ctx the parse tree
*/
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}
* labeled alternative in {@link KickCParser#expr}.

File diff suppressed because it is too large Load Diff

View File

@ -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;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
@ -197,20 +197,6 @@ public interface KickCVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
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}
* labeled alternative in {@link KickCParser#lvalue}.
@ -288,6 +274,13 @@ public interface KickCVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
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}
* labeled alternative in {@link KickCParser#expr}.

View File

@ -64,11 +64,6 @@ public class ParseTreeConstantEvaluator extends KickCBaseVisitor<ConstantValue>
throw new NotConstantException();
}
@Override
public ConstantValue visitInitExpr(KickCParser.InitExprContext ctx) {
return visit(ctx.expr());
}
@Override
public ConstantValue visitInitList(KickCParser.InitListContext ctx) {
throw new NotConstantException();

View File

@ -138,11 +138,11 @@ public class StatementSequenceGenerator extends KickCBaseVisitor<Object> {
public Object visitDeclVar(KickCParser.DeclVarContext ctx) {
SymbolType type = (SymbolType) visit(ctx.typeDecl());
String varName = ctx.NAME().getText();
KickCParser.InitializerContext initializer = ctx.initializer();
VariableUnversioned lValue = getCurrentSymbols().addVariable(varName, type);
if (ctx.getChild(0).getText().equals("const")) {
lValue.setDeclaredConstant(true);
}
KickCParser.ExprContext initializer = ctx.expr();
if (initializer != null) {
addInitialAssignment(initializer, lValue);
}
@ -269,7 +269,7 @@ public class StatementSequenceGenerator extends KickCBaseVisitor<Object> {
} else {
lValue = getCurrentSymbols().getVariable(varName);
}
KickCParser.InitializerContext initializer = forDeclCtx.initializer();
KickCParser.ExprContext initializer = forDeclCtx.expr();
if (initializer != null) {
addInitialAssignment(initializer, lValue);
}
@ -388,7 +388,7 @@ public class StatementSequenceGenerator extends KickCBaseVisitor<Object> {
return null;
}
private void addInitialAssignment(KickCParser.InitializerContext initializer, Variable lValue) {
private void addInitialAssignment(KickCParser.ExprContext initializer, Variable lValue) {
PrePostModifierHandler.addPreModifiers(this, initializer);
RValue rValue = (RValue) visit(initializer);
Statement stmt = new StatementAssignment(lValue, rValue);
@ -448,15 +448,10 @@ public class StatementSequenceGenerator extends KickCBaseVisitor<Object> {
return new PointerDereferenceIndexed(lval, index);
}
@Override
public RValue visitInitExpr(KickCParser.InitExprContext ctx) {
return (RValue) visit(ctx.expr());
}
@Override
public RValue visitInitList(KickCParser.InitListContext ctx) {
List<RValue> initValues = new ArrayList<>();
for (KickCParser.InitializerContext initializer : ctx.initializer()) {
for (KickCParser.ExprContext initializer : ctx.expr()) {
RValue rValue = (RValue) visit(initializer);
initValues.add(rValue);
}