mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-25 20:32:25 +00:00
Converted DeclFunction to use declarator. #121
This commit is contained in:
parent
d59c5315ec
commit
09d11f220b
@ -64,14 +64,6 @@ declType
|
||||
: directive* type directive*
|
||||
;
|
||||
|
||||
declPointer
|
||||
: ASTERISK directive*
|
||||
;
|
||||
|
||||
declArray
|
||||
: BRACKET_BEGIN (expr)? BRACKET_END
|
||||
;
|
||||
|
||||
typeSpecifier
|
||||
: type #typeSpecifierSimple
|
||||
| typeSpecifier ASTERISK #typeSpecifierPointer
|
||||
@ -126,7 +118,7 @@ enumMember
|
||||
;
|
||||
|
||||
declFunction
|
||||
: declType declPointer* NAME PAR_BEGIN parameterListDecl? PAR_END (declFunctionBody | ';' )
|
||||
: declType declarator PAR_BEGIN parameterListDecl? PAR_END (declFunctionBody | ';' )
|
||||
;
|
||||
|
||||
declFunctionBody
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -133,30 +133,6 @@ public class KickCParserBaseListener implements KickCParserListener {
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitDeclType(KickCParser.DeclTypeContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterDeclPointer(KickCParser.DeclPointerContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitDeclPointer(KickCParser.DeclPointerContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterDeclArray(KickCParser.DeclArrayContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitDeclArray(KickCParser.DeclArrayContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
@ -83,20 +83,6 @@ public class KickCParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> imple
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitDeclType(KickCParser.DeclTypeContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitDeclPointer(KickCParser.DeclPointerContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitDeclArray(KickCParser.DeclArrayContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
@ -113,26 +113,6 @@ public interface KickCParserListener extends ParseTreeListener {
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitDeclType(KickCParser.DeclTypeContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link KickCParser#declPointer}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterDeclPointer(KickCParser.DeclPointerContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link KickCParser#declPointer}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitDeclPointer(KickCParser.DeclPointerContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link KickCParser#declArray}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterDeclArray(KickCParser.DeclArrayContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link KickCParser#declArray}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitDeclArray(KickCParser.DeclArrayContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code typeSpecifierSimple}
|
||||
* labeled alternative in {@link KickCParser#typeSpecifier}.
|
||||
|
@ -74,18 +74,6 @@ public interface KickCParserVisitor<T> extends ParseTreeVisitor<T> {
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitDeclType(KickCParser.DeclTypeContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link KickCParser#declPointer}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitDeclPointer(KickCParser.DeclPointerContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link KickCParser#declArray}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitDeclArray(KickCParser.DeclArrayContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code typeSpecifierSimple}
|
||||
* labeled alternative in {@link KickCParser#typeSpecifier}.
|
||||
|
@ -390,12 +390,10 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
@Override
|
||||
public Object visitDeclFunction(KickCParser.DeclFunctionContext ctx) {
|
||||
this.visit(ctx.declType());
|
||||
for(KickCParser.DeclPointerContext declPointerContext : ctx.declPointer()) {
|
||||
this.visit(declPointerContext);
|
||||
}
|
||||
this.visit(ctx.declarator());
|
||||
SymbolType type = varDecl.getEffectiveType();
|
||||
List<Directive> directives = varDecl.getDeclDirectives();
|
||||
String name = ctx.NAME().getText();
|
||||
String name = varDecl.getVarName();
|
||||
Procedure procedure = new Procedure(name, type, program.getScope(), currentCodeSegment, currentDataSegment, currentCallingConvention);
|
||||
addDirectives(procedure, directives, StatementSource.procedureDecl(ctx));
|
||||
procedure.setComments(ensureUnusedComments(getCommentsSymbol(ctx)));
|
||||
@ -887,37 +885,6 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
this.varDecl = varDeclStack.pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitDeclPointer(KickCParser.DeclPointerContext ctx) {
|
||||
// Create a var-level declaration type
|
||||
final SymbolType elementDeclType = varDecl.getEffectiveType();
|
||||
SymbolTypePointer pointerType = new SymbolTypePointer(elementDeclType);
|
||||
final List<Directive> typeDirectives = getDirectives(ctx.directive());
|
||||
varDecl.setVarDeclTypeAndDirectives(pointerType, typeDirectives);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object visitDeclArray(KickCParser.DeclArrayContext ctx) {
|
||||
// Handle array type declaration by updating the declared type and the array spec
|
||||
ArraySpec arraySpec;
|
||||
if(ctx.expr() != null) {
|
||||
varDeclPush();
|
||||
RValue sizeVal = (RValue) visit(ctx.expr());
|
||||
if(!(sizeVal instanceof ConstantValue))
|
||||
throw new CompileError(sizeVal.toString() + " is not constant or is not defined", new StatementSource(ctx));
|
||||
varDeclPop();
|
||||
arraySpec = new ArraySpec((ConstantValue) sizeVal);
|
||||
} else {
|
||||
arraySpec = new ArraySpec();
|
||||
}
|
||||
final SymbolType elementDeclType = varDecl.getEffectiveType();
|
||||
SymbolType arrayDeclType = new SymbolTypePointer(elementDeclType, arraySpec, false, false);
|
||||
varDecl.setVarDeclType(arrayDeclType);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit the type/directive part of a declaration. Setup the local decl-variables
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user