コード例 #1
0
 private void defineInterfaceProperty(PropertyDeclarationNode propertyDeclaration, TypeBuilder typeBuilder) {
     defineTypeProperty(propertyDeclaration, typeBuilder);
 }
コード例 #2
0
 private void defineTypeProperty(PropertyDeclarationNode propertyDeclaration, TypeBuilder typeBuilder) {
     var isInterface = typeBuilder.IsInterface;
     var name = context.getIdentifier(propertyDeclaration.NameOffset, propertyDeclaration.NameLength);
     foreach (var meth in typeBuilder.Methods) {
         foreach (var ann in meth.Annotations) {
             if (BytecodeHelper.isPropertyGet(ann)) {
                 if (BytecodeHelper.getPropertyGetName(meth, ann).equals(name)) {
                     context.addError(CompileErrorId.AlreadyDefinedProperty, propertyDeclaration,
                         BytecodeHelper.getDisplayName(typeBuilder), name);
                 }
             } else if (BytecodeHelper.isPropertySet(ann)) {
                 if (BytecodeHelper.getPropertySetName(meth, ann).equals(name)) {
                     context.addError(CompileErrorId.AlreadyDefinedProperty, propertyDeclaration,
                         BytecodeHelper.getDisplayName(typeBuilder), name);
                 }
             }
         }
     }
     var type = CompilerHelper.resolveTypeReference(context, typeBuilder.PackageName, propertyDeclaration.Type);
     var get = propertyDeclaration.GetAccessor;
     var set = propertyDeclaration.SetAccessor;
     if (!isInterface) {
         checkAccessors(propertyDeclaration.Modifiers, get, set, propertyDeclaration);
     }
     if (get != null) {
         var methodName = "get" + name;
         if (type.IsBoolean) {
             if (name.length() > 2 && name.startsWith("Is") && Character.isUpperCase(name[2])) {
                 methodName = Character.toLowerCase(name[0]) + name.substring(1);
             }
         }
         var methodBuilder = typeBuilder.defineMethod(methodName);
         get.addUserData(methodBuilder);
         if (isInterface) {
             methodBuilder.setAbstract(true);
             methodBuilder.setPublic(true);
         } else {
             setPropertyOrIndexerModifiers(get, propertyDeclaration.getModifiers(), methodBuilder);
         }
         methodBuilder.setReturnType(type);
         methodBuilder.addAnnotation(context.getType("stab/lang/PropertyGet", get), false);
     }
     if (set != null) {
         var methodBuilder = typeBuilder.defineMethod("set" + name);
         set.addUserData(methodBuilder);
         if (isInterface) {
             methodBuilder.setAbstract(true);
             methodBuilder.setPublic(true);
         } else {
             setPropertyOrIndexerModifiers(set, propertyDeclaration.getModifiers(), methodBuilder);
         }
         methodBuilder.setReturnType(context.TypeSystem.VoidType);
         var paramBuilder = methodBuilder.addParameter(type);
         paramBuilder.setName("value");
         methodBuilder.addAnnotation(context.getType("stab/lang/PropertySet", set), false);
     }
 }
コード例 #3
0
        private ITypeMember parseFieldOrPropertyOrMethod(List<AnnotationSectionNode> annotations, EnumSet<Modifier> modifiers,
                bool partial, TypeReferenceNode type, int startPosition) {
            if (!isIdentifier(lexicalUnit)) {
                throw error(ParseErrorId.IdentifierExpected);
            }
            int sp = scanner.StartPosition;
            int len = getLexicalUnitLength();
            saveScannerState();
            var typeParameters = new ArrayList<SimpleNameTypeReferenceNode>();
            nextLexicalUnit(true);
            parseTypeParameters(typeParameters);
			Modifier setterAccess = checkSetterAccess();
			bool forceAsField = false;
			if (lexicalUnit == LexicalUnit.Multiply) {
				forceAsField = true;
                nextLexicalUnit(true);			
			}
            switch (lexicalUnit) {
            case OpenParenthesis:
				if (setterAccess != Modifier.Public || forceAsField) {
					throw error(ParseErrorId.IdentifierExpected);
				}
                var methodDeclaration = new MethodDeclarationNode { IsPartial = partial, ReturnType = type, NameOffset = sp, NameLength = len,
						StartPosition = startPosition };
                if (docCommentEndPosition > 0) {
                    methodDeclaration.DocumentationOffset = docCommentStartPosition;
                    methodDeclaration.DocumentationLength = docCommentEndPosition - docCommentStartPosition;
                    docCommentEndPosition = 0;
                }
                setSavedScannerState(methodDeclaration);
                methodDeclaration.Modifiers.addAll(modifiers);
                methodDeclaration.Annotations.addAll(annotations);
                foreach (var t in typeParameters) {
                    if (t.TypeReferenceKind != TypeReferenceKind.SimpleName || t.TypeArguments.size() > 0) {
                        throw error(ParseErrorId.SimpleNameExpected);
                    }
                    methodDeclaration.TypeParameters.add((SimpleNameTypeReferenceNode)t);
                }

                if (nextLexicalUnit(true) != LexicalUnit.CloseParenthesis) {
                    parseFormalParameters(methodDeclaration.Parameters, LexicalUnit.CloseParenthesis);
                } else {
                    nextLexicalUnit(true);
                }
                parseTypeParameterConstraintsClauses(methodDeclaration.ConstraintsClauses);
                switch (lexicalUnit) {
                case OpenBrace:
                    methodDeclaration.Body = parseBlockStatement();
					methodDeclaration.EndPosition = methodDeclaration.Body.EndPosition;
                    break;

                case SemiColon:
					methodDeclaration.EndPosition = scanner.EndPosition;
                    nextLexicalUnit(true);
                    break;

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

            case OpenBrace:
				if (setterAccess != Modifier.Public || forceAsField) {
					throw error(ParseErrorId.IdentifierExpected);
				}
                var propertyDeclaration = new PropertyDeclarationNode { Type = type, NameOffset = sp, NameLength = len,
						StartPosition = startPosition };
                if (docCommentEndPosition > 0) {
                    propertyDeclaration.DocumentationOffset = docCommentStartPosition;
                    propertyDeclaration.DocumentationLength = docCommentEndPosition - docCommentStartPosition;
                    docCommentEndPosition = 0;
                }
                setSavedScannerState(propertyDeclaration);
                propertyDeclaration.Modifiers.addAll(modifiers);
                nextLexicalUnit(true);
                parseAccessorDeclaration(propertyDeclaration, false);
                if (lexicalUnit != LexicalUnit.CloseBrace) {
                    parseAccessorDeclaration(propertyDeclaration, false);
                }
                docCommentEndPosition = 0;
				propertyDeclaration.EndPosition = scanner.EndPosition;
                nextLexicalUnit(false);
                return propertyDeclaration;

            case Assign: {
				if (setterAccess != Modifier.Public || forceAsField) {
					throw error(ParseErrorId.IdentifierExpected);
				}
                var declaration = new FieldDeclarationNode { 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);
                nextLexicalUnit(true);
                var decl = new VariableDeclaratorNode { NameOffset = sp, NameLength = len };
                setSavedScannerState(decl);
                decl.Value = parseFieldInitializer();
                decl.EndPosition = decl.Value.EndPosition;
                declaration.Declarators.add(decl);
                while (lexicalUnit == LexicalUnit.Comma) {
                    if (!isIdentifier(nextLexicalUnit(true))) {
                        throw error(ParseErrorId.IdentifierExpected);
                    }
                    decl = new VariableDeclaratorNode { NameOffset = scanner.StartPosition, NameLength = getLexicalUnitLength() };
                    setScannerState(decl);
                    decl.EndPosition = scanner.EndPosition;
                    declaration.Declarators.add(decl);
                    if (nextLexicalUnit(true) == LexicalUnit.Assign) {
                        nextLexicalUnit(true);
                        decl.Value = parseFieldInitializer();
                        decl.EndPosition = decl.Value.EndPosition;
                    }
                }
                docCommentEndPosition = 0;
                declaration.EndPosition = parseSemiColon(false, false);
                return declaration;
            }

            case Comma: {
				if (setterAccess != Modifier.Public || forceAsField) {
					throw error(ParseErrorId.IdentifierExpected);
				}
                var declaration = new FieldDeclarationNode { 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);
                var decl = new VariableDeclaratorNode { NameOffset = sp, NameLength = len };
                setSavedScannerState(decl);
                decl.EndPosition = sp + len;
                declaration.Declarators.add(decl);
                do {
                    if (!isIdentifier(nextLexicalUnit(true))) {
                        throw error(ParseErrorId.IdentifierExpected);
                    }
                    decl = new VariableDeclaratorNode { NameOffset = scanner.StartPosition, NameLength = getLexicalUnitLength() };
                    setScannerState(decl);
                    declaration.Declarators.add(decl);
                    decl.EndPosition = scanner.EndPosition;
                    if (nextLexicalUnit(true) == LexicalUnit.Assign) {
                        nextLexicalUnit(true);
                        decl.Value = parseFieldInitializer();
                        decl.EndPosition = decl.Value.EndPosition;
                    }
                } while (lexicalUnit == LexicalUnit.Comma);
                docCommentEndPosition = 0;
                declaration.EndPosition = parseSemiColon(false, false);
                return declaration;
            }

            case SemiColon: {
				if ((modifiers.contains(Modifier.Public) || modifiers.contains(Modifier.Protected)) && !forceAsField) {
					var propertyShortDeclaration = new PropertyDeclarationNode { Type = type, NameOffset = sp, NameLength = len,
							StartPosition = startPosition };
					if (docCommentEndPosition > 0) {
						propertyShortDeclaration.DocumentationOffset = docCommentStartPosition;
						propertyShortDeclaration.DocumentationLength = docCommentEndPosition - docCommentStartPosition;
						docCommentEndPosition = 0;
					}
					setSavedScannerState(propertyShortDeclaration);
					propertyShortDeclaration.Modifiers.addAll(modifiers);
					fakeParseShortProperty(propertyShortDeclaration, setterAccess, false);
					docCommentEndPosition = 0;
					propertyShortDeclaration.EndPosition = scanner.EndPosition;
					nextLexicalUnit(false);
					return propertyShortDeclaration;
				}
                var declaration = new FieldDeclarationNode { 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);
                var decl = new VariableDeclaratorNode { NameOffset = sp, NameLength = len };
                setSavedScannerState(decl);
                decl.EndPosition = sp + len;
                declaration.Declarators.add(decl);
                docCommentEndPosition = 0;
				declaration.EndPosition = scanner.EndPosition;
                nextLexicalUnit(false);
                return declaration;
            }

            default:
                throw error(ParseErrorId.UnexpectedLexicalUnit);
            }
        }
コード例 #4
0
		public void enterPropertySetter(PropertyDeclarationNode declaration) {
			methodInfos.add(declaration.SetAccessor.getUserData(typeof(MethodInfo)));
		}
コード例 #5
0
        private IInterfaceMember parseInterfaceMember(List<AnnotationSectionNode> annotations, EnumSet<Modifier> modifiers, int startPosition) {
            var type = parseType(true, true);
            if (lexicalUnit == LexicalUnit.Keyword && scanner.Keyword == Keyword.This) {
                saveScannerState();
                nextLexicalUnit(true);
                return parseIndexerDeclaration(annotations, modifiers, false, type, true, startPosition);
            }
            if (!isIdentifier(lexicalUnit)) {
                throw error(ParseErrorId.IdentifierExpected);
            }
            int sp = scanner.StartPosition;
            int len = getLexicalUnitLength();
            saveScannerState();
			var lexicalUnitShorter = nextLexicalUnit(true);
            if (lexicalUnitShorter == LexicalUnit.OpenBrace) {
                var declaration = new PropertyDeclarationNode { Type = type, NameOffset = sp, NameLength = len, StartPosition = startPosition };
                if (docCommentEndPosition > 0) {
                    declaration.DocumentationOffset = docCommentStartPosition;
                    declaration.DocumentationLength = docCommentEndPosition - docCommentStartPosition;
                    docCommentEndPosition = 0;
                }
                setSavedScannerState(declaration);
                declaration.Modifiers.addAll(modifiers);
                declaration.Annotations.addAll(annotations);
                nextLexicalUnit(true);
                parseAccessorDeclaration(declaration, true);
                if (lexicalUnit != LexicalUnit.CloseBrace) {
                    parseAccessorDeclaration(declaration, true);
                }
				declaration.EndPosition = scanner.EndPosition;
                nextLexicalUnit(false);
                return declaration;
			} 
			Modifier setterAccess = Modifier.Public;
			if (lexicalUnitShorter == LexicalUnit.Xor) {
				setterAccess = Modifier.Private;
				lexicalUnitShorter = nextLexicalUnit(true);
			}
			if (lexicalUnitShorter == LexicalUnit.SemiColon) {
				var propertyShortDeclaration = new PropertyDeclarationNode { Type = type, NameOffset = sp, NameLength = len,
						StartPosition = startPosition };
				if (docCommentEndPosition > 0) {
					propertyShortDeclaration.DocumentationOffset = docCommentStartPosition;
					propertyShortDeclaration.DocumentationLength = docCommentEndPosition - docCommentStartPosition;
					docCommentEndPosition = 0;
				}
				setSavedScannerState(propertyShortDeclaration);
				propertyShortDeclaration.Modifiers.addAll(modifiers);
                propertyShortDeclaration.Annotations.addAll(annotations);
				fakeParseShortProperty(propertyShortDeclaration, setterAccess, true);
				docCommentEndPosition = 0;
				propertyShortDeclaration.EndPosition = scanner.EndPosition;
				nextLexicalUnit(false);
				return propertyShortDeclaration;
			}
			var declaration = new MethodDeclarationNode { ReturnType = type, NameOffset = sp, NameLength = len, StartPosition = startPosition };
			if (docCommentEndPosition > 0) {
				declaration.DocumentationOffset = docCommentStartPosition;
				declaration.DocumentationLength = docCommentEndPosition - docCommentStartPosition;
				docCommentEndPosition = 0;
			}
			setSavedScannerState(declaration);
			declaration.Modifiers.addAll(modifiers);
			declaration.Annotations.addAll(annotations);
			parseTypeParameters(declaration.TypeParameters);
			if (lexicalUnit != LexicalUnit.OpenParenthesis) {
				throw error(ParseErrorId.OpenParenthesisExpected);
			}
			if (nextLexicalUnit(true) != LexicalUnit.CloseParenthesis) {
				parseFormalParameters(declaration.Parameters, LexicalUnit.CloseParenthesis);
			} else {
				nextLexicalUnit(true);
			}
			if (lexicalUnit == LexicalUnit.Assign) {
				nextLexicalUnit(true);
				declaration.DefaultValue = parseAnnotationValue();
			} else {
				parseTypeParameterConstraintsClauses(declaration.ConstraintsClauses);
			}
			docCommentEndPosition = 0;
			declaration.EndPosition = parseSemiColon(false, false);
			return declaration;
        }