Ejemplo n.º 1
0
 private void defineClassDestructor(DestructorDeclarationNode destructorDeclaration, TypeBuilder typeBuilder) {
     if (typeBuilder.IsEnum) {
         // TODO: error
     }
     var methodBuilder = (MethodBuilder)typeBuilder.getMethod("finalize", Query.empty<TypeInfo>());
     if (methodBuilder != null) {
         context.addError(CompileErrorId.AlreadyDefinedDestructor, destructorDeclaration,
                 BytecodeHelper.getDisplayName(typeBuilder));
     }
     var name = context.getIdentifier(destructorDeclaration.NameOffset, destructorDeclaration.NameLength);
     if (!name.equals(typeBuilder.Name)) {
         context.addError(CompileErrorId.InvalidDestructorName, destructorDeclaration, name);
     }
     methodBuilder = typeBuilder.defineMethod("finalize");
     methodBuilder.setReturnType(context.TypeSystem.VoidType);
     methodBuilder.setProtected(true);
     destructorDeclaration.addUserData(methodBuilder);
 }
Ejemplo n.º 2
0
        private ITypeMember parseDestructorDeclaration(List<AnnotationSectionNode> annotations, EnumSet<Modifier> modifiers) {
            if (!isIdentifier(lexicalUnit)) {
                throw error(ParseErrorId.IdentifierExpected);
            }
            var declaration = new DestructorDeclarationNode { NameOffset = scanner.StartPosition, NameLength = getLexicalUnitLength() };
            if (docCommentEndPosition > 0) {
                declaration.DocumentationOffset = docCommentStartPosition;
                declaration.DocumentationLength = docCommentEndPosition - docCommentStartPosition;
                docCommentEndPosition = 0;
            }
            setScannerState(declaration);
            declaration.Modifiers.addAll(modifiers);
            declaration.Annotations.addAll(annotations);
            if (nextLexicalUnit(true) != LexicalUnit.OpenParenthesis) {
                throw error(ParseErrorId.OpenParenthesisExpected);
            }
            if (nextLexicalUnit(true) != LexicalUnit.CloseParenthesis) {
                throw error(ParseErrorId.CloseParenthesisExpected);
            }
            nextLexicalUnit(true);
            switch (lexicalUnit) {
            case OpenBrace:
                declaration.Body = parseBlockStatement();
				declaration.EndPosition = declaration.Body.EndPosition;
                break;

            case SemiColon:
				declaration.EndPosition = scanner.StartPosition;
                docCommentEndPosition = 0;
                nextLexicalUnit(true);
                break;

            default:
                throw error(ParseErrorId.OpenBraceExpected);
            }
            return declaration;
        }