1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-04-09 21:37:31 +00:00

Converted typedef to use declarator. #121

This commit is contained in:
jespergravgaard 2021-05-02 21:11:03 +02:00
parent fafc9a5765
commit 7fb310296d
6 changed files with 883 additions and 919 deletions

View File

@ -19759,3 +19759,8 @@ lda {z2}+2
sta {z1}
lda {z2}+3
sta {z1}+1
//FRAGMENT _deref_qvoc1=pvoc2
lda #<{c2}
sta {c1}
lda #>{c2}
sta {c1}+1

View File

@ -8,11 +8,15 @@ options { tokenVocab=KickCLexer; }
@members {
// The C parser
CParser cParser;
// true when a typedef is being created
boolean isTypedef;
public KickCParser(TokenStream input, CParser cParser) {
this(input);
this.cParser = cParser;
this.isTypedef = false;
}
}
@ -53,7 +57,7 @@ declaratorInit
;
typeDef
: TYPEDEF declType declPointer* NAME declArray* {cParser.addTypedef($NAME.text);}
: TYPEDEF declType { isTypedef=true; } declarator
;
declType
@ -75,7 +79,7 @@ typeSpecifier
;
declarator
: NAME #declaratorName // {if(isTypedef) Parser.addTypedef($NAME.text);}
: NAME {if(isTypedef) { cParser.addTypedef($NAME.text); isTypedef=false; } } #declaratorName
| declarator BRACKET_BEGIN (expr)? BRACKET_END #declaratorArray
| ASTERISK directive* declarator #declaratorPointer
| PAR_BEGIN declarator PAR_END #declaratorPar

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -70,7 +70,7 @@ typeSpecifier
;
declarator
: NAME {if(isTypedef) Parser.addTypedef($NAME.text);} #declaratorName
: NAME {if(isTypedef) { Parser.addTypedef($NAME.text); isTypedef=false; } } #declaratorName
| declarator PAR_BEGIN parameterListDecl? PAR_END #declaratorProcedure
| declarator BRACKET_BEGIN (expr)? BRACKET_END #declaratorArray
| ASTERISK directive* declarator #declaratorPointer

View File

@ -2030,13 +2030,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
Scope typedefScope = program.getScope().getTypeDefScope();
scopeStack.push(typedefScope);
this.visit(ctx.declType());
for(KickCParser.DeclPointerContext declPointerContext : ctx.declPointer()) {
this.visit(declPointerContext);
}
for(KickCParser.DeclArrayContext declArrayContext : ctx.declArray()) {
this.visit(declArrayContext);
}
String typedefName = ctx.NAME().getText();
this.visit(ctx.declarator());
String typedefName = varDecl.getVarName();
VariableBuilder varBuilder = new VariableBuilder(typedefName, getCurrentScope(), false, varDecl.getEffectiveType(), varDecl.getDeclDirectives(), currentDataSegment, program.getTargetPlatform().getVariableBuilderConfig());
varBuilder.build();
scopeStack.pop();