/// <summary>
        /// Parse the specified name into a child <see cref="NamespaceRef"/> or <see cref="TypeRef"/> on the current namespace,
        /// or a <see cref="Dot"/> expression that evaluates to one.
        /// </summary>
        public virtual Expression ParseName(string name)
        {
            string      prefix = RemovePrefix(ref name);
            SymbolicRef symbolicRef;
            object      obj;

            lock (this)
                obj = _children.Find(prefix);
            if (obj != null)
            {
                if (obj is Namespace)
                {
                    symbolicRef = new NamespaceRef((Namespace)obj);
                }
                else if (obj is ITypeDecl)
                {
                    symbolicRef = new TypeRef((ITypeDecl)obj);
                }
                else //if (obj is Type)
                {
                    symbolicRef = new TypeRef((Type)obj);
                }
            }
            else
            {
                symbolicRef = new UnresolvedRef(prefix);
            }
            return(string.IsNullOrEmpty(name) ? symbolicRef : ParseName(symbolicRef, name));
        }
        /// <summary>
        /// Parse the specified name into a child <see cref="NamespaceRef"/> or <see cref="TypeRef"/> on the existing
        /// <see cref="Lookup"/> or <see cref="Dot"/> expression.
        /// </summary>
        protected Expression ParseName(Expression expression, string name)
        {
            Expression rightMost = expression.SkipPrefixes();

            do
            {
                string      prefix = RemovePrefix(ref name);
                SymbolicRef newRight;
                if (rightMost is NamespaceRef)
                {
                    newRight = (SymbolicRef)((NamespaceRef)rightMost).Namespace.ParseName(prefix);
                }
                else if (rightMost is TypeRef)
                {
                    newRight = ((TypeRef)rightMost).GetNestedType(prefix);
                }
                else
                {
                    newRight = new UnresolvedRef(prefix);
                }
                expression = new Dot(expression, newRight);
                rightMost  = newRight;
            }while (!string.IsNullOrEmpty(name));
            return(expression);
        }
        /// <summary>
        /// Parse a <see cref="ConstraintClause"/>.
        /// </summary>
        public ConstraintClause(Parser parser, CodeObject parent)
            : base(parser, parent)
        {
            // Get any regular comments from before the 'where'
            MoveComments(parser.LastToken);

            parser.NextToken();                              // Move past 'where'
            SetField(ref _typeParameter, UnresolvedRef.Create(parser.GetIdentifier()), false);
            ParseExpectedToken(parser, ParseTokenSeparator); // Move past ':'

            // Parse list of TypeParameterConstraints
            while (true)
            {
                CreateConstraints().Add(TypeParameterConstraint.Parse(parser, this));
                if (parser.TokenText == TypeParameterConstraint.ParseTokenSeparator)
                {
                    parser.NextToken();  // Move past ','
                }
                else
                {
                    break;
                }
            }

            // Get the EOL comment from the Type expression of the last constraint if it's a TypeConstraint
            // (it will end up there since they use an Expression), otherwise from the LastToken.
            if (_constraints != null && _constraints.Last is TypeConstraint)
            {
                MoveEOLComment(((TypeConstraint)_constraints.Last).Type);
            }
            else
            {
                MoveEOLComment(parser.LastToken);
            }
        }
        protected ExternAlias(Parser parser, CodeObject parent)
            : base(parser, parent)
        {
            Token token = (Token)parser.RemoveLastUnused();

            NewLines = token.NewLines;
            SetLineCol(token);
            parser.NextToken();                        // Move past 'alias' keyword
            token = parser.Token;
            string name = parser.GetIdentifierText();  // Parse the name

            RootNamespaceRef = new UnresolvedRef(name, token.LineNumber, token.ColumnNumber);
            ParseTerminator(parser);
        }
        /// <summary>
        /// Determine if the current reference refers to the same code object as the specified reference.
        /// </summary>
        public override bool IsSameRef(SymbolicRef symbolicRef)
        {
            UnresolvedRef unresolvedRef = (symbolicRef is AliasRef ? ((AliasRef)symbolicRef).Alias.Expression.SkipPrefixes() : symbolicRef) as UnresolvedRef;

            if (unresolvedRef == null || (string)Reference != (string)unresolvedRef.Reference)
            {
                return(false);
            }

            // The strings of the UnresolvedRefs match, but we have to also verify that any Dot prefixes
            // match - if either side has one, they must match, otherwise neither side can have one.
            Dot         parentDot  = _parent as Dot;
            Dot         parentDot2 = symbolicRef.Parent as Dot;
            SymbolicRef dotPrefix  = (parentDot != null && parentDot.Right == this ? parentDot.Left as SymbolicRef : null);
            SymbolicRef dotPrefix2 = (parentDot2 != null && parentDot2.Right == this ? parentDot2.Left as SymbolicRef : null);

            return(dotPrefix == null || dotPrefix2 == null || dotPrefix.IsSameRef(dotPrefix2));
        }
Exemplo n.º 6
0
 private static Expression ResolveNamespaceExpression(Namespace parentNamespace, Expression expression)
 {
     if (expression is UnresolvedRef)
     {
         // Find any existing or create the namespace
         UnresolvedRef unresolvedRef = (UnresolvedRef)expression;
         Namespace     @namespace    = parentNamespace.FindOrCreateChildNamespace(unresolvedRef.Name);
         @namespace.SetDeclarationsInProject(true);
         expression = @namespace.CreateRef();
     }
     else if (expression is Dot)
     {
         // If multiple namespaces are specified, resolve from left to right
         Dot dot = (Dot)expression;
         dot.Left  = ResolveNamespaceExpression(parentNamespace, dot.Left);
         dot.Right = ResolveNamespaceExpression(((NamespaceRef)dot.Left.SkipPrefixes()).Namespace, dot.Right);
     }
     return(expression);
 }
 protected internal GenericMethodDecl(Parser parser, CodeObject parent, bool typeParametersAlreadyParsed, ParseFlags flags)
     : base(parser, parent, false, flags)
 {
     if (typeParametersAlreadyParsed)
     {
         // The type parameters were already parsed on the unused Dot expression - fetch them from there
         UnresolvedRef unresolvedRef = (UnresolvedRef)((Dot)parser.LastUnusedCodeObject).Right;
         _typeParameters = new ChildList <TypeParameter>(this);
         foreach (Expression expression in unresolvedRef.TypeArguments)
         {
             _typeParameters.Add(new TypeParameter(expression is UnresolvedRef ? ((UnresolvedRef)expression).Name : null));
         }
         unresolvedRef.TypeArguments = null;
     }
     ParseMethodNameAndType(parser, parent, true, false);
     ParseModifiersAndAnnotations(parser);  // Parse any attributes and/or modifiers
     if (!typeParametersAlreadyParsed)
     {
         _typeParameters = TypeParameter.ParseList(parser, this);  // Parse any type parameters
     }
     ParseParameters(parser);
     _constraintClauses = ConstraintClause.ParseList(parser, this);  // Parse any constraint clauses
     ParseTerminatorOrBody(parser, flags);
 }
Exemplo n.º 8
0
        protected ConstructorInitializer(Parser parser, CodeObject parent, string keyword)
            : base(parser, parent, true)
        {
            Token lastHeaderToken = parser.LastToken;

            parser.NextToken();  // Move past ':'
            Token token = parser.Token;

            SetLineCol(token);
            MoveFormatting(token);                                        // Move formatting
            parser.NextToken();                                           // Move past 'this' or 'base'
            ParseArguments(parser, this, ParseTokenStart, ParseTokenEnd); // Parse arguments

            MoveComments(lastHeaderToken);                                // Move any regular comments from before the ':' this object

            // Set the expression to an unresolved reference using the keyword for the name
            Expression = new UnresolvedRef(keyword, LineNumber, ColumnNumber);

            // Force constructor initializers to start on a new line if auto-cleanup is on
            if (AutomaticFormattingCleanup && !parser.IsGenerated)
            {
                IsFirstOnLine = true;
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Create a <see cref="Goto"/> to a constant <see cref="Expression"/>.
 /// </summary>
 public Goto(Expression constantExpression)
 {
     ConstantExpression = constantExpression;
     Target             = new UnresolvedRef(Case.ParseToken + " " + _constantExpression.AsString());
 }
Exemplo n.º 10
0
 /// <summary>
 /// Create a <see cref="Goto"/> to a string name.
 /// </summary>
 public Goto(string name)
 {
     Target = new UnresolvedRef(name);
 }
 /// <summary>
 /// Create an <see cref="ExternAlias"/> with the specified name.
 /// </summary>
 public ExternAlias(string name)
 {
     RootNamespaceRef = new UnresolvedRef(name);
 }