Esempio n. 1
0
        /// <summary>
        /// Writes the member attributes.
        /// </summary>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <param name="overloads">Whether or not the member is overloaded.</param>
        private void WriteMemberAttributes(MemberModifiers memberAttributes, bool overloads)
        {
            if ((memberAttributes & MemberModifiers.New) == MemberModifiers.New)
            {
                Writer.Write(VBKeyword.Shadows);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Constant) == MemberModifiers.Constant)
            {
                Writer.Write(VBKeyword.Constant);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Static) == MemberModifiers.Static)
            {
                Writer.Write(VBKeyword.Shared);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Abstract) == MemberModifiers.Abstract)
            {
                Writer.Write(VBKeyword.MustOverride);
                Writer.Write(' ');
            }

            if (overloads)
            {
                Writer.Write(VBKeyword.Overloads);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Override) == MemberModifiers.Override)
            {
                Writer.Write(VBKeyword.Overrides);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.ReadOnly) == MemberModifiers.ReadOnly)
            {
                Writer.Write(VBKeyword.ReadOnly);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Sealed) == MemberModifiers.Sealed)
            {
                Writer.Write(VBKeyword.NotOverridable);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Virtual) == MemberModifiers.Virtual)
            {
                Writer.Write(VBKeyword.Overridable);
                Writer.Write(' ');
            }
        }
Esempio n. 2
0
        void FieldDecl(MemberModifiers mmod, List<MemberDecl/*!*/>/*!*/ mm)
        {
            Contract.Requires(cce.NonNullElements(mm));
            Attributes attrs = null;
            IToken/*!*/ id;  Type/*!*/ ty;

            while (!(la.kind == 0 || la.kind == 78)) {SynErr(152); Get();}
            Expect(78);
            if (mmod.IsStatic) { SemErr(t, "fields cannot be declared 'static'"); }

            while (la.kind == 46) {
            Attribute(ref attrs);
            }
            FIdentType(out id, out ty);
            mm.Add(new Field(id, id.val, mmod.IsGhost, ty, attrs));
            while (la.kind == 22) {
            Get();
            FIdentType(out id, out ty);
            mm.Add(new Field(id, id.val, mmod.IsGhost, ty, attrs));
            }
            OldSemi();
        }
Esempio n. 3
0
 public MethodBaseWithReturn(Scope scope, MemberModifiers modifiers = MemberModifiers.None)
     : base(scope, modifiers)
 {
 }
Esempio n. 4
0
 protected MethodBase(Scope scope = Scope.Public, MemberModifiers modifiers = MemberModifiers.None)
     : base(scope, modifiers)
 {
 }
Esempio n. 5
0
        /// <summary>
        /// Parses a delegate.
        /// </summary>
        /// <param name="memberName">Member name</param>
        /// <param name="access">Code access</param>
        /// <param name="memberAttributes">Member attributes</param>
        /// <param name="returnType">Return type</param>
        /// <returns>A delegate code element.</returns>
        private DelegateElement ParseDelegate(
            string memberName, CodeAccess access, MemberModifiers memberAttributes, string returnType)
        {
            DelegateElement delegateElement = new DelegateElement();
            delegateElement.Name = memberName;
            delegateElement.Access = access;
            delegateElement.Type = returnType;
            delegateElement.MemberModifiers = memberAttributes;

            int genericIndex = memberName.IndexOf(CSharpSymbol.BeginGeneric);
            bool isGeneric = genericIndex >= 0 && genericIndex < memberName.Length - 1;
            if (isGeneric)
            {
                delegateElement.Name = memberName.Substring(0, genericIndex);
                string typeParameterString = memberName.TrimEnd(CSharpSymbol.EndGeneric).Substring(
                    genericIndex + 1);

                string[] typeParameterNames = typeParameterString.Split(
                    new char[] { CSharpSymbol.AliasSeparator, ' ' },
                    StringSplitOptions.RemoveEmptyEntries);
                foreach (string typeParameterName in typeParameterNames)
                {
                    TypeParameter typeParameter = new TypeParameter();
                    typeParameter.Name = typeParameterName;
                    delegateElement.AddTypeParameter(typeParameter);
                }
            }

            delegateElement.Parameters = this.ParseParameters();

            if (isGeneric)
            {
                ParseTypeParameterConstraints(delegateElement);
            }

            EatChar(CSharpSymbol.EndOfStatement);

            return delegateElement;
        }
Esempio n. 6
0
        /// <summary>
        /// Parses a property.
        /// </summary>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="returnType">Type of the return.</param>
        /// <param name="access">The access.</param>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <returns>A property code element.</returns>
        private PropertyElement ParseProperty(string memberName, string returnType, CodeAccess access, MemberModifiers memberAttributes)
        {
            PropertyElement property = new PropertyElement();

            int indexStart = memberName.IndexOf(CSharpSymbol.BeginAttribute);
            if (indexStart >= 0)
            {
                string indexParameter = memberName.Substring(indexStart).Trim().Trim(
                    CSharpSymbol.BeginAttribute, CSharpSymbol.EndAttribute).Trim();
                property.IndexParameter = indexParameter;
                memberName = memberName.Substring(0, indexStart);
            }

            property.Name = memberName;
            property.Access = access;
            property.Type = returnType;
            property.MemberModifiers = memberAttributes;

            property.BodyText = this.ParseBlock(false, property);

            return property;
        }
Esempio n. 7
0
 protected MemberBase(Scope scope, MemberModifiers modifiers)
 {
     Scope     = scope;
     Modifiers = modifiers;
 }
Esempio n. 8
0
        /// <summary>
        /// Parses a field.
        /// </summary>
        /// <param name="wordList">The word list.</param>
        /// <param name="access">The field access.</param>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <param name="untypedAssignment">Whether or not the field is untyped.</param>
        /// <returns>A field code element.</returns>
        private FieldElement ParseField(
            StringCollection wordList,
            CodeAccess access,
            MemberModifiers memberAttributes,
            bool untypedAssignment)
        {
            FieldElement field = new FieldElement();

            StringBuilder nameBuilder = new StringBuilder(DefaultWordLength);

            foreach (string word in wordList)
            {
                string trimmedWord = word.Trim(' ', VBSymbol.AliasSeparator);

                string upperWord = trimmedWord.ToUpperInvariant();
                if ((!VBKeyword.IsVBKeyword(trimmedWord) ||
                    upperWord == VBKeyword.Custom.ToUpperInvariant() ||
                    upperWord == VBKeyword.Ansi.ToUpperInvariant() ||
                    upperWord == VBKeyword.Unicode.ToUpperInvariant() ||
                    upperWord == VBKeyword.Auto.ToUpperInvariant()) &&
                    trimmedWord.Length > 0)
                {
                    nameBuilder.Append(trimmedWord);
                    nameBuilder.Append(VBSymbol.AliasSeparator);
                    nameBuilder.Append(' ');
                }
            }

            field.Name = nameBuilder.ToString().TrimEnd(VBSymbol.AliasSeparator, ' ');

            EatWhiteSpace();

            if (!untypedAssignment)
            {
                string returnType = CaptureTypeName();
                if (returnType.ToUpperInvariant() == VBKeyword.New.ToUpperInvariant())
                {
                    EatWhiteSpace(WhiteSpaceTypes.SpaceAndTab);
                    field.InitialValue = VBKeyword.New + " " + ReadCodeLine().Trim();
                }
                else
                {
                    field.Type = returnType;
                }
            }

            field.Access = access;
            field.MemberModifiers = memberAttributes;

            EatWhiteSpace(WhiteSpaceTypes.SpaceAndTab);

            bool isAssignment = NextChar == VBSymbol.Assignment || untypedAssignment;
            if (isAssignment)
            {
                if (!untypedAssignment)
                {
                    EatChar(VBSymbol.Assignment);
                }
                string initialValue = ParseInitialValue();

                field.InitialValue = initialValue;
            }

            EatWhiteSpace(WhiteSpaceTypes.SpaceAndTab);

            if (NextChar == VBSymbol.BeginComment)
            {
                EatChar(VBSymbol.BeginComment);

                string commentText = ReadLine().Trim();
                if (commentText.Length > 0)
                {
                    CommentElement comment = new CommentElement(commentText);
                    field.TrailingComment = comment;
                }
            }

            return field;
        }
Esempio n. 9
0
        // delegate-declaration:
        //     attributes?   delegate-modifiers?   delegate  return-type   identifier
        //          type-parameter-list?
        //              (   formal-parameter-list?   )   type-parameter-constraints-clauses?   ;
        //
        // type-parameter-list:
        //     <   type-parameters   >
        private CsType DoParseDelegateDeclaration(CsAttribute[] attrs, MemberModifiers modifiers, Token first, MemberModifiers defaultAccess)
        {
            Token last = m_scanner.Token;
            string rtype = DoParseReturnType();
            int nameOffset = m_scanner.Token.Offset;
            string name = DoParseIdentifier(ref last);

            string gargs = null;
            if (m_scanner.Token.IsPunct("<"))
            {
                gargs = DoScanBody("<", ">", ref last);
            }

            var parms = new List<CsParameter>();
            DoParsePunct("(");
            DoParseFormalParameterList(parms);
            DoParsePunct(")");
            string constraints = DoParseTypeParameterConstraintsClauses();
            last = DoParsePunct(";");

            if (((int) modifiers & CsMember.AccessMask) == 0)
                modifiers |= defaultAccess;

            // ;?
            if (m_scanner.Token.IsPunct(";"))
            {
                last = m_scanner.Token;
                m_scanner.Advance();
            }

            return new CsDelegate(nameOffset, constraints, parms.ToArray(), gargs, rtype, attrs, modifiers, name, first.Offset, last.Offset + last.Length - first.Offset, first.Line);
        }
Esempio n. 10
0
        // operator-declaration:
        //     attributes?   operator-modifiers   operator-declarator   operator-body
        //
        // conversion-operator-declarator:
        //     implicit   operator   type   (   type   identifier   )
        //     explicit   operator   type   (   type   identifier   )
        private void DoParseConversionOperatorDeclaration(bool isImplicit, List<CsMember> members, CsAttribute[] attrs, MemberModifiers modifiers, Token first)
        {
            DoParseKeyword("operator");
            int nameOffset = m_scanner.Token.Offset;
            string type = DoParseType();

            var parms = new List<CsParameter>();
            DoParsePunct("(");
            DoParseFormalParameterList(parms);
            DoParsePunct(")");

            Token last = m_scanner.Token;
            CsBody body = null;
            if (m_scanner.Token.IsPunct(";"))
            {
                m_scanner.Advance();
            }
            else
            {
                Token f = m_scanner.Token;
                Token start = m_scanner.Token;
                DoSkipBody("{", "}", ref f, ref last);
                body = new CsBody(isImplicit ? "op_Implict" : "op_Explict", start.Offset, f.Offset, last.Offset + last.Length - f.Offset, start.Line);
            }

            members.Add(new CsOperator(nameOffset, body, isImplicit, !isImplicit, parms.ToArray(), type, attrs, modifiers, type, first.Offset, last.Offset + last.Length - first.Offset, first.Line));
        }
Esempio n. 11
0
        // constructor-declaration:
        //     attributes?   constructor-modifiers?   constructor-declarator   constructor-body
        //
        // constructor-declarator:
        //     identifier   (   formal-parameter-list?   )   constructor-initializer?
        //
        // constructor-initializer:
        //     :   base   (   argument-list?   )
        //     :   this   (   argument-list?   )
        //
        // constructor-body:
        //     block
        //     ;
        private void DoParseConstructorDeclaration(string name, int nameOffset, List<CsMember> members, CsAttribute[] attrs, MemberModifiers modifiers, Token first)
        {
            var parms = new List<CsParameter>();
            DoParseFormalParameterList(parms);
            DoParsePunct(")");

            string gargs = null;
            int i = name.IndexOf('<');
            if (i > 0)
            {
                int j = name.IndexOf('>');
                gargs = name.Substring(i + 1, j - (i + 1)).TrimAll();
                name = name.Substring(0, i);
            }

            Token last = m_scanner.Token;
            Token open = last;
            if (m_scanner.Token.IsPunct(":"))
            {
                m_scanner.Advance();
                DoParseIdentifier(ref last);
                DoSkipBody("(", ")", ref open, ref last);
            }

            last = m_scanner.Token;
            open = new Token();
            Token start = m_scanner.Token;
            Token close = last;
            if (m_scanner.Token.IsPunct(";"))
            {
                m_scanner.Advance();
            }
            else
            {
                DoSkipBody("{", "}", ref open, ref last);
                close = last;
            }

            CsBody body = open.Length > 0 ? new CsBody(name, start.Offset, open.Offset, close.Offset + close.Length - start.Offset, start.Line) : null;
            members.Add(new CsMethod(nameOffset, body, true, false, null, parms.ToArray(), gargs, "void", attrs, modifiers, name, first.Offset, last.Offset + last.Length - first.Offset, first.Line));
        }
Esempio n. 12
0
        // class-declaration:
        //      attributes?   class-modifiers?   partial?   class   identifier   type-parameter-list?
        //         class-base?   type-parameter-constraints-clauses?   class-body  ;?
        private CsType DoParseClassDeclaration(CsAttribute[] attrs, MemberModifiers modifiers, Token first, MemberModifiers defaultAccess)
        {
            // partial?
            if (m_scanner.Token.IsIdentifier("partial"))
            {
                m_scanner.Advance();
                modifiers |= MemberModifiers.Partial;
            }

            // class
            DoParseKeyword("class");

            // identifier
            Token last = m_scanner.Token;
            int nameOffset = m_scanner.Token.Offset;
            string name = DoParseIdentifier(ref last);

            // type-parameter-list?
            string gargs = null;
            if (m_scanner.Token.IsPunct("<"))
            {
                gargs = DoScanBody("<", ">", ref last);
            }

            // class-base?
            CsBases bases = DoParseInterfaceTypeList(last);

            // type-parameter-constraints-clauses?
            string constraints = DoParseTypeParameterConstraintsClauses();

            // class-body
            var members = new List<CsMember>();
            var types = new List<CsType>();
            Token open = m_scanner.Token;
            Token start = m_scanner.Token;
            DoParseStructBody(members, types, ref open, ref last);
            Token close = last;

            // ;?
            if (m_scanner.Token.IsPunct(";"))
            {
                last = m_scanner.Token;
                m_scanner.Advance();
            }

            CsBody body = new CsBody(name, start.Offset, open.Offset, close.Offset + close.Length - start.Offset, start.Line);
            CsClass result = new CsClass(nameOffset, body, members.ToArray(), types.ToArray(), bases, constraints, gargs, attrs, modifiers, name, first.Offset, last.Offset + last.Length - first.Offset, first.Line);

            return result;
        }
Esempio n. 13
0
        // accessor-declarations:
        //      get-accessor-declaration   set-accessor-declaration?
        //      set-accessor-declaration   get-accessor-declaration?
        //
        // get-accessor-declaration:
        //     attributes?   accessor-modifier?   get   accessor-body
        //
        // set-accessor-declaration:
        //     attributes?   accessor-modifier?   set   accessor-body
        //
        // accessor-body:
        //     block
        //     ;
        private void DoParseAccessorDeclarations(string name, ref bool isGetter, ref bool isSetter, ref CsBody getterBody, ref CsBody setterBody, ref CsAttribute[] getAttrs, ref CsAttribute[] setAttrs, ref MemberModifiers getAccess, ref MemberModifiers setAccess )
        {
            CsAttribute[] attrs = DoParseAttributes();
            MemberModifiers modifiers = DoParseModifiers();

            Token last = m_scanner.Token;
            if (m_scanner.Token.IsIdentifier("get"))
            {
                isGetter = true;
                getAttrs = attrs;
                getAccess = modifiers;
                m_scanner.Advance();

                if (m_scanner.Token.IsPunct(";"))
                {
                    DoParsePunct(";");
                }
                else
                {
                    Token start = m_scanner.Token;
                    Token first = m_scanner.Token;
                    DoSkipBody("{", "}", ref first, ref last);
                    getterBody = new CsBody("get_" + name, start.Offset, first.Offset, last.Offset + last.Length - start.Offset, start.Line);
                }
            }
            else if (m_scanner.Token.IsIdentifier("set"))
            {
                isSetter = true;
                setAttrs = attrs;
                setAccess = modifiers;
                m_scanner.Advance();

                if (m_scanner.Token.IsPunct(";"))
                {
                    DoParsePunct(";");
                }
                else
                {
                    Token first = m_scanner.Token;
                    Token start = m_scanner.Token;
                    DoSkipBody("{", "}", ref first, ref last);
                    setterBody = new CsBody("set_" + name, start.Offset, first.Offset, last.Offset + last.Length - start.Offset, start.Line);
                }
            }
            else
                throw new CsParserException("Expected 'get' or 'set' on line {0}, but found '{1}'", m_scanner.Token.Line, m_scanner.Token.Text());
        }
Esempio n. 14
0
 private void DoParseTypeDeclarationStub(Token first, CsAttribute[] attrs, MemberModifiers modifiers, List<CsType> types, MemberModifiers defaultAccess)
 {
     if (m_scanner.Token.IsIdentifier("enum"))
     {
         m_scanner.Advance();
         CsType type = DoParseEnumDeclaration(attrs, modifiers, first, defaultAccess);
         types.Add(type);
     }
     else if (m_scanner.Token.IsIdentifier("delegate"))
     {
         m_scanner.Advance();
         CsType type = DoParseDelegateDeclaration(attrs, modifiers, first, defaultAccess);
         types.Add(type);
     }
     else if (m_scanner.Token.IsIdentifier("interface") || (m_scanner.Token.IsIdentifier("partial") && m_scanner.LookAhead(1).IsIdentifier("interface")))
     {
         CsType type = DoParseInterfaceDeclaration(attrs, modifiers, first, defaultAccess);
         types.Add(type);
     }
     else if (m_scanner.Token.IsIdentifier("struct") || (m_scanner.Token.IsIdentifier("partial") && m_scanner.LookAhead(1).IsIdentifier("struct")))
     {
         CsType type = DoParseStructDeclaration(attrs, modifiers, first, defaultAccess);
         types.Add(type);
     }
     else if (m_scanner.Token.IsIdentifier("class") || (m_scanner.Token.IsIdentifier("partial") && m_scanner.LookAhead(1).IsIdentifier("class")))
     {
         CsType type = DoParseClassDeclaration(attrs, modifiers, first, defaultAccess);
         types.Add(type);
     }
     else
         throw new CsParserException("Expected 'class', 'struct', 'interface', 'enum', 'delegate', or 'partial' on line {0}, but found '{1}'", m_scanner.Token.Line, m_scanner.Token.Text());
 }
Esempio n. 15
0
        void MethodDecl(MemberModifiers mmod, bool allowConstructor, bool isWithinAbstractModule, out Method/*!*/ m)
        {
            Contract.Ensures(Contract.ValueAtReturn(out m) !=null);
            IToken/*!*/ id = Token.NoToken;
            bool hasName = false;  IToken keywordToken;
            Attributes attrs = null;
            List<TypeParameter/*!*/>/*!*/ typeArgs = new List<TypeParameter/*!*/>();
            List<Formal/*!*/> ins = new List<Formal/*!*/>();
            List<Formal/*!*/> outs = new List<Formal/*!*/>();
            List<MaybeFreeExpression/*!*/> req = new List<MaybeFreeExpression/*!*/>();
            List<FrameExpression/*!*/> mod = new List<FrameExpression/*!*/>();
            List<MaybeFreeExpression/*!*/> ens = new List<MaybeFreeExpression/*!*/>();
            List<Expression/*!*/> dec = new List<Expression/*!*/>();
            Attributes decAttrs = null;
            Attributes modAttrs = null;
            BlockStmt body = null;
            bool isLemma = false;
            bool isConstructor = false;
            bool isIndLemma = false;
            bool isCoLemma = false;
            IToken signatureEllipsis = null;
            IToken bodyStart = Token.NoToken;
            IToken bodyEnd = Token.NoToken;

            while (!(StartOf(10))) {SynErr(158); Get();}
            switch (la.kind) {
            case 84: {
            Get();
            break;
            }
            case 41: {
            Get();
            isLemma = true;
            break;
            }
            case 85: {
            Get();
            isCoLemma = true;
            break;
            }
            case 86: {
            Get();
            isCoLemma = true;
            errors.Warning(t, "the 'comethod' keyword has been deprecated; it has been renamed to 'colemma'");

            break;
            }
            case 40: {
            Get();
            Expect(41);
            isIndLemma = true;
            break;
            }
            case 87: {
            Get();
            if (allowConstructor) {
             isConstructor = true;
            } else {
             SemErr(t, "constructors are allowed only in classes");
            }

            break;
            }
            default: SynErr(159); break;
            }
            keywordToken = t;
            if (isLemma) {
             if (mmod.IsGhost) {
               SemErr(t, "lemmas cannot be declared 'ghost' (they are automatically 'ghost')");
             }
            } else if (isConstructor) {
             if (mmod.IsGhost) {
               SemErr(t, "constructors cannot be declared 'ghost'");
             }
             if (mmod.IsStatic) {
               SemErr(t, "constructors cannot be declared 'static'");
             }
            } else if (isIndLemma) {
             if (mmod.IsGhost) {
               SemErr(t, "inductive lemmas cannot be declared 'ghost' (they are automatically 'ghost')");
             }
            } else if (isCoLemma) {
             if (mmod.IsGhost) {
               SemErr(t, "colemmas cannot be declared 'ghost' (they are automatically 'ghost')");
             }
            }

            while (la.kind == 46) {
            Attribute(ref attrs);
            }
            if (la.kind == 1) {
            NoUSIdent(out id);
            hasName = true;
            }
            if (!hasName) {
             id = keywordToken;
             if (!isConstructor) {
               SemErr(la, "a method must be given a name (expecting identifier)");
             }
            }

            if (la.kind == 50 || la.kind == 52) {
            if (la.kind == 52) {
                GenericParameters(typeArgs);
            }
            Formals(true, !mmod.IsGhost, ins);
            if (la.kind == 83) {
                Get();
                if (isConstructor) { SemErr(t, "constructors cannot have out-parameters"); }
                Formals(false, !mmod.IsGhost, outs);
            }
            } else if (la.kind == 59) {
            Get();
            signatureEllipsis = t;
            } else SynErr(160);
            while (StartOf(11)) {
            MethodSpec(req, mod, ens, dec, ref decAttrs, ref modAttrs);
            }
            if (la.kind == 46) {
            BlockStmt(out body, out bodyStart, out bodyEnd);
            }
            if (!isWithinAbstractModule && DafnyOptions.O.DisallowSoundnessCheating && body == null && ens.Count > 0 && !Attributes.Contains(attrs, "axiom") && !Attributes.Contains(attrs, "imported") && !Attributes.Contains(attrs, "decl") && theVerifyThisFile) {
              SemErr(t, "a method with an ensures clause must have a body, unless given the :axiom attribute");
            }

            IToken tok = theVerifyThisFile ? id : new IncludeToken(id);
            if (isConstructor) {
             m = new Constructor(tok, hasName ? id.val : "_ctor", typeArgs, ins,
                             req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
            } else if (isIndLemma) {
             m = new InductiveLemma(tok, id.val, mmod.IsStatic, typeArgs, ins, outs,
                                req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
            } else if (isCoLemma) {
             m = new CoLemma(tok, id.val, mmod.IsStatic, typeArgs, ins, outs,
                         req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
            } else if (isLemma) {
             m = new Lemma(tok, id.val, mmod.IsStatic, typeArgs, ins, outs,
                       req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
            } else {
             m = new Method(tok, id.val, mmod.IsStatic, mmod.IsGhost, typeArgs, ins, outs,
                        req, new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
            }
            m.BodyStartTok = bodyStart;
            m.BodyEndTok = bodyEnd;
        }
Esempio n. 16
0
        /// <summary>
        /// Writes the member attributes.
        /// </summary>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <param name="overloads">Whether or not the member is overloaded.</param>
        private void WriteMemberAttributes(MemberModifiers memberAttributes, bool overloads)
        {
            if ((memberAttributes & MemberModifiers.New) == MemberModifiers.New)
            {
                Writer.Write(VBKeyword.Shadows);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Constant) == MemberModifiers.Constant)
            {
                Writer.Write(VBKeyword.Constant);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Static) == MemberModifiers.Static)
            {
                Writer.Write(VBKeyword.Shared);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Abstract) == MemberModifiers.Abstract)
            {
                Writer.Write(VBKeyword.MustOverride);
                Writer.Write(' ');
            }

            if (overloads)
            {
                Writer.Write(VBKeyword.Overloads);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Override) == MemberModifiers.Override)
            {
                Writer.Write(VBKeyword.Overrides);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.ReadOnly) == MemberModifiers.ReadOnly)
            {
                Writer.Write(VBKeyword.ReadOnly);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Sealed) == MemberModifiers.Sealed)
            {
                Writer.Write(VBKeyword.NotOverridable);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Virtual) == MemberModifiers.Virtual)
            {
                Writer.Write(VBKeyword.Overridable);
                Writer.Write(' ');
            }
        }
Esempio n. 17
0
        // destructor-declaration:
        //     attributes?  extern?   ~   identifier   (   )    destructor-body
        //
        // destructor-body:
        //     block
        //     ;
        private void DoParseDestructorDeclaration(List<CsMember> members, CsAttribute[] attrs, MemberModifiers modifiers, Token first)
        {
            Token last = first;
            int nameOffset = m_scanner.Token.Offset;
            string name = "~" + DoParseIdentifier(ref last);
            DoParsePunct("(");
            DoParsePunct(")");

            last = m_scanner.Token;
            Token start = m_scanner.Token;
            Token open = new Token();
            Token close = last;
            if (m_scanner.Token.IsPunct(";"))
            {
                m_scanner.Advance();
            }
            else
            {
                DoSkipBody("{", "}", ref open, ref last);
                close = last;
            }

            CsBody body = open.Length > 0 ? new CsBody(name, start.Offset, open.Offset, close.Offset + close.Length - start.Offset, start.Line) : null;
            members.Add(new CsMethod(nameOffset, body, false, true, null, new CsParameter[0], null, "void", attrs, modifiers, name, first.Offset, last.Offset + last.Length - first.Offset, first.Line));
        }
Esempio n. 18
0
        /// <summary>
        /// Parses a property.
        /// </summary>
        /// <param name="access">The access.</param>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <param name="isDefault">Whether or not the property is a default property</param>
        /// <param name="modifyAccess">The modify access.</param>
        /// <param name="inInterface">Whether or not the property is part of an interface.</param>
        /// <returns>A property code element.</returns>
        private PropertyElement ParseProperty(
            CodeAccess access,
            MemberModifiers memberAttributes,
            bool isDefault,
            string modifyAccess,
            bool inInterface)
        {
            PropertyElement property = new PropertyElement();
            property.Name = CaptureWord();
            property.Access = access;
            property.MemberModifiers = memberAttributes;
            property[VBExtendedProperties.Default] = isDefault;
            property[VBExtendedProperties.AccessModifier] = modifyAccess;

            EatLineContinuation();

            if (NextChar == VBSymbol.BeginParameterList)
            {
                string indexParam = this.ParseParams();
                if (indexParam.Length > 0)
                {
                    property.IndexParameter = indexParam;
                }
            }

            EatWord(VBKeyword.As, "Expected As");

            string type = CaptureTypeName();
            if (string.IsNullOrEmpty(type))
            {
                this.OnParseError("Expected return type");
            }

            property.Type = type;

            string[] implements;
            string blockTemp = TryParseImplements(out implements);
            foreach (string implementation in implements)
            {
                InterfaceReference interfaceReference =
                    new InterfaceReference(implementation, InterfaceReferenceType.Interface);
                property.AddImplementation(interfaceReference);
            }

            if ((memberAttributes & MemberModifiers.Abstract) != MemberModifiers.Abstract &&
                !inInterface)
            {
                property.BodyText = (blockTemp + this.ParseBlock(VBKeyword.Property)).Trim();
            }

            return property;
        }
Esempio n. 19
0
        // enum-declaration:
        //     attributes?   enum-modifiers?   enum   identifier   enum-base?   enum-body   ;?
        //
        // enum-base:
        //    :   integral-type
        //
        // enum-body:
        //    {   enum-member-declarations?   }
        //    {   enum-member-declarations   ,   }
        private CsType DoParseEnumDeclaration(CsAttribute[] attrs, MemberModifiers modifiers, Token first, MemberModifiers defaultAccess)
        {
            Token last = first;
            int nameOffset = m_scanner.Token.Offset;
            string name = DoParseIdentifier(ref last);

            string baseType = "int";
            if (m_scanner.Token.IsPunct(":"))
            {
                m_scanner.Advance();
                baseType = DoParseIdentifier(ref last);
            }

            DoParsePunct("{");
            string[] names = DoParseEnumMemberDeclarations();
            last = m_scanner.Token;
            DoParsePunct("}");

            if (((int) modifiers & CsMember.AccessMask) == 0)
                modifiers |= defaultAccess;

            // ;?
            if (m_scanner.Token.IsPunct(";"))
            {
                last = m_scanner.Token;
                m_scanner.Advance();
            }

            return new CsEnum(names, nameOffset, baseType, attrs, modifiers, name, first.Offset, last.Offset + last.Length - first.Offset, first.Line);
        }
Esempio n. 20
0
        /// <summary>
        /// Parses a method.
        /// </summary>
        /// <param name="memberName">Member name.</param>
        /// <param name="access">Code access.</param>
        /// <param name="memberAttributes">Member attributes.</param>
        /// <param name="returnType">Return type.</param>
        /// <param name="isOperator">Whether or not the method is an operator.</param>
        /// <param name="operatorType">Type of the operator.</param>
        /// <returns>Method code element.</returns>
        private MethodElement ParseMethod(
            string memberName,
            CodeAccess access,
            MemberModifiers memberAttributes,
            string returnType,
            bool isOperator,
            OperatorType operatorType)
        {
            MethodElement method = new MethodElement();
            method.Name = memberName;
            method.Access = access;
            method.Type = returnType;
            method.MemberModifiers = memberAttributes;
            method.IsOperator = isOperator;
            method.OperatorType = operatorType;
            if (isOperator &&
                (operatorType == OperatorType.Implicit || operatorType == OperatorType.Explicit))
            {
                method.Type = memberName;
                method.Name = null;
            }

            int genericIndex = memberName.LastIndexOf(CSharpSymbol.BeginGeneric);
            int lastQualifierIndex = memberName.LastIndexOf(CSharpSymbol.AliasQualifier);
            bool isGeneric = !isOperator &&
                (genericIndex >= 0 && genericIndex < memberName.Length - 1 &&
                (lastQualifierIndex < 0 || lastQualifierIndex < genericIndex));
            if (isGeneric)
            {
                method.Name = memberName.Substring(0, genericIndex);
                string typeParameterString = memberName.TrimEnd(CSharpSymbol.EndGeneric).Substring(
                    genericIndex + 1);

                string[] typeParameterNames = typeParameterString.Split(
                    new char[] { CSharpSymbol.AliasSeparator, ' ' },
                    StringSplitOptions.RemoveEmptyEntries);
                foreach (string typeParameterName in typeParameterNames)
                {
                    TypeParameter typeParameter = new TypeParameter();
                    typeParameter.Name = typeParameterName;
                    method.AddTypeParameter(typeParameter);
                }
            }

            method.Parameters = this.ParseParameters();

            if (isGeneric)
            {
                ParseTypeParameterConstraints(method);
            }

            EatWhiteSpace();
            bool endOfStatement = NextChar == CSharpSymbol.EndOfStatement;
            if (endOfStatement)
            {
                TryReadChar();
                method.BodyText = null;
            }
            else
            {
                method.BodyText = this.ParseBlock(true, method);
            }

            return method;
        }
Esempio n. 21
0
        // event-declaration:
        //     attributes?   event-modifiers?   event   type   variable-declarators   ;
        //     attributes?   event-modifiers?   event   type   member-name   {   event-accessor-declarations   }
        //
        // variable-declarators:
        //     variable-declarator
        //     variable-declarators   ,   variable-declarator
        private void DoParseEventDeclaration(List<CsMember> members, CsAttribute[] attrs, MemberModifiers modifiers, Token first)
        {
            string type = DoParseType();

            Token next = m_scanner.LookAhead(1);
            if (next.IsPunct("=") || next.IsPunct(",") || next.IsPunct(";"))
            {
                while (true)
                {
                    DoParseEventDeclarator(type, members, attrs, modifiers, first);

                    if (m_scanner.Token.IsPunct(","))
                        m_scanner.Advance();
                    else
                        break;
                }

                DoParsePunct(";");
            }
            else
            {
                int nameOffset = m_scanner.Token.Offset;
                string name = DoParseMemberName();

                Token last = m_scanner.Token;
                Token open = m_scanner.Token;
                DoSkipBody("{", "}", ref open, ref last);

                members.Add(new CsEvent(nameOffset, type, name, attrs, modifiers, first.Offset, last.Offset + last.Length - first.Offset, first.Line));
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Parses a constructor.
        /// </summary>
        /// <param name="memberName">Member name.</param>
        /// <param name="access">Member accessibility.</param>
        /// <param name="memberAttributes">Member attributes.</param>
        /// <returns>Constructor code element.</returns>
        private ConstructorElement ParseConstructor(string memberName, CodeAccess access, MemberModifiers memberAttributes)
        {
            ConstructorElement constructor = new ConstructorElement();
            constructor.Name = memberName;
            constructor.Access = access;
            constructor.MemberModifiers = memberAttributes;

            constructor.Parameters = this.ParseParameters();

            EatWhiteSpace();

            List<ICommentElement> extraComments = new List<ICommentElement>();
            extraComments.AddRange(ParseComments());

            EatWhiteSpace();

            bool hasReference = TryReadChar(CSharpSymbol.TypeImplements);
            if (hasReference)
            {
                EatWhiteSpace();

                extraComments.AddRange(ParseComments());

                StringBuilder referenceBuilder = new StringBuilder(DefaultWordLength);

                EatWhiteSpace();
                referenceBuilder.Append(CaptureWord());

                EatWhiteSpace();
                string referenceParams =
                    ParseNestedText(CSharpSymbol.BeginParameterList, CSharpSymbol.EndParameterList, true, true);
                referenceBuilder.Append(CSharpSymbol.BeginParameterList);
                referenceBuilder.Append(referenceParams);
                referenceBuilder.Append(CSharpSymbol.EndParameterList);

                constructor.Reference = referenceBuilder.ToString();
            }

            constructor.BodyText = this.ParseBlock(true, constructor);

            foreach (ICommentElement comment in extraComments)
            {
                constructor.AddHeaderComment(comment);
            }

            return constructor;
        }
Esempio n. 23
0
        // variable-declarator:
        //     identifier
        //     identifier   =   variable-initializer
        private void DoParseEventDeclarator(string type, List<CsMember> members, CsAttribute[] attrs, MemberModifiers modifiers, Token first)
        {
            Token last = m_scanner.Token;
            int nameOffset = m_scanner.Token.Offset;
            string name = DoParseIdentifier(ref last);

            if (m_scanner.Token.IsPunct("="))
            {
                DoParsePunct("=");

                // TODO: this won't parse multiple declarators correctly. We could probably handle this
                // by scanning until we hit a semi-colon or a comma not within brackets.
                while (m_scanner.Token.IsValid() && !m_scanner.Token.IsPunct(";"))
                {
                    last = m_scanner.Token;
                    m_scanner.Advance();
                }
            }

            members.Add(new CsEvent(nameOffset, type, name, attrs, modifiers, first.Offset, last.Offset + last.Length - first.Offset, first.Line));
        }
Esempio n. 24
0
        /// <summary>
        /// Writes the modifiers for a member.
        /// </summary>
        /// <param name="memberAttributes">Member modifiers.</param>
        private void WriteMemberAttributes(MemberModifiers memberAttributes)
        {
            if ((memberAttributes & MemberModifiers.Static) == MemberModifiers.Static)
            {
                Writer.Write(CSharpKeyword.Static);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Unsafe) == MemberModifiers.Unsafe)
            {
                Writer.Write(CSharpKeyword.Unsafe);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.New) == MemberModifiers.New)
            {
                Writer.Write(CSharpKeyword.New);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Constant) == MemberModifiers.Constant)
            {
                Writer.Write(CSharpKeyword.Constant);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Abstract) == MemberModifiers.Abstract)
            {
                Writer.Write(CSharpKeyword.Abstract);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.External) == MemberModifiers.External)
            {
                Writer.Write(CSharpKeyword.External);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Override) == MemberModifiers.Override)
            {
                Writer.Write(CSharpKeyword.Override);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.ReadOnly) == MemberModifiers.ReadOnly)
            {
                Writer.Write(CSharpKeyword.ReadOnly);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Sealed) == MemberModifiers.Sealed)
            {
                Writer.Write(CSharpKeyword.Sealed);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Virtual) == MemberModifiers.Virtual)
            {
                Writer.Write(CSharpKeyword.Virtual);
                Writer.Write(' ');
            }
        }
Esempio n. 25
0
        // field-declaration:
        //      attributes?   field-modifiers?   type   variable-declarators  ;
        private void DoParseFieldDeclaration(string type, List<CsMember> members, CsAttribute[] attrs, MemberModifiers modifiers, Token first)
        {
            while (true)
            {
                DoParseFieldDeclarator(type, members, attrs, modifiers, first);

                if (m_scanner.Token.IsPunct(","))
                    m_scanner.Advance();
                else
                    break;
            }

            DoParsePunct(";");
        }
Esempio n. 26
0
 public StatementContainer(Scope scope = Scope.Public, MemberModifiers modifiers = MemberModifiers.None)
     : base(scope, modifiers)
 {
 }
Esempio n. 27
0
        // constant-declarator:
        //     identifier   =   constant-expression
        //
        // field-declaration:
        //      attributes?   field-modifiers?   type   variable-declarators  ;
        //
        // variable-declarator:
        //     identifier
        //     identifier   =   variable-initializer
        private void DoParseFieldDeclarator(string type, List<CsMember> members, CsAttribute[] attrs, MemberModifiers modifiers, Token first)
        {
            Token last = m_scanner.Token;
            int nameOffset = m_scanner.Token.Offset;
            string name = DoParseIdentifier(ref last);

            string value = null;
            if (m_scanner.Token.IsPunct("="))
            {
                DoParsePunct("=");
                value = DoParseExpression(ref last, ";");
            }

            members.Add(new CsField(nameOffset, type, value, attrs, modifiers, name, first.Offset, last.Offset + last.Length - first.Offset, first.Line));
        }
Esempio n. 28
0
        void ClassMemberDecl(List<MemberDecl> mm, bool allowConstructors, bool moduleLevelDecl, bool isWithinAbstractModule)
        {
            Contract.Requires(cce.NonNullElements(mm));
            Method/*!*/ m;
            Function/*!*/ f;
            MemberModifiers mmod = new MemberModifiers();
            IToken staticToken = null, protectedToken = null;

            while (la.kind == 73 || la.kind == 74 || la.kind == 75) {
            if (la.kind == 73) {
                Get();
                mmod.IsGhost = true;
            } else if (la.kind == 74) {
                Get();
                mmod.IsStatic = true; staticToken = t;
            } else {
                Get();
                mmod.IsProtected = true; protectedToken = t;
            }
            }
            if (la.kind == 78) {
            if (moduleLevelDecl) {
             SemErr(la, "fields are not allowed to be declared at the module level; instead, wrap the field in a 'class' declaration");
             mmod.IsStatic = false;
             mmod.IsProtected = false;
            }

            FieldDecl(mmod, mm);
            } else if (IsFunctionDecl()) {
            if (moduleLevelDecl && staticToken != null) {
             errors.Warning(staticToken, "module-level functions are always non-instance, so the 'static' keyword is not allowed here");
             mmod.IsStatic = false;
            }

            FunctionDecl(mmod, isWithinAbstractModule, out f);
            mm.Add(f);
            } else if (StartOf(6)) {
            if (moduleLevelDecl && staticToken != null) {
             errors.Warning(staticToken, "module-level methods are always non-instance, so the 'static' keyword is not allowed here");
             mmod.IsStatic = false;
            }
            if (protectedToken != null) {
             SemErr(protectedToken, "only functions, not methods, can be declared 'protected'");
             mmod.IsProtected = false;
            }

            MethodDecl(mmod, allowConstructors, isWithinAbstractModule, out m);
            mm.Add(m);
            } else SynErr(151);
        }
Esempio n. 29
0
 private bool DoShouldAdd(bool isInstance, bool isStatic, MemberModifiers modifiers)
 {
     if ((modifiers & MemberModifiers.Static) == 0 && (modifiers & MemberModifiers.Const) == 0)
         return isInstance;
     else
         return isStatic;
 }
Esempio n. 30
0
        void FunctionDecl(MemberModifiers mmod, bool isWithinAbstractModule, out Function/*!*/ f)
        {
            Contract.Ensures(Contract.ValueAtReturn(out f)!=null);
            Attributes attrs = null;
            IToken/*!*/ id = Token.NoToken;  // to please compiler
            List<TypeParameter/*!*/> typeArgs = new List<TypeParameter/*!*/>();
            List<Formal/*!*/> formals = new List<Formal/*!*/>();
            Type/*!*/ returnType = new BoolType();
            List<Expression/*!*/> reqs = new List<Expression/*!*/>();
            List<Expression/*!*/> ens = new List<Expression/*!*/>();
            List<FrameExpression/*!*/> reads = new List<FrameExpression/*!*/>();
            List<Expression/*!*/> decreases;
            Expression body = null;
            bool isPredicate = false; bool isIndPredicate = false; bool isCoPredicate = false;
            bool isFunctionMethod = false;
            IToken bodyStart = Token.NoToken;
            IToken bodyEnd = Token.NoToken;
            IToken signatureEllipsis = null;
            bool missingOpenParen;

            if (la.kind == 38) {
            Get();
            if (la.kind == 84) {
                Get();
                isFunctionMethod = true;
            }
            if (mmod.IsGhost) { SemErr(t, "functions cannot be declared 'ghost' (they are ghost by default)"); }

            while (la.kind == 46) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (la.kind == 50 || la.kind == 52) {
                if (la.kind == 52) {
                    GenericParameters(typeArgs);
                }
                Formals(true, isFunctionMethod, formals);
                Expect(21);
                Type(out returnType);
            } else if (la.kind == 59) {
                Get();
                signatureEllipsis = t;
            } else SynErr(153);
            } else if (la.kind == 39) {
            Get();
            isPredicate = true;
            if (la.kind == 84) {
                Get();
                isFunctionMethod = true;
            }
            if (mmod.IsGhost) { SemErr(t, "predicates cannot be declared 'ghost' (they are ghost by default)"); }

            while (la.kind == 46) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (StartOf(8)) {
                if (la.kind == 52) {
                    GenericParameters(typeArgs);
                }
                missingOpenParen = true;
                if (la.kind == 50) {
                    Formals(true, isFunctionMethod, formals);
                    missingOpenParen = false;
                }
                if (missingOpenParen) { errors.Warning(t, "with the new support of higher-order functions in Dafny, parentheses-less predicates are no longer supported; in the new syntax, parentheses are required for the declaration and uses of predicates, even if the predicate takes no additional arguments"); }
                if (la.kind == 21) {
                    Get();
                    SemErr(t, "predicates do not have an explicitly declared return type; it is always bool");
                }
            } else if (la.kind == 59) {
                Get();
                signatureEllipsis = t;
            } else SynErr(154);
            } else if (la.kind == 40) {
            Get();
            Expect(39);
            isIndPredicate = true;
            if (mmod.IsGhost) { SemErr(t, "inductive predicates cannot be declared 'ghost' (they are ghost by default)"); }

            while (la.kind == 46) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (la.kind == 50 || la.kind == 52) {
                if (la.kind == 52) {
                    GenericParameters(typeArgs);
                }
                Formals(true, isFunctionMethod, formals);
                if (la.kind == 21) {
                    Get();
                    SemErr(t, "inductive predicates do not have an explicitly declared return type; it is always bool");
                }
            } else if (la.kind == 59) {
                Get();
                signatureEllipsis = t;
            } else SynErr(155);
            } else if (la.kind == 42) {
            Get();
            isCoPredicate = true;
            if (mmod.IsGhost) { SemErr(t, "copredicates cannot be declared 'ghost' (they are ghost by default)"); }

            while (la.kind == 46) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (la.kind == 50 || la.kind == 52) {
                if (la.kind == 52) {
                    GenericParameters(typeArgs);
                }
                Formals(true, isFunctionMethod, formals);
                if (la.kind == 21) {
                    Get();
                    SemErr(t, "copredicates do not have an explicitly declared return type; it is always bool");
                }
            } else if (la.kind == 59) {
                Get();
                signatureEllipsis = t;
            } else SynErr(156);
            } else SynErr(157);
            decreases = isIndPredicate || isCoPredicate ? null : new List<Expression/*!*/>();
            while (StartOf(9)) {
            FunctionSpec(reqs, reads, ens, decreases);
            }
            if (la.kind == 46) {
            FunctionBody(out body, out bodyStart, out bodyEnd);
            }
            if (!isWithinAbstractModule && DafnyOptions.O.DisallowSoundnessCheating && body == null && ens.Count > 0 && !Attributes.Contains(attrs, "axiom") && !Attributes.Contains(attrs, "imported")) {
              SemErr(t, "a function with an ensures clause must have a body, unless given the :axiom attribute");
            }

            IToken tok = theVerifyThisFile ? id : new IncludeToken(id);
            if (isPredicate) {
              f = new Predicate(tok, id.val, mmod.IsStatic, mmod.IsProtected, !isFunctionMethod, typeArgs, formals,
                            reqs, reads, ens, new Specification<Expression>(decreases, null), body, Predicate.BodyOriginKind.OriginalOrInherited, attrs, signatureEllipsis);
            } else if (isIndPredicate) {
              f = new InductivePredicate(tok, id.val, mmod.IsStatic, mmod.IsProtected, typeArgs, formals,
                                     reqs, reads, ens, body, attrs, signatureEllipsis);
            } else if (isCoPredicate) {
              f = new CoPredicate(tok, id.val, mmod.IsStatic, mmod.IsProtected, typeArgs, formals,
                              reqs, reads, ens, body, attrs, signatureEllipsis);
            } else {
              f = new Function(tok, id.val, mmod.IsStatic, mmod.IsProtected, !isFunctionMethod, typeArgs, formals, returnType,
                           reqs, reads, ens, new Specification<Expression>(decreases, null), body, attrs, signatureEllipsis);
            }
            f.BodyStartTok = bodyStart;
            f.BodyEndTok = bodyEnd;
            theBuiltIns.CreateArrowTypeDecl(formals.Count);
            if (isIndPredicate || isCoPredicate) {
             // also create an arrow type for the corresponding prefix predicate
             theBuiltIns.CreateArrowTypeDecl(formals.Count + 1);
            }
        }
Esempio n. 31
0
 public Method(string name, Scope scope = Scope.Public, MemberModifiers modifiers = MemberModifiers.None)
     : base(scope, modifiers)
 {
     Name = name;
 }
Esempio n. 32
0
        /// <summary>
        /// Writes the modifiers for a member.
        /// </summary>
        /// <param name="memberAttributes">Member modifiers.</param>
        private void WriteMemberAttributes(MemberModifiers memberAttributes)
        {
            if ((memberAttributes & MemberModifiers.Static) == MemberModifiers.Static)
            {
                Writer.Write(CSharpKeyword.Static);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Unsafe) == MemberModifiers.Unsafe)
            {
                Writer.Write(CSharpKeyword.Unsafe);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.New) == MemberModifiers.New)
            {
                Writer.Write(CSharpKeyword.New);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Constant) == MemberModifiers.Constant)
            {
                Writer.Write(CSharpKeyword.Constant);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Abstract) == MemberModifiers.Abstract)
            {
                Writer.Write(CSharpKeyword.Abstract);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.External) == MemberModifiers.External)
            {
                Writer.Write(CSharpKeyword.External);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Override) == MemberModifiers.Override)
            {
                Writer.Write(CSharpKeyword.Override);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.ReadOnly) == MemberModifiers.ReadOnly)
            {
                Writer.Write(CSharpKeyword.ReadOnly);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Sealed) == MemberModifiers.Sealed)
            {
                Writer.Write(CSharpKeyword.Sealed);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Virtual) == MemberModifiers.Virtual)
            {
                Writer.Write(CSharpKeyword.Virtual);
                Writer.Write(' ');
            }

            if ((memberAttributes & MemberModifiers.Async) == MemberModifiers.Async)
            {
                Writer.Write(CSharpKeyword.Async);
                Writer.Write(' ');
            }
        }
Esempio n. 33
0
 public Field(string name, TypeRep typeRep, Scope scope = Scope.Public, bool readOnly = false, MemberModifiers modifiers = MemberModifiers.None)
     : base(scope, modifiers)
 {
     Name     = name;
     ReadOnly = readOnly;
     TypeRep  = typeRep;
 }
Esempio n. 34
0
        /// <summary>
        /// Parses an event.
        /// </summary>
        /// <param name="access">The event access.</param>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <param name="isCustom">Whether or not the event is custom.</param>
        /// <returns>An event code element.</returns>
        private EventElement ParseEvent(
            CodeAccess access, MemberModifiers memberAttributes, bool isCustom)
        {
            EventElement eventElement = new EventElement();
            string name = CaptureWord();
            eventElement.Name = name;
            eventElement.Access = access;
            eventElement.MemberModifiers = memberAttributes;

            EatWhiteSpace(WhiteSpaceTypes.SpaceAndTab);
            if (NextChar == VBSymbol.BeginParameterList)
            {
                eventElement.Parameters = ParseNestedText(
                    VBSymbol.BeginParameterList, VBSymbol.EndParameterList, true, true);
            }
            else
            {
                EatWord(VBKeyword.As);

                string eventType = CaptureTypeName();
                if (string.IsNullOrEmpty(eventType))
                {
                    this.OnParseError("Expected type identifier");
                }
                eventElement.Type = eventType;
            }

            string[] implements;
            string blockTemp = TryParseImplements(out implements);
            foreach (string implementation in implements)
            {
                InterfaceReference interfaceReference =
                    new InterfaceReference(implementation, InterfaceReferenceType.Interface);
                eventElement.AddImplementation(interfaceReference);
            }

            if (isCustom)
            {
                eventElement.BodyText = (blockTemp + this.ParseBlock(VBKeyword.Event)).Trim();
            }

            return eventElement;
        }
Esempio n. 35
0
        /// <summary>
        /// Parses an event.
        /// </summary>
        /// <param name="access">Member accessibility.</param>
        /// <param name="memberAttributes">Member modifiers.</param>
        /// <returns>Event code element.</returns>
        private EventElement ParseEvent(CodeAccess access, MemberModifiers memberAttributes)
        {
            EventElement eventElement = new EventElement();

            StringBuilder eventSignature = new StringBuilder();
            while (NextChar != CSharpSymbol.EndOfStatement &&
                NextChar != CSharpSymbol.BeginBlock)
            {
                if (TryReadChar())
                {
                    eventSignature.Append(CurrentChar);
                }
            }

            string[] words = eventSignature.ToString().Split(WhiteSpaceCharacters, StringSplitOptions.RemoveEmptyEntries);
            StringCollection wordList = new StringCollection();
            wordList.AddRange(words);
            string name = null;
            string type = null;

            GetMemberNameAndType(wordList, out name, out type);

            eventElement.Type = type;
            eventElement.Name = name;
            eventElement.Access = access;
            eventElement.MemberModifiers = memberAttributes;

            EatWhiteSpace();

            char nextChar = NextChar;
            if (nextChar == CSharpSymbol.EndOfStatement)
            {
                EatChar(CSharpSymbol.EndOfStatement);
            }
            else
            {
                eventElement.BodyText = this.ParseBlock(true, eventElement);
            }

            return eventElement;
        }
Esempio n. 36
0
        /// <summary>
        /// Parses a method.
        /// </summary>
        /// <param name="access">The member access.</param>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <param name="isFunction">Whether or not the method is a function.</param>
        /// <param name="isDelegate">Whether or not the method is a delegate.</param>
        /// <param name="isOperator">Whether or not the method is an operator.</param>
        /// <param name="operatorType">Type of the operator.</param>
        /// <param name="inInterface">Whether or not the method is in an interface.</param>
        /// <param name="isExternal">Whether or not the method is external.</param>
        /// <param name="externalModifier">The external modifier.</param>
        /// <returns>A method element.</returns>
        private MethodElement ParseMethod(
            CodeAccess access,
            MemberModifiers memberAttributes,
            bool isFunction,
            bool isDelegate,
            bool isOperator,
            OperatorType operatorType,
            bool inInterface,
            bool isExternal,
            string externalModifier)
        {
            MethodElement method = new MethodElement();

            method.Name = CaptureWord();
            if (isOperator)
            {
                // Handle greater than/less than for the method name since these will get
                // excluded with < and > being alias breaks (needed by attributes).
                while (NextChar == VBSymbol.BeginAttribute || NextChar == VBSymbol.EndAttribute)
                {
                    TryReadChar();
                    method.Name += CurrentChar + CaptureWord();
                }
            }

            method.Access = access;
            method.MemberModifiers = memberAttributes;

            method.IsOperator = isOperator;
            method.OperatorType = operatorType;
            method[VBExtendedProperties.ExternalModifier] = externalModifier;

            if (isExternal)
            {
                method.MemberModifiers = method.MemberModifiers | MemberModifiers.External;

                EatLineContinuation();

                EatWord(VBKeyword.Lib);

                EatLineContinuation();

                EatChar(VBSymbol.BeginString);
                string library = CaptureWord().TrimEnd(VBSymbol.BeginString);

                method[VBExtendedProperties.ExternalLibrary] = library;

                EatLineContinuation();

                if (NextChar != VBSymbol.BeginParameterList)
                {
                    EatLineContinuation();

                    EatWord(VBKeyword.Alias);

                    EatLineContinuation();

                    EatChar(VBSymbol.BeginString);
                    string alias = CaptureWord().TrimEnd(VBSymbol.BeginString);

                    method[VBExtendedProperties.ExternalAlias] = alias;
                }
            }

            EatLineContinuation();

            EatChar(VBSymbol.BeginParameterList);
            EatWhiteSpace();
            string paramsTemp = string.Empty;

            if (char.ToLower(NextChar) == char.ToLower(VBKeyword.Of[0]))
            {
                TryReadChar();
                paramsTemp += CurrentChar;

                if (char.ToLower(NextChar) == char.ToLower(VBKeyword.Of[1]))
                {
                    TryReadChar();
                    paramsTemp = string.Empty;

                    this.ParseTypeParameters(method);

                    EatChar(VBSymbol.BeginParameterList);
                    EatWhiteSpace();
                }
            }

            method.Parameters = paramsTemp + ParseNestedText(
                VBSymbol.BeginParameterList, VBSymbol.EndParameterList, false, false);

            if (isFunction || isOperator)
            {
                EatLineContinuation();
                if (char.ToUpper(NextChar) == VBKeyword.As[0])
                {
                    EatWord(VBKeyword.As);
                    method.Type = CaptureTypeName();
                }
                else
                {
                    method.Type = string.Empty;
                }
            }

            EatWhiteSpace();

            string[] implements;
            string[] handles;
            bool parseHandles = !(isFunction || isOperator || isDelegate);
            string blockTemp = TryParseImplementsOrHandles(out implements, out handles, parseHandles);
            if (parseHandles)
            {
                method[VBExtendedProperties.Handles] = handles;
            }

            foreach (string implementation in implements)
            {
                InterfaceReference interfaceReference =
                     new InterfaceReference(implementation, InterfaceReferenceType.Interface);
                method.AddImplementation(interfaceReference);
            }

            if ((memberAttributes & MemberModifiers.Abstract) != MemberModifiers.Abstract &&
                !inInterface && !isExternal)
            {
                if (isFunction || isOperator)
                {
                    if (isOperator)
                    {
                        method.BodyText = (blockTemp + this.ParseBlock(VBKeyword.Operator)).Trim();
                    }
                    else if (!isDelegate)
                    {
                        method.BodyText = (blockTemp + this.ParseBlock(VBKeyword.Function)).Trim();
                    }
                }
                else if (!isDelegate)
                {
                    method.BodyText = (blockTemp + this.ParseBlock(VBKeyword.Sub)).Trim();
                }
            }

            return method;
        }
Esempio n. 37
0
        /// <summary>
        /// Parses a field.
        /// </summary>
        /// <param name="isAssignment">Has field assignment.</param>
        /// <param name="access">Field access.</param>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="returnType">Return type.</param>
        /// <param name="isVolatile">Whether or not the field is volatile.</param>
        /// <param name="isFixed">Whether or not the field is fixed.</param>
        /// <returns>A field code element.</returns>
        private FieldElement ParseField(
            bool isAssignment,
            CodeAccess access,
            MemberModifiers memberAttributes,
            string memberName,
            string returnType,
            bool isVolatile,
            bool isFixed)
        {
            FieldElement field = new FieldElement();
            field.Name = memberName;
            field.Type = returnType;
            field.Access = access;
            field.MemberModifiers = memberAttributes;
            field.IsVolatile = isVolatile;
            field[CSharpExtendedProperties.Fixed] = isFixed;

            if (isAssignment)
            {
                string initialValue = ParseInitialValue();
                field.InitialValue = initialValue;
            }

            EatWhiteSpace(WhiteSpaceTypes.SpaceAndTab);
            if (NextChar == CSharpSymbol.BeginComment)
            {
                EatChar(CSharpSymbol.BeginComment);
                if (NextChar == CSharpSymbol.BeginComment)
                {
                    field.TrailingComment = ParseCommentLine();
                }
                else if (NextChar == CSharpSymbol.BlockCommentModifier)
                {
                    field.TrailingComment = ParseCommentBlock();
                }
            }
            return field;
        }
Esempio n. 38
0
        /// <summary>
        /// Parses a delegate.
        /// </summary>
        /// <param name="access">The member access.</param>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <returns>Delegate code element.</returns>
        private DelegateElement ParseDelegate(
            CodeAccess access, MemberModifiers memberAttributes)
        {
            string delegateType = CaptureWord();

            bool isFunction = false;
            switch (VBKeyword.Normalize(delegateType))
            {
                case VBKeyword.Sub:
                    isFunction = false;
                    break;

                case VBKeyword.Function:
                    isFunction = true;
                    break;

                default:
                    this.OnParseError(
                        "Expected Sub or Function for delegate declaration");
                    break;
            }

            MethodElement methodElement = ParseMethod(
                access, memberAttributes, isFunction, true, false, OperatorType.None, false, false, null);

            DelegateElement delegateElement = new DelegateElement();
            delegateElement.Name = methodElement.Name;
            delegateElement.Access = methodElement.Access;
            delegateElement.MemberModifiers = methodElement.MemberModifiers;
            delegateElement.Parameters = methodElement.Parameters;
            delegateElement.BodyText = methodElement.BodyText;
            if (isFunction)
            {
                delegateElement.Type = methodElement.Type;
            }

            foreach (TypeParameter typeParameter in methodElement.TypeParameters)
            {
                delegateElement.AddTypeParameter(typeParameter);
            }

            return delegateElement;
        }
Esempio n. 39
0
 public Constructor(TypeRep containingType, Scope scope = Scope.Public, MemberModifiers modifiers = MemberModifiers.None)
     :  base(scope, modifiers)
 {
     ContainingType = containingType;
 }