Пример #1
0
 private void setNestedDelegateModifiers(DelegateDeclarationNode delegateDeclaration, TypeBuilder typeBuilder) {
     foreach (var modifier in delegateDeclaration.Modifiers) {
         switch (modifier) {
         case Public:
             if (typeBuilder.IsNestedPrivate || typeBuilder.IsNestedProtected) {
                 context.addError(CompileErrorId.PublicProtectedPrivate, delegateDeclaration);
             } else {
                 typeBuilder.setPublic(true);
                 typeBuilder.setNestedPublic(true);
             }
             break;
             
         case Protected:
             if (typeBuilder.IsNestedPrivate || typeBuilder.IsNestedPublic) {
                 context.addError(CompileErrorId.PublicProtectedPrivate, delegateDeclaration);
             } else {
                 typeBuilder.setNestedProtected(true);
             }
             break;
             
         case Private:
             if (typeBuilder.IsNestedProtected || typeBuilder.IsNestedPublic) {
                 context.addError(CompileErrorId.PublicProtectedPrivate, delegateDeclaration);
             } else {
                 typeBuilder.setNestedPrivate(true);
             }
             break;
             
         default:
             context.addError(CompileErrorId.UnexpectedModifier, delegateDeclaration, modifier.toString().toLowerCase());
             break;
         }
     }
 }
Пример #2
0
 private void defineNestedDelegate(TypeBuilder declaringClass, DelegateDeclarationNode delegateDeclaration) {
     var shortName = context.getIdentifier(delegateDeclaration.NameOffset, delegateDeclaration.NameLength);
     var className = declaringClass.FullName + '$' + shortName;
     var typeBuilder = defineNestedType(declaringClass, className, shortName, delegateDeclaration);
     typeBuilder.setAbstract(true);
     delegateDeclaration.addUserData(typeBuilder);
     setNestedDelegateModifiers(delegateDeclaration, typeBuilder);
 }
Пример #3
0
 private void setDelegateModifiers(DelegateDeclarationNode delegateDeclaration, TypeBuilder typeBuilder) {
     foreach (var modifier in delegateDeclaration.Modifiers) {
         switch (modifier) {
         case Public:
             typeBuilder.setPublic(true);
             break;
             
         default:
             context.addError(CompileErrorId.UnexpectedModifier, delegateDeclaration, modifier.toString().toLowerCase());
             break;
         }
     }
 }
Пример #4
0
 private void defineDelegate(String packageName, DelegateDeclarationNode delegateDeclaration) {
     var className = getTypeName(packageName, delegateDeclaration.NameOffset, delegateDeclaration.NameLength);
     var typeBuilder = defineType(className, delegateDeclaration);
     typeBuilder.setAbstract(true);
     delegateDeclaration.addUserData(typeBuilder);
     setDelegateModifiers(delegateDeclaration, typeBuilder);
 }
Пример #5
0
 private void defineDelegateMembers(DelegateDeclarationNode delegateDeclaration) {
     var typeBuilder = delegateDeclaration.getUserData(typeof(TypeBuilder));
     context.CurrentType = typeBuilder;
     setTypeParameters(typeBuilder, delegateDeclaration.TypeParameters, delegateDeclaration);
     try {
         context.MemberResolver.enterType(typeBuilder);
         
         // invoke()
         var methodBuilder = typeBuilder.defineMethod("invoke");
         methodBuilder.setReturnType(CompilerHelper.resolveTypeReference(context, typeBuilder.PackageName, delegateDeclaration.ReturnType));
         foreach (var p in delegateDeclaration.Parameters) {
             var pb = methodBuilder.addParameter(CompilerHelper.resolveTypeReference(context, typeBuilder.PackageName, p.Type));
             pb.setName(context.getIdentifier(p.NameOffset, p.NameLength));
         }
         methodBuilder.setAbstract(true);
         methodBuilder.setPublic(true);
         
         // TODO: async invoke
         
         // Constructor
         methodBuilder = typeBuilder.defineMethod("<init>");
         methodBuilder.setProtected(true);
         methodBuilder.setReturnType(context.TypeSystem.VoidType);
         var pb = methodBuilder.addParameter(context.TypeSystem.ObjectType);
         pb.setName("target");
     } finally {
         context.MemberResolver.leaveType();
     }
 }
Пример #6
0
 private void setDelegateBaseTypes(DelegateDeclarationNode delegateDeclaration) {
     var typeBuilder = delegateDeclaration.getUserData(typeof(TypeBuilder));
     typeBuilder.setBaseType(context.getType("stab/lang/Delegate", delegateDeclaration));
 }
Пример #7
0
 private DelegateDeclarationNode parseDelegate(List<AnnotationSectionNode> annotations, EnumSet<Modifier> modifiers, int startPosition) {
     var declaration = new DelegateDeclarationNode { ReturnType = parseType(true, true), StartPosition = startPosition };
     if (docCommentEndPosition > 0) {
         declaration.DocumentationOffset = docCommentStartPosition;
         declaration.DocumentationLength = docCommentEndPosition - docCommentStartPosition;
         docCommentEndPosition = 0;
     }
     declaration.Modifiers.addAll(modifiers);
     declaration.Annotations.addAll(annotations);
     if (!isIdentifier(lexicalUnit)) {
         throw error(ParseErrorId.IdentifierExpected);
     }
     setScannerState(declaration);
     declaration.NameOffset = scanner.StartPosition;
     declaration.NameLength = getLexicalUnitLength();
     nextLexicalUnit(true);
     parseTypeParameters(declaration.TypeParameters);
     if (lexicalUnit != LexicalUnit.OpenParenthesis) {
         throw error(ParseErrorId.OpenParenthesisExpected);
     }
     if (nextLexicalUnit(true) != LexicalUnit.CloseParenthesis) {
         parseFormalParameters(declaration.Parameters, LexicalUnit.CloseParenthesis);
     } else {
         nextLexicalUnit(true);
     }
     parseTypeParameterConstraintsClauses(declaration.ConstraintsClauses);
     docCommentEndPosition = 0;
     declaration.EndPosition = parseSemiColon(false, false);
     return declaration;
 }
		private void print(DelegateDeclarationNode declaration, int indent, StringBuilder sb) {
			var indentText = buildIndentText(indent);
			foreach (var attr in declaration.Annotations) {
				sb.append(indentText);
				print(attr, true, sb);
			}
			sb.append(indentText);
			print(declaration.Modifiers, sb);
			sb.append("delegate ");
			print(declaration.ReturnType, sb);
			sb.append(" ");
			sb.append(new String(text, declaration.NameOffset, declaration.NameLength));
			sb.append("(");
			bool first = true;
			foreach (var p in declaration.Parameters) {
				if (first) {
					first = false;
				} else {
					sb.append(", ");
				}
				print(p, sb);
			}
			sb.append(");\r\n");
		}