private void field_or_method_declaration(ref ClassTypeNode currentClassType, TypeNode type, EncapsulationNode encapsulation, MethodModifierNode modifier) { printIfDebug("field_or_method_declaration"); if (!pass(TokenType.ID)) { throwError("identifier expected"); } var Identifier = new IdNode(token.lexeme, token); var identifierMethodOrFielToken = token; consumeToken(); if (pass(TokenType.PUNT_PAREN_OPEN)) { var newMethodDeclared = method_declaration(Identifier, type, identifierMethodOrFielToken); newMethodDeclared.setEncapsulation(encapsulation); if (modifier != null) { newMethodDeclared.setModifier(modifier); } currentClassType.addMethod(newMethodDeclared); } else { var isStatic = (modifier != null)?modifier.token.type == TokenType.RW_STATIC:false; if (modifier != null && !isStatic) { Utils.ThrowError("The modifier '" + modifier.token.lexeme + "' is not valid on fields. Try using a property instead."); } var fieldDeclarationList = field_declaration(type, Identifier, encapsulation, isStatic); currentClassType.addFields(fieldDeclarationList); } }
/* * ; SEMANTIC: validar que el constructor no tenga tipo de retorno * class-member-declaration-options: | optional-modifier type-or-void identifier field-or-method-or-constructor */ private void class_member_declaration_options(ref ClassTypeNode currentClassType, EncapsulationNode encapsulation) { printIfDebug("class_member_declaration_options"); if (pass(optionalModifiersOptions)) //Field or Method { Token optionalModifierToken = token; var methodModifier = new MethodModifierNode(optionalModifierToken); consumeToken(); if (!pass(typesOptions, voidOption)) { throwError("type-or-void expected"); } var type = type_or_void(); if (!pass(TokenType.ID)) { throwError("identifier expected"); } if (optionalModifierToken.type == TokenType.RW_STATIC) //Field { field_or_method_declaration(ref currentClassType, type, encapsulation, methodModifier); } else //Method { var Identifier = new IdNode(token.lexeme, token); var identifierMethodToken = token; consumeToken(); var methodDeclared = method_declaration(Identifier, type, identifierMethodToken); methodDeclared.setModifier(methodModifier); methodDeclared.setEncapsulation(encapsulation); currentClassType.addMethod(methodDeclared); } } else if (pass(typesOptions, voidOption)) //Field, Method or constructor { Token oldToken = token; var type = type_or_void(); if (oldToken.type == TokenType.ID) //Field, Method or constructor { if (pass(TokenType.ID)) //Field or Method { field_or_method_declaration(ref currentClassType, type, encapsulation, null); } else if (pass(TokenType.PUNT_PAREN_OPEN)) //Contructor { var Identifier = new IdNode(oldToken.lexeme, token); var contructoreDeclaration = constructor_declaration(Identifier); contructoreDeclaration.setEncapsulation(encapsulation); currentClassType.addContructor(contructoreDeclaration); } } else //Field or Method { if (!pass(TokenType.ID)) { throwError("identifier expected"); } field_or_method_declaration(ref currentClassType, type, encapsulation, null); } } // else //Contructor // { // constructor_declaration(); // } }