@Override public void generate(Node node) { Node directDeclarator = node.getChild(0); String name = (String) directDeclarator.getChild(0).getAttribute(Attribute.VALUE); Type type = directDeclarator.identifierTable().variable(name); switch (Production.fromNode(node)) { case INITIALIZATION_DECLARATOR_1: { // INITIALIZATION_DECLARATOR_1("<init_deklarator> ::= <izravni_deklarator>"), FRISCGenerator.generateCommand(ch.move(0, Reg.R5)); FRISCGenerator.generateCommand(ch.push(Reg.R5)); CallStack.push(name, type); if (type.isArray()) { int size = (Integer) directDeclarator.getChild(2).getAttribute(Attribute.VALUE); for (int i = 1; i < size; i++) { FRISCGenerator.generateCommand(ch.push(Reg.R5)); CallStack.push(null, type.fromArray()); } } break; } case INITIALIZATION_DECLARATOR_2: { // INITIALIZATION_DECLARATOR_2("<init_deklarator> ::= <izravni_deklarator> OP_PRIDRUZI // <inicijalizator>"); node.getChild(2).generate(); CallStack.push(name, type); if (type.isArray()) { int size = (Integer) directDeclarator.getChild(2).getAttribute(Attribute.VALUE); for (int i = 1; i < size; i++) { CallStack.push(null, type.fromArray()); } } break; } default: System.err.println("Generation reached undefined production!"); break; } }
private static boolean handleInits( final Integer elemCount, Type myType, final List<Type> initTypes) { if ((initTypes == null) || (myType == null) || (elemCount < initTypes.size())) { return false; } if (myType.isArray()) { myType = myType.fromArray(); } for (final Type type : initTypes) { if (!type.implicitConversion(myType)) { return false; } } return true; }