Esempio n. 1
0
        internal void IncludeCompilationUnitUsingClauses() {
            CompilationUnitNode compilationUnit = (CompilationUnitNode)parent;
            if (compilationUnit.UsingClauses.Count != 0) {
                ParseNodeList mergedUsings = new ParseNodeList();
                mergedUsings.Append(compilationUnit.UsingClauses);

                if (_usingClauses.Count != 0) {
                    mergedUsings.Append(_usingClauses);
                }

                _usingClauses = GetParentedNodeList(mergedUsings);
            }
        }
Esempio n. 2
0
        internal void IncludeCompilationUnitUsingClauses()
        {
            CompilationUnitNode compilationUnit = (CompilationUnitNode)parent;

            if (compilationUnit.UsingClauses.Count != 0)
            {
                ParseNodeList mergedUsings = new ParseNodeList();
                mergedUsings.Append(compilationUnit.UsingClauses);

                if (_usingClauses.Count != 0)
                {
                    mergedUsings.Append(_usingClauses);
                }

                _usingClauses = GetParentedNodeList(mergedUsings);
            }
        }
Esempio n. 3
0
        internal override void MergePartialType(CustomTypeNode partialTypeNode)
        {
            base.MergePartialType(partialTypeNode);

            if (partialTypeNode._baseTypes.Count > 0)
            {
                _baseTypes.Append(GetParentedNodeList(partialTypeNode._baseTypes));
            }
        }
Esempio n. 4
0
        public static ParseNodeList GetAttributeList(ParseNodeList attributeBlocks) {
            if ((attributeBlocks == null)  || (attributeBlocks.Count == 0)) {
                return attributeBlocks;
            }

            ParseNodeList attributes = new ParseNodeList();
            foreach (AttributeBlockNode attributeBlock in attributeBlocks) {
                ParseNodeList localAttributes = attributeBlock.Attributes;
                if (localAttributes.Count != 0) {
                    attributes.Append(localAttributes);
                }
            }

            return attributes;
        }
Esempio n. 5
0
        private void BuildCodeModel() {
            _compilationUnitList = new ParseNodeList();

            CodeModelBuilder codeModelBuilder = new CodeModelBuilder(_options, this);
            CodeModelValidator codeModelValidator = new CodeModelValidator(this);
            CodeModelProcessor validationProcessor = new CodeModelProcessor(codeModelValidator, _options);

            foreach (IStreamSource source in _options.Sources) {
                CompilationUnitNode compilationUnit = codeModelBuilder.BuildCodeModel(source);
                if (compilationUnit != null) {
                    validationProcessor.Process(compilationUnit);

                    _compilationUnitList.Append(compilationUnit);
                }
            }
        }
Esempio n. 6
0
        private ParseNodeList GetNamespaces(ParseNodeList members) {
            ParseNodeList namespaceList = new ParseNodeList();

            foreach (ParseNode memberNode in members) {
                NamespaceNode namespaceNode = memberNode as NamespaceNode;

                if (namespaceNode == null) {
                    // Top-level type nodes are turned into children of a namespace with
                    // an empty name.

                    Token nsToken = new Token(TokenType.Namespace, memberNode.Token.SourcePath, memberNode.Token.Position);
                    namespaceNode = new NamespaceNode(nsToken, String.Empty, _usingClauses, new ParseNodeList(memberNode));
                }

                namespaceList.Append(namespaceNode);
            }

            return namespaceList;
        }
Esempio n. 7
0
        public static ParseNodeList GetAttributeList(ParseNodeList attributeBlocks)
        {
            if ((attributeBlocks == null) || (attributeBlocks.Count == 0))
            {
                return(attributeBlocks);
            }

            ParseNodeList attributes = new ParseNodeList();

            foreach (AttributeBlockNode attributeBlock in attributeBlocks)
            {
                ParseNodeList localAttributes = attributeBlock.Attributes;
                if (localAttributes.Count != 0)
                {
                    attributes.Append(localAttributes);
                }
            }

            return(attributes);
        }
Esempio n. 8
0
        private ParseNodeList GetNamespaces(ParseNodeList members)
        {
            ParseNodeList namespaceList = new ParseNodeList();

            foreach (ParseNode memberNode in members)
            {
                NamespaceNode namespaceNode = memberNode as NamespaceNode;

                if (namespaceNode == null)
                {
                    // Top-level type nodes are turned into children of a namespace with
                    // an empty name.

                    Token nsToken = new Token(TokenType.Namespace, memberNode.Token.SourcePath, memberNode.Token.Position);
                    namespaceNode = new NamespaceNode(nsToken, String.Empty, _usingClauses, new ParseNodeList(memberNode));
                }

                namespaceList.Append(namespaceNode);
            }

            return(namespaceList);
        }
Esempio n. 9
0
        internal virtual void MergePartialType(CustomTypeNode partialTypeNode)
        {
            Debug.Assert(Name == partialTypeNode.Name);

            if (partialTypeNode._attributes.Count > 0)
            {
                _attributes.Append(GetParentedNodeList(partialTypeNode._attributes));
            }

            if ((partialTypeNode.Modifiers & Modifiers.PartialModifiers) != 0)
            {
                _modifiers |= (partialTypeNode.Modifiers & Modifiers.PartialModifiers);
            }

            if (partialTypeNode._typeParameters.Count > 0)
            {
                _typeParameters.Append(GetParentedNodeList(partialTypeNode._typeParameters));
            }

            if (partialTypeNode._constraintClauses.Count > 0)
            {
                _constraintClauses.Append(GetParentedNodeList(partialTypeNode._constraintClauses));
            }
        }
Esempio n. 10
0
 private ParseNodeList ParseClassOrStructMembers() {
     ParseNodeList list = new ParseNodeList();
     TokenType type = PeekType();
     while (type != TokenType.CloseCurly && type != TokenType.EOF) {
         int mark = Mark();
         list.Append(ParseClassOrStructMember());
         if (mark == Mark()) {
             // didn't consume any tokens!
             // ensure we make some progress
             NextToken();
         }
         type = PeekType();
     }
     return list;
 }
Esempio n. 11
0
        private ParseNode ParseAttributeBlock() {
            Token token = Eat(TokenType.OpenSquare);
            AttributeTargets location;
            if (PeekType() <= TokenType.Identifier && PeekType(1) == TokenType.Colon) {
                location = CheckAttributeTargets(NextToken());
                Eat(TokenType.Colon);
            }
            else {
                location = 0;
            }

            ParseNodeList list = new ParseNodeList();
            do {
                list.Append(ParseAttribute());
            } while ((null != EatOpt(TokenType.Comma)) && (PeekType() != TokenType.CloseSquare));
            Eat(TokenType.CloseSquare);

            return new AttributeBlockNode(
                        token,
                        location,
                        list);
        }
Esempio n. 12
0
        private ParseNodeList ParseAttributes() {
            ParseNodeList list = new ParseNodeList();

            while (PeekType() == TokenType.OpenSquare) {
                list.Append(ParseAttributeBlock());
            }

            return list;
        }
Esempio n. 13
0
        private TryNode ParseTry() {
            Token token = Eat(TokenType.Try);
            ParseNode body = ParseBlock();

            ParseNodeList catchClauses = new ParseNodeList();
            while (PeekType() == TokenType.Catch) {
                Token catchToken = Eat(TokenType.Catch);
                ParseNode type;
                AtomicNameNode name;

                if (PeekType() == TokenType.OpenParen) {
                    Eat(TokenType.OpenParen);
                    type = ParseType();
                    if (PeekType() == TokenType.Identifier) {
                        name = ParseIdentifier();
                    }
                    else {
                        name = null;
                    }
                    Eat(TokenType.CloseParen);
                }
                else {
                    type = null;
                    name = null;
                }

                catchClauses.Append(new CatchNode(
                                        catchToken,
                                        type,
                                        name,
                                        ParseBlock()));
            }

            ParseNode finallyClause;
            if (PeekType() == TokenType.Finally) {
                Eat(TokenType.Finally);
                finallyClause = ParseBlock();
            }
            else {
                finallyClause = null;
            }

            return new TryNode(
                            token,
                            body,
                            catchClauses,
                            finallyClause);
        }
Esempio n. 14
0
        private ParseNodeList ParseFieldInitializers(bool isFixed) {
            ParseNodeList list = new ParseNodeList();
            do {
                if (!isFixed)
                    list.Append(new VariableInitializerNode(ParseIdentifier(), ParseVariableInitializer()));
                else
                    list.Append(new VariableInitializerNode(ParseIdentifier(), ParseFixedArrayDimension()));
            } while (EatOpt(TokenType.Comma) != null);

            return list;
        }
Esempio n. 15
0
        private BlockStatementNode ParseBlock() {
            Token token = PeekToken();

            ParseNodeList statements = new ParseNodeList();
            Eat(TokenType.OpenCurly);

            TokenType type = PeekType();
            while (type != TokenType.CloseCurly && type != TokenType.EOF) {
                int mark = Mark();
                statements.Append(ParseStatement());

                // ensure we make progress in an error case
                if (mark == Mark()) {
                    NextToken();
                }

                type = PeekType();
            }
            Eat(TokenType.CloseCurly);

            return new BlockStatementNode(token, statements);
        }
Esempio n. 16
0
        // namespace-or-type-name
        private NameNode ParseNamespaceOrTypeName() {
            Token token = PeekToken();
            NameNode name = ParseAliasQualifiedName(false);

            if ((PeekType() == TokenType.Dot || PeekType() == TokenType.ColonColon) && PeekType(1) == TokenType.Identifier) {
                ParseNodeList list = new ParseNodeList(name);
                do {
                    EatDotOrColonColon();
                    list.Append(ParseSimpleName(false));
                }
                while (PeekType() == TokenType.Dot && PeekType(1) == TokenType.Identifier);

                return new MultiPartNameNode(token, list);
            }
            else {
                return name;
            }
        }
Esempio n. 17
0
        private ParseNodeList ParseExternAliases() {
            ParseNodeList list = new ParseNodeList();
            Token token;
            while (null != (token = EatOpt(TokenType.Extern))) {
                EatContextualKeyword(aliasName);
                list.Append(
                        new ExternAliasNode(
                            token,
                            ParseIdentifier()));
                Eat(TokenType.Semicolon);
            }

            return list;
        }
Esempio n. 18
0
 private ParseNodeList ParseTypeArgumentList() {
     ParseNodeList returnValue = new ParseNodeList();
     Eat(TokenType.OpenAngle);
     do {
         returnValue.Append(ParseType());
     } while (null != EatOpt(TokenType.Comma));
     Eat(TokenType.CloseAngle);
     return returnValue;
 }
Esempio n. 19
0
        // qualified-name
        private NameNode ParseMultiPartName() {
            Token token = PeekToken();
            NameNode name = ParseIdentifier();
            if (PeekType() == TokenType.Dot && PeekType(1) == TokenType.Identifier) {
                ParseNodeList list = new ParseNodeList(name);
                do {
                    Eat(TokenType.Dot);
                    list.Append(ParseIdentifier());
                }
                while (PeekType() == TokenType.Dot && PeekType(1) == TokenType.Identifier);

                return new MultiPartNameNode(token, list);
            }
            else {
                return name;
            }
        }
Esempio n. 20
0
        private ExpressionListNode ParseParenArgumentList() {
            Token token = PeekToken();

            Eat(TokenType.OpenParen);
            ParseNodeList list = new ParseNodeList();

            while (PeekType() != TokenType.CloseParen) {
                list.Append(ParseArgument());
                if (null == EatOpt(TokenType.Comma)) {
                    break;
                }
            }

            Eat(TokenType.CloseParen);

            return new ExpressionListNode(token, list);
        }
Esempio n. 21
0
        private ArrayInitializerNode ParseArrayInitializer() {
            Token token = Eat(TokenType.OpenCurly);

            ParseNodeList list = new ParseNodeList();
            while (PeekType() != TokenType.CloseCurly && PeekType() != TokenType.EOF) {
                if (PeekType() == TokenType.OpenCurly) {
                    list.Append(ParseArrayInitializer());
                }
                else {
                    list.Append(ParseExpression());
                }
                if (null == EatOpt(TokenType.Comma)) {
                    break;
                }
            }
            Eat(TokenType.CloseCurly);

            return new ArrayInitializerNode(token, list);
        }
Esempio n. 22
0
        // using-directives
        private ParseNodeList ParseUsingClauses() {
            ParseNodeList list = new ParseNodeList();
            while (PeekType() == TokenType.Using) {
                Token token = Eat(TokenType.Using);
                if (PeekType() == TokenType.Identifier && PeekType(1) == TokenType.Equal) {
                    // using-alias-directive
                    AtomicNameNode name = ParseIdentifier();
                    Eat(TokenType.Equal);
                    list.Append(
                            new UsingAliasNode(
                                token,
                                name,
                                ParseNamespaceOrTypeName()));
                }
                else {
                    // using-namespace-directive
                    list.Append(
                            new UsingNamespaceNode(
                                token,
                                ParseNamespaceOrTypeName()));
                }
                Eat(TokenType.Semicolon);
            }

            return list;
        }
Esempio n. 23
0
        // this
        // type-name.this
        // methodName (
        // methodName<T> (
        // typename.methodName (
        // propertyName {
        // typename.propertyName {
        // typename.methodName<[Attr]T> (
        // fieldName
        private ScanMemberNameKind ParseMemberName(out NameNode interfaceType) {
            if (PeekType() == TokenType.Operator) {
                interfaceType = null;
                return ScanMemberNameKind.Operator;
            }

            Token token = PeekToken();
            ParseNodeList list = new ParseNodeList();
            if (PeekType() == TokenType.Identifier && PeekType(1) == TokenType.ColonColon) {
                interfaceType = ParseAliasQualifiedName(false);
                list.Append(interfaceType);
                EatDotOrColonColon();
            }
            else {
                interfaceType = null;
            }

            ScanMemberNameKind result = ScanMemberNameKind.Invalid;
            do {
                if (PeekType() == TokenType.This)
                    result = ScanMemberNameKind.Indexer;
                else if (PeekType() != TokenType.Identifier)
                    result = ScanMemberNameKind.Field;
                else {
                    switch (PeekType(1)) {
                        case TokenType.OpenCurly:
                            result = ScanMemberNameKind.Property;
                            break;
                        case TokenType.OpenParen:
                            result = ScanMemberNameKind.Method;
                            break;
                        case TokenType.OpenAngle:
                            int mark = Mark();
                            NextToken();        // _id
                            TypeArgumentListScan scan = ScanTypeArgumentListOpt();
                            if (scan == TypeArgumentListScan.MayBeTypeArgumentList) {
                                switch (PeekType()) {
                                    case TokenType.Dot:
                                    case TokenType.ColonColon:
                                        scan = TypeArgumentListScan.MustBeTypeArgumentList;
                                        break;
                                    default:
                                        scan = TypeArgumentListScan.TypeParameterList;
                                        break;
                                }
                            }
                            Rewind(mark);

                            if (scan == TypeArgumentListScan.TypeParameterList || scan == TypeArgumentListScan.NotTypeArgumentList) {
                                result = ScanMemberNameKind.Method;
                                break;
                            }

                            list.Append(ParseSimpleName(false));
                            EatDotOrColonColon();
                            break;
                        case TokenType.ColonColon:
                        case TokenType.Dot:
                            list.Append(ParseSimpleName(false));
                            EatDotOrColonColon();
                            break;
                        default:
                            result = ScanMemberNameKind.Field;
                            break;
                    }
                }
            } while (ScanMemberNameKind.Invalid == result);

            if (list.Count > 1)
                interfaceType = new MultiPartNameNode(token, list);

            return result;
        }
Esempio n. 24
0
        private ParseNodeList ParseTypeParametersOpt() {
            ParseNodeList returnValue = new ParseNodeList();
            if (PeekType() == TokenType.OpenAngle) {
                Eat(TokenType.OpenAngle);

                do {
                    returnValue.Append(ParseTypeParameter());
                } while (null != EatOpt(TokenType.Comma));

                Eat(TokenType.CloseAngle);
            }
            return returnValue;
        }
Esempio n. 25
0
        private SwitchNode ParseSwitch() {
            Token token = Eat(TokenType.Switch);
            ParseNode condition = ParseParenExpression();
            ParseNodeList cases = new ParseNodeList();
            Eat(TokenType.OpenCurly);

            TokenType type = PeekType();
            while (type != TokenType.CloseCurly && type != TokenType.EOF) {
                Token sectionToken = PeekToken();

                // parse case labels
                ParseNodeList labels = new ParseNodeList();
                ParseNode label;
                while ((label = ParseSwitchLabel()) != null) {
                    Eat(TokenType.Colon);
                    labels.Append(label);
                }
                if (labels.Count == 0) {
                    ReportError(ParseError.CaseOrDefaultExpected);
                }

                // parse statements
                ParseNodeList statements = new ParseNodeList();
                type = PeekType();
                while (type != TokenType.Case && type != TokenType.Default && type != TokenType.CloseCurly && type != TokenType.EOF) {
                    int mark = Mark();

                    statements.Append(ParseStatement());

                    // ensure we make progress in an error case
                    if (mark == Mark()) {
                        NextToken();
                    }

                    type = PeekType();
                }
                if (statements.Count == 0) {
                    ReportError(ParseError.StatementExpected);
                }
                cases.Append(new SwitchSectionNode(
                                    sectionToken,
                                    labels,
                                    statements));
            }

            Eat(TokenType.CloseCurly);

            return new SwitchNode(token, condition, cases);
        }
Esempio n. 26
0
        private TypeParameterConstraintNode ParseConstraintClause() {
            EatWhere();
            AtomicNameNode name = ParseIdentifier();
            Eat(TokenType.Colon);

            bool hasConstructorConstraint = false;
            ParseNodeList typeConstraints = new ParseNodeList();
            do {
                if (PeekType() == TokenType.New) {
                    if (hasConstructorConstraint)
                        ReportError(ParseError.DuplicateConstructorConstraint);

                    hasConstructorConstraint = true;

                    Eat(TokenType.New);
                    Eat(TokenType.OpenParen);
                    Eat(TokenType.CloseParen);
                }
                else {
                    if (hasConstructorConstraint)
                        ReportError(ParseError.ConstructorConstraintMustBeLast);

                    typeConstraints.Append(ParseNamespaceOrTypeName());
                }

            } while (null != EatOpt(TokenType.Comma));

            return new TypeParameterConstraintNode(name, typeConstraints, hasConstructorConstraint);
        }
Esempio n. 27
0
        private ParseNodeList ParseFormalParameterList(TokenType endType, bool allowAttributes) {
            ParseNodeList list = new ParseNodeList();

            if (PeekType() != endType) {
                ParameterNode lastParam;
                do {
                    lastParam = ParseFormalParameter(allowAttributes);
                    list.Append(lastParam);
                } while (null != EatOpt(TokenType.Comma) && lastParam.Flags != ParameterFlags.Params);
            }

            return list;
        }
Esempio n. 28
0
        private ParseNodeList ParseConstraintClauses() {
            ParseNodeList returnValue = new ParseNodeList();
            while (PeekWhere()) {
                returnValue.Append(ParseConstraintClause());
            }

            return returnValue;
        }
Esempio n. 29
0
        private ParseNodeList ParseEnumMembers() {
            ParseNodeList list = new ParseNodeList();

            while (PeekType() == TokenType.Identifier || PeekType() == TokenType.OpenSquare) {
                list.Append(ParseEnumerationField());
                if (null == EatOpt(TokenType.Comma)) {
                    break;
                }
            }
            return list;
        }
Esempio n. 30
0
        private ParseNodeList ParseGlobalAttributes() {
            ParseNodeList list = new ParseNodeList();

            while (PeekType() == TokenType.OpenSquare &&
                   PeekType(1) == TokenType.Identifier &&
                   PeekType(2) == TokenType.Colon &&
                   (((IdentifierToken)PeekToken(1)).Symbol == assemblyName ||
                    ((IdentifierToken)PeekToken(1)).Symbol == moduleName)) {
                list.Append(ParseAttributeBlock());
            }

            return list;
        }
Esempio n. 31
0
        // namespace-member-declarations
        private ParseNodeList ParseNamespaceMembers() {
            ParseNodeList list = new ParseNodeList();
            while (true) {
                TokenType type = PeekType();
                switch (type) {
                    case TokenType.Namespace:
                        list.Append(ParseNamespace());
                        break;

                    case TokenType.Class:
                    case TokenType.Interface:
                    case TokenType.Enum:
                    case TokenType.Delegate:
                    case TokenType.Struct:

                    case TokenType.Abstract:
                    case TokenType.Sealed:

                    case TokenType.Public:
                    case TokenType.Internal:
                    case TokenType.Private:
                    case TokenType.Protected:

                    case TokenType.New:
                    case TokenType.Virtual:
                    case TokenType.Static:
                    case TokenType.Readonly:
                    case TokenType.Extern:
                    case TokenType.Override:
                    case TokenType.Unsafe:

                    case TokenType.OpenSquare:
                        list.Append(ParseTypeDeclaration());
                        break;

                    case TokenType.Identifier:
                        if (PeekPartial())
                            goto case TokenType.Class;
                        goto default;

                    default:
                        return list;
                }
            }
        }
Esempio n. 32
0
 private ExpressionListNode ParseExpressionList(TokenType terminator) {
     Token token = PeekToken();
     ParseNodeList list = new ParseNodeList();
     if (PeekType() != terminator) {
         do {
             list.Append(ParseExpression());
         } while (null != EatOpt(TokenType.Comma));
     }
     return new ExpressionListNode(token, list);
 }