private void defineInterfaceIndexer(IndexerDeclarationNode indexerDeclaration, TypeBuilder typeBuilder) { defineTypeIndexer(indexerDeclaration, typeBuilder); }
public void enterIndexerSetter(IndexerDeclarationNode declaration) { methodInfos.add(declaration.SetAccessor.getUserData(typeof(MethodInfo))); }
private void defineTypeIndexer(IndexerDeclarationNode indexerDeclaration, TypeBuilder typeBuilder) { var isInterface = typeBuilder.IsInterface; var type = CompilerHelper.resolveTypeReference(context, typeBuilder.PackageName, indexerDeclaration.Type); var get = indexerDeclaration.GetAccessor; var set = indexerDeclaration.SetAccessor; if (!isInterface) { checkAccessors(indexerDeclaration.Modifiers, get, set, indexerDeclaration); } var paramTypes = new TypeInfo[indexerDeclaration.Parameters.size()]; var paramNames = new String[sizeof(paramTypes)]; var isVarargs = false; int i = 0; foreach (var p in indexerDeclaration.Parameters) { paramTypes[i] = CompilerHelper.resolveTypeReference(context, typeBuilder.PackageName, p.Type); paramNames[i] = context.getIdentifier(p.NameOffset, p.NameLength); if (p.Modifier == ParameterModifier.Params) { if (i < indexerDeclaration.Parameters.size() - 1) { context.addError(CompileErrorId.ParamsNotLast, p); } if (!paramTypes[i].IsArray) { context.addError(CompileErrorId.ParamsNotArray, p); } isVarargs = true; } i++; } foreach (var meth in typeBuilder.Methods) { foreach (var ann in meth.Annotations) { if (BytecodeHelper.isIndexerGet(ann)) { // TODO: check the parameter types for redefinition } else if (BytecodeHelper.isIndexerSet(ann)) { // TODO: check the parameter types for redefinition } } } if (get != null) { var methodBuilder = typeBuilder.defineMethod("getItem"); methodBuilder.setVarargs(isVarargs); get.addUserData(methodBuilder); if (isInterface) { methodBuilder.setAbstract(true); methodBuilder.setPublic(true); } else { setPropertyOrIndexerModifiers(get, indexerDeclaration.getModifiers(), methodBuilder); } methodBuilder.setReturnType(type); methodBuilder.addAnnotation(context.getType("stab/lang/IndexerGet", get), false); for (i = 0; i < sizeof(paramTypes); i++) { var paramBuilder = methodBuilder.addParameter(paramTypes[i]); paramBuilder.setName(paramNames[i]); } } if (set != null) { var methodBuilder = typeBuilder.defineMethod("setItem"); methodBuilder.setVarargs(isVarargs); set.addUserData(methodBuilder); if (isInterface) { methodBuilder.setAbstract(true); methodBuilder.setPublic(true); } else { setPropertyOrIndexerModifiers(set, indexerDeclaration.getModifiers(), methodBuilder); } methodBuilder.setReturnType(context.TypeSystem.VoidType); for (i = 0; i < sizeof(paramTypes); i++) { var paramBuilder = methodBuilder.addParameter(paramTypes[i]); paramBuilder.setName(paramNames[i]); if (paramNames[i].equals("value")) { throw context.error(CompileErrorId.ValueParameterConflict, set); } } var paramBuilder = methodBuilder.addParameter(type); paramBuilder.setName("value"); methodBuilder.addAnnotation(context.getType("stab/lang/IndexerSet", set), false); } }
private IndexerDeclarationNode parseIndexerDeclaration(List<AnnotationSectionNode> annotations, EnumSet<Modifier> modifiers, bool partial, TypeReferenceNode type, bool inInterface, int startPosition) { var declaration = new IndexerDeclarationNode { Type = type, StartPosition = startPosition }; if (docCommentEndPosition > 0) { declaration.DocumentationOffset = docCommentStartPosition; declaration.DocumentationLength = docCommentEndPosition - docCommentStartPosition; docCommentEndPosition = 0; } setSavedScannerState(declaration); declaration.Modifiers.addAll(modifiers); declaration.Annotations.addAll(annotations); if (lexicalUnit != LexicalUnit.OpenBracket) { throw error(ParseErrorId.OpenBracketExpected); } if (nextLexicalUnit(true) != LexicalUnit.CloseBracket) { parseFormalParameters(declaration.Parameters, LexicalUnit.CloseBracket); } else { nextLexicalUnit(true); } Modifier setterAccess = Modifier.Public; if (lexicalUnit == LexicalUnit.Xor) { if (!inInterface) { throw error(ParseErrorId.OpenBraceExpected); } setterAccess = Modifier.Private; nextLexicalUnit(true); } if (lexicalUnit == LexicalUnit.SemiColon) { if (!inInterface) { throw error(ParseErrorId.OpenBraceExpected); } fakeParseShortProperty(declaration, setterAccess, inInterface); docCommentEndPosition = 0; declaration.EndPosition = scanner.EndPosition; nextLexicalUnit(false); return declaration; } if (lexicalUnit != LexicalUnit.OpenBrace) { throw error(ParseErrorId.OpenBraceExpected); } nextLexicalUnit(true); parseAccessorDeclaration(declaration, inInterface); if (lexicalUnit != LexicalUnit.CloseBrace) { parseAccessorDeclaration(declaration, inInterface); } docCommentEndPosition = 0; declaration.EndPosition = scanner.EndPosition; nextLexicalUnit(false); return declaration; }