Пример #1
0
 private bool ExplicitInterfaceImplementationIsAllowable(TypeNode parentType, Identifier id){
   if (parentType is Class || parentType is Struct) return true;
   this.HandleError(id.SourceContext, Error.ExplicitInterfaceImplementationInNonClassOrStruct,
     id.ToString()+"."+this.scanner.GetTokenSource());
   return false;
 }
Пример #2
0
    void AddWriteElement(StatementList statements, TypeNode referringType, Identifier writer, Identifier name, Expression src, TypeNode mt, bool emptyElementOnNull) {

      if (mt.Template == SystemTypes.GenericBoxed) {
        statements = AddCheckForNull(statements, Duplicate(src, referringType), mt);     
        mt = Checker.GetCollectionElementType(mt); // check for null and unbox 
        src = CastTo(src, mt); //unbox it
      }

      Literal nameLit = new Literal(name.ToString(), SystemTypes.String);
      Literal nsLit = (name.Prefix != null) ? new Literal(name.Prefix.Name, SystemTypes.String) : Literal.Null;

      if (!emptyElementOnNull) {
        statements = AddCheckForNull(statements, Duplicate(src, referringType), mt);         
      }
      if (!AddWriteSimpleType(mt, statements, referringType, writer, src, nameLit, nsLit)) {
        AddCallSerializer(mt, statements, src, writer, nameLit, nsLit);
      }

    }
Пример #3
0
 public Member CheckAttribute(Identifier attrName, out TypeNode mType) {
   mType = null;
   if (attributes != null) {
     for (int j = 0, m = attributes.Length; j < m; j++) {
       SchemaAttDef attdef = attributes[j];
       if (attdef.Name.UniqueKey != attrName.UniqueKey) continue;
       if (attrSpecified[j]) {
         context.HandleError(this.RootNode, attrName, Error.DuplicateAttributeSpecified, ErrorHandler.GetTypeNameFor(element.Type), attrName.ToString());
         return null;          
       }
       attrSpecified[j] = true;
       Member mem = attdef.Member;
       //TODO: skip over mem if it is not visible from the current context
       mType =  (mem.NodeType == NodeType.Field) ? ((Field)mem).Type : ((Property)mem).Type;
       return mem;
     }
   }
   return null;
 }
Пример #4
0
 private void ParseProperty(TypeNode parentType, AttributeList attributes, TokenList modifierTokens,
   SourceContextList modifierContexts, object sctx, TypeNode type, TypeNode interfaceType, Identifier name, TokenSet followers){
   SourceContext ctx = (SourceContext)sctx;
   ctx.EndPos = this.scanner.endPos;
   bool isIndexer = this.currentToken == Token.This && name.UniqueIdKey == StandardIds.Item.UniqueIdKey;
   Debug.Assert(this.currentToken == Token.LeftBrace || isIndexer);
   this.GetNextToken();
   ParameterList paramList = null;
   if (isIndexer){
     if (interfaceType == null){
       AttributeNode defaultMember = new AttributeNode();
       defaultMember.Constructor = new Literal(TypeExpressionFor("System", "Reflection", "DefaultMemberAttribute"));
       defaultMember.Expressions = new ExpressionList(1);
       defaultMember.Expressions.Add(new Literal("Item"));
       if (parentType.Attributes == null) parentType.Attributes = new AttributeList(1);
       parentType.Attributes.Add(defaultMember);
     }
     paramList = this.ParseParameters(Token.RightBracket, followers|Token.LeftBrace);
     this.Skip(Token.LeftBrace);
   }
   Property p = new Property(parentType, attributes, PropertyFlags.None, name, null, null);
   parentType.Members.Add(p);
   p.SourceContext = ctx;
   p.Documentation = this.LastDocComment;
   p.Type = p.TypeExpression = type;
   MethodFlags mflags;
   if (interfaceType != null){
     p.ImplementedTypeExpressions = p.ImplementedTypes = new TypeNodeList(interfaceType);
     mflags = MethodFlags.Private|MethodFlags.HideBySig|MethodFlags.NewSlot|MethodFlags.Final|MethodFlags.Virtual|MethodFlags.SpecialName;
     for (int i = 0, n = modifierContexts == null ? 0 : modifierContexts.Length; i < n; i++) {
       if (modifierTokens[i] == Token.Extern)
         mflags |= MethodFlags.PInvokeImpl;
       else if (modifierTokens[i] == Token.Unsafe) {
         if (!this.allowUnsafeCode) {
           this.allowUnsafeCode = true;
           this.HandleError(modifierContexts[i], Error.IllegalUnsafe);
         }
         this.inUnsafeCode = true;
       } else
         this.HandleError(modifierContexts[i], Error.InvalidModifier, modifierContexts[i].SourceText);
     }
   }else
     mflags = this.GetMethodFlags(modifierTokens, modifierContexts, parentType, p)|MethodFlags.SpecialName;
   if ((mflags & MethodFlags.Static) != 0 && parentType is Interface){
     this.HandleError(name.SourceContext, Error.InvalidModifier, "static");
     mflags &= ~MethodFlags.Static;
     mflags |= MethodFlags.Abstract;
   }
   TokenSet followersOrRightBrace = followers|Token.RightBrace;
   bool accessorModifiersAlreadySpecified = false;
   MethodFlags accessorFlags = mflags;
   while (Parser.GetOrLeftBracketOrSetOrModifier[this.currentToken]){
     SourceContext sc = this.scanner.CurrentSourceContext;
     AttributeList accessorAttrs = this.ParseAttributes(null, followers|Token.Get|Token.Set|Token.LeftBrace);
     switch (this.currentToken){
       case Token.Get:{
         if (p.Getter != null)
           this.HandleError(Error.DuplicateAccessor);
         SourceContext scntx = this.scanner.CurrentSourceContext;
         this.GetNextToken();
         Method m = new Method(parentType, accessorAttrs, new Identifier("get_"+name.ToString()), paramList, type, null);
         m.SourceContext = sc;
         m.ReturnTypeExpression = type;
         m.Name.SourceContext = scntx;
         if ((accessorFlags & MethodFlags.Static) == 0)
           m.CallingConvention = CallingConventionFlags.HasThis;
         parentType.Members.Add(m);
         m.Flags = accessorFlags|MethodFlags.HideBySig;
         if (interfaceType != null)
           m.ImplementedTypeExpressions = m.ImplementedTypes = new TypeNodeList(interfaceType);
         bool swallowedSemicolonAlready = false;
         bool bodyAllowed = true;
         if (this.currentToken == Token.Semicolon){
           m.SourceContext.EndPos = this.scanner.endPos;
           this.GetNextToken();
           bodyAllowed = false;
           swallowedSemicolonAlready = true;
         }
         this.ParseMethodContract(m, followers|Token.LeftBrace|Token.Semicolon, ref swallowedSemicolonAlready);
         if (bodyAllowed)
           m.Body = this.ParseBody(m, sc, followersOrRightBrace|Token.Set, swallowedSemicolonAlready);
         else if (!swallowedSemicolonAlready)
           this.SkipSemiColon(followersOrRightBrace|Token.Set);
         p.Getter = m;
         m.DeclaringMember = p;
         accessorFlags = mflags;
         break;}
       case Token.Set:{
         if (p.Setter != null)
           this.HandleError(Error.DuplicateAccessor);
         SourceContext scntx = this.scanner.CurrentSourceContext;
         this.GetNextToken();
         ParameterList parList = new ParameterList();
         if (paramList != null)
           for (int i = 0, n = paramList.Count; i < n; i++) parList.Add((Parameter)paramList[i].Clone());
         parList.Add(new Parameter(null, ParameterFlags.None, Identifier.For("value"), type, null, null));
         Method m = new Method(parentType, accessorAttrs, new Identifier("set_"+name.ToString()), parList, this.TypeExpressionFor(Token.Void), null);
         m.SourceContext = sc;
         m.Name.SourceContext = scntx;
         if ((accessorFlags & MethodFlags.Static) == 0)
           m.CallingConvention = CallingConventionFlags.HasThis;
         parentType.Members.Add(m);
         m.Flags = accessorFlags|MethodFlags.HideBySig;
         if (interfaceType != null)
           m.ImplementedTypeExpressions = m.ImplementedTypes = new TypeNodeList(interfaceType);
         bool swallowedSemicolonAlready = false;
         bool bodyAllowed = true;
         if (this.currentToken == Token.Semicolon) {
           m.SourceContext.EndPos = this.scanner.endPos;
           this.GetNextToken();
           bodyAllowed = false;
           swallowedSemicolonAlready = true;
         }
         this.ParseMethodContract(m, followers|Token.LeftBrace|Token.Semicolon, ref swallowedSemicolonAlready);
         if (bodyAllowed)
           m.Body = this.ParseBody(m, sc, followersOrRightBrace|Token.Get, swallowedSemicolonAlready);
         else if (!swallowedSemicolonAlready)
           this.SkipSemiColon(followersOrRightBrace|Token.Get);
         p.Setter = m;
         m.DeclaringMember = p;
         accessorFlags = mflags;
         break;}
       case Token.Protected:
       case Token.Internal:
       case Token.Private:
         if (parentType is Interface || interfaceType != null || accessorModifiersAlreadySpecified)
           goto case Token.New;
         accessorFlags = this.ParseAccessorModifiers(mflags);
         accessorModifiersAlreadySpecified = true;
         break;
       case Token.Public:
       case Token.New:
       case Token.Abstract:
       case Token.Sealed:
       case Token.Static:
       case Token.Readonly:
       case Token.Volatile:
       case Token.Virtual:
       case Token.Override:
       case Token.Extern:
       case Token.Unsafe:
         this.HandleError(Error.NoModifiersOnAccessor);
         this.GetNextToken();
         break;
       default:
         this.SkipTo(followersOrRightBrace, Error.GetOrSetExpected);
         break;
     }
   }
   p.SourceContext.EndPos = this.scanner.endPos;
   Error e = Error.GetOrSetExpected;
   if (p.Getter == null && p.Setter == null) p.Parameters = paramList;
   if (p.Getter != null && p.Setter != null) e = Error.ExpectedRightBrace;
   if ((p.Getter == null || p.Setter == null) && this.sink != null && this.currentToken == Token.Identifier){
     p.SourceContext.EndPos = this.scanner.startPos-1;
     KeywordCompletionList keywords;
     if (p.Getter != null)
       keywords = new KeywordCompletionList(this.scanner.GetIdentifier(), new KeywordCompletion("set"));
     else if (p.Setter != null)
       keywords = new KeywordCompletionList(this.scanner.GetIdentifier(), new KeywordCompletion("get"));
     else
       keywords = new KeywordCompletionList(this.scanner.GetIdentifier(), new KeywordCompletion("get"), new KeywordCompletion("set"));
     parentType.Members.Add(keywords);
     this.GetNextToken();
     this.SkipTo(followers);
     return;
   }
   this.ParseBracket(ctx, Token.RightBrace, followers, e);
 }
Пример #5
0
 protected void ValidateElementError(Identifier name, ValidationState context) {
   ArrayList names = ExpectedElements(context, false, true);
   if (names == null) {
     context.HandleError(this.RootNode, name, Error.InvalidElementContentNone, context.Name.ToString(), name.ToString());
   }
   else {
     Debug.Assert(names.Count > 0);
     context.HandleError(this.RootNode, name, Error.InvalidContentExpecting, context.Name.ToString(), name.ToString(), GetExpectedElements(names));
   }
 }
Пример #6
0
 public virtual int ValidateElement(Identifier name, ValidationState context) {
   Debug.Assert(contentType != XmlSchemaContentType.ElementOnly);
   if (contentType == XmlSchemaContentType.Empty) {
     context.HandleError(this.RootNode, context.Name, Error.InvalidElementInEmpty, name.ToString(), context.Name.ToString());
   }
   else if (contentType == XmlSchemaContentType.TextOnly || !anyElement) {
     context.HandleError(this.RootNode, context.Name, Error.InvalidElementInTextOnly, name.ToString(), context.Name.ToString());
   }
   // we treat Mixed as Any
   return -1;
 }
Пример #7
0
 public Namespace(Identifier name, Identifier fullName, AliasDefinitionList aliasDefinitions, UsedNamespaceList usedNamespaces,
   NamespaceList nestedNamespaces, TypeNodeList types)
     : base(NodeType.Namespace)
 {
     this.Name = name;
     this.FullNameId = fullName;
     if(fullName != null)
         this.fullName = fullName.ToString();
     this.AliasDefinitions = aliasDefinitions;
     this.NestedNamespaces = nestedNamespaces;
     this.Types = types;
     this.UsedNamespaces = usedNamespaces;
 }
Пример #8
0
 public Namespace(Identifier name, TypeProvider provideTypes, object providerHandle)
     : base(NodeType.Namespace)
 {
     this.Name = name;
     this.FullNameId = name;
     if(name != null)
         this.fullName = name.ToString();
     this.ProvideTypes = provideTypes;
     this.ProviderHandle = providerHandle;
 }
Пример #9
0
 public Namespace(Identifier name)
     : base(NodeType.Namespace)
 {
     this.Name = name;
     this.FullNameId = name;
     if(name != null)
         this.fullName = name.ToString();
 }