Exemple #1
0
            public AbstractType Visit(DEnum de)
            {
                AbstractType bt;

                if (de.Type == null)
                {
                    bt = new PrimitiveType(DTokens.Int);
                }
                else
                {
                    var pop = de.Parent is IBlockNode && ctxt.ScopedBlock != de.Parent;
                    if (pop)
                    {
                        ctxt.PushNewScope(de.Parent as IBlockNode);
                    }

                    var bts = TypeDeclarationResolver.Resolve(de.Type, ctxt);

                    if (pop)
                    {
                        ctxt.Pop();
                    }

                    ctxt.CheckForSingleResult(bts, de.Type);

                    bt = bts != null && bts.Length != 0 ? bts[0] : null;
                }

                return(new EnumType(de, bt, typeBase));
            }
 public override void Visit(DEnum n)
 {
     if (CheckNode(n))
     {
         base.Visit(n);
     }
 }
Exemple #3
0
 public void Accept(DEnum type, StringBuilder x)
 {
     x.Append(type.StrValue);
 }
Exemple #4
0
		public EnumType(DEnum Enum, ISyntaxRegion td) : base(Enum, new PrimitiveType(DTokens.Int, 0), null, td) { }
 public void Accept(DEnum type, TType x, List <ResourceInfo> y)
 {
 }
Exemple #6
0
 public string Visit(DEnum dEnum)
 {
     return("ENUM");
 }
Exemple #7
0
 public EnumType(DEnum Enum, AbstractType BaseType, ISyntaxRegion td) : base(Enum, BaseType, null, td)
 {
 }
Exemple #8
0
 public void Accept(DEnum type, RawTextTable x)
 {
 }
 public ulong Visit(DEnum dEnum)
 {
     return(1000081);
 }
Exemple #10
0
        /*public override void VisitAttributeMetaDeclaration(AttributeMetaDeclaration md)
         * {
         *      base.Visit(md);
         * }
         *
         * public override void VisitMetaDeclarationBlock(MetaDeclarationBlock metaDeclarationBlock)
         * {
         *      base.Visit(metaDeclarationBlock);
         * }
         *
         * public override void VisitAttributeMetaDeclarationBlock(AttributeMetaDeclarationBlock attributeMetaDeclarationBlock)
         * {
         *      base.Visit(attributeMetaDeclarationBlock);
         * }
         *
         * public override void VisitAttributeMetaDeclarationSection(AttributeMetaDeclarationSection attributeMetaDeclarationSection)
         * {
         *      base.Visit(attributeMetaDeclarationSection);
         * }
         *
         * public override void Visit(ElseMetaDeclaration elseMetaDeclaration)
         * {
         *      base.Visit(elseMetaDeclaration);
         * }
         *
         * public override void Visit(ElseMetaDeclarationBlock elseMetaDeclarationBlock)
         * {
         *      base.Visit(elseMetaDeclarationBlock);
         * }*/
        #endregion

        public override void Visit(DEnum n)
        {
            base.Visit(n);
        }
Exemple #11
0
            public override void Visit(DEnum n)
            {
                l.Add(new FoldingRegion(GetBlockBodyRegion(n), FoldType.Type));

                base.Visit(n);
            }
Exemple #12
0
 public void Accept(DEnum type, DefAssembly x)
 {
     throw new NotImplementedException();
 }
Exemple #13
0
 public void Accept(DEnum type, StringBuilder line)
 {
     line.Append(type.Value);
 }
        /// <returns>Either CurrentScope, a BlockStatement object that is associated with the parent method or a complete new DModule object</returns>
        public static object FindCurrentCaretContext(string code,
                                                     IBlockNode CurrentScope,
                                                     int caretOffset, CodeLocation caretLocation,
                                                     out ParserTrackerVariables TrackerVariables)
        {
            bool ParseDecl = false;

            int blockStart         = 0;
            var blockStartLocation = CurrentScope.BlockStartLocation;

            if (CurrentScope is DMethod)
            {
                var block = (CurrentScope as DMethod).GetSubBlockAt(caretLocation);

                if (block != null)
                {
                    blockStart = DocumentHelper.LocationToOffset(code, blockStartLocation = block.Location);
                }
                else
                {
                    return(FindCurrentCaretContext(code, CurrentScope.Parent as IBlockNode, caretOffset, caretLocation, out TrackerVariables));
                }
            }
            else if (CurrentScope != null)
            {
                if (CurrentScope.BlockStartLocation.IsEmpty || caretLocation < CurrentScope.BlockStartLocation && caretLocation > CurrentScope.Location)
                {
                    ParseDecl  = true;
                    blockStart = DocumentHelper.LocationToOffset(code, blockStartLocation = CurrentScope.Location);
                }
                else
                {
                    blockStart = DocumentHelper.LocationToOffset(code, CurrentScope.BlockStartLocation);
                }
            }

            if (blockStart >= 0 && caretOffset - blockStart > 0)
            {
                var codeToParse = code.Substring(blockStart, caretOffset - blockStart);

                var sr  = new StringReader(codeToParse);
                var psr = DParser.Create(sr);

                /* Deadly important! For correct resolution behaviour,
                 * it is required to set the parser virtually to the blockStart position,
                 * so that everything using the returned object is always related to
                 * the original code file, not our code extraction!
                 */
                psr.Lexer.SetInitialLocation(blockStartLocation);

                object ret = null;

                if (CurrentScope == null || CurrentScope is IAbstractSyntaxTree)
                {
                    ret = psr.Parse();
                }
                else if (CurrentScope is DMethod)
                {
                    psr.Step();
                    ret = psr.BlockStatement(CurrentScope);
                }
                else if (CurrentScope is DModule)
                {
                    ret = psr.Root();
                }
                else
                {
                    psr.Step();
                    if (ParseDecl)
                    {
                        var ret2 = psr.Declaration(CurrentScope);

                        if (ret2 != null && ret2.Length > 0)
                        {
                            ret = ret2[0];
                        }
                    }
                    else
                    {
                        DBlockNode bn = null;
                        if (CurrentScope is DClassLike)
                        {
                            var t = new DClassLike((CurrentScope as DClassLike).ClassType);
                            t.AssignFrom(CurrentScope);
                            bn = t;
                        }
                        else if (CurrentScope is DEnum)
                        {
                            var t = new DEnum();
                            t.AssignFrom(CurrentScope);
                            bn = t;
                        }

                        bn.Clear();

                        psr.ClassBody(bn);
                        ret = bn;
                    }
                }

                TrackerVariables = psr.TrackerVariables;
                sr.Close();

                return(ret);
            }

            TrackerVariables = null;

            return(null);
        }
Exemple #15
0
 public CompletionItemKind Visit(DEnum n)
 {
     return(CompletionItemKind.Enum);
 }
Exemple #16
0
 public virtual string Accept(DEnum type)
 {
     return(type.Value.ToString());
 }
Exemple #17
0
 public void Accept(DEnum type, ByteBuf x)
 {
     x.WriteInt(type.Value);
 }
Exemple #18
0
 public void Accept(DEnum type, Utf8JsonWriter x)
 {
     x.WriteNumberValue(type.Value);
 }
 public override void Visit(DEnum n)
 {
     PushBlock(n);
 }
Exemple #20
0
 public void Accept(DEnum type, DefField x, List <ResourceInfo> y)
 {
     throw new NotImplementedException();
 }
Exemple #21
0
 public bool Accept(DEnum type)
 {
     return(type.Value == 0);
 }
		public override void Visit(DEnum n)
		{
			base.Visit(n);
		}
Exemple #23
0
 public EnumType(DEnum Enum, ISyntaxRegion td) : base(Enum, new PrimitiveType(DTokens.Int, 0), null, td)
 {
 }
Exemple #24
0
		private INode[] EnumDeclaration(INode Parent)
		{
			Expect(Enum);
			var ret = new List<INode>();

			var mye = new DEnum() { Location = t.Location, Description = GetComments(), Parent=Parent };
			LastParsedObject = mye;

			ApplyAttributes(mye);

			if (laKind != Identifier && IsBasicType())
				mye.Type = Type();
			else if (laKind == Auto)
			{
				Step();
				mye.Attributes.Add(new Modifier(Auto));
			}

			if (laKind == (Identifier))
			{
				// Normal enum identifier
				if (Lexer.CurrentPeekToken.Kind == (Assign) || // enum e = 1234;
				    Lexer.CurrentPeekToken.Kind == (OpenCurlyBrace) || // enum e { A,B,C, }
				    Lexer.CurrentPeekToken.Kind == (Semicolon) || // enum e;
				    Lexer.CurrentPeekToken.Kind == Colon) { // enum e : uint {..}
					Step ();
					mye.Name = t.Value;
					mye.NameLocation = t.Location;
				}
				else {
					if (mye.Type == null)
						mye.Type = Type();

					if (Expect(Identifier))
					{
						mye.Name = t.Value;
						mye.NameLocation = t.Location;
					}
				}
			}
			else if (IsEOF)
				ExpectingNodeName = true;

			if (IsDeclaratorSuffix)
			{
				DeclaratorSuffixes(mye);
			}

			// Enum inhertance type
			if (laKind == (Colon))
			{
				Step();
				mye.Type = Type();
			}

			// Variables with 'enum' as base type
			if (laKind == (Assign) || laKind == (Semicolon))
			{
				do
				{
					var enumVar = new DVariable();
					LastParsedObject = enumVar;

					enumVar.AssignFrom(mye);

					enumVar.Attributes.Add(new Modifier(Enum));
					if (mye.Type != null)
						enumVar.Type = mye.Type;
					else
						enumVar.Type = new DTokenDeclaration(Enum);

					if (laKind == (Comma))
					{
						Step();
						Expect(Identifier);
						enumVar.Name = t.Value;
						enumVar.NameLocation = t.Location;
					}

					if (laKind == (Assign))
					{
						//Step(); -- expected by initializer
						enumVar.Initializer = Initializer(); // Seems to be specified wrongly - theoretically there must be an AssignExpression();
					}
					enumVar.EndLocation = t.Location;
					ret.Add(enumVar);
				}
				while (laKind == Comma);

				Expect(Semicolon);
			}
			else if (laKind == OpenCurlyBrace) // Normal enum block
			{
				EnumBody(mye);
				ret.Add(mye);
			}

			mye.Description += CheckForPostSemicolonComment();

			return ret.ToArray();
		}
		public static ISyntaxRegion FindCurrentCaretContext(IEditorData editor, 
			out ParserTrackerVariables trackerVariables, 
			ref IBlockNode currentScope, 
			out IStatement currentStatement)
		{
			if(currentScope == null)
				currentScope = DResolver.SearchBlockAt (editor.SyntaxTree, editor.CaretLocation, out currentStatement);

			if (currentScope == null) {
				trackerVariables = null;
				currentStatement = null;
				return null;
			}

			bool ParseDecl = false;

			int blockStart = 0;
			var blockStartLocation = currentScope != null ? currentScope.BlockStartLocation : editor.CaretLocation;

			if (currentScope is DMethod)
			{
				var block = (currentScope as DMethod).GetSubBlockAt(editor.CaretLocation);

				if (block != null)
					blockStart = DocumentHelper.GetOffsetByRelativeLocation (editor.ModuleCode, editor.CaretLocation, editor.CaretOffset, blockStartLocation = block.Location);
				else {
					currentScope = currentScope.Parent as IBlockNode;
					return FindCurrentCaretContext (editor, out trackerVariables, ref currentScope, out currentStatement);
				}
			}
			else if (currentScope != null)
			{
				if (currentScope.BlockStartLocation.IsEmpty || (editor.CaretLocation < currentScope.BlockStartLocation && editor.CaretLocation > currentScope.Location))
				{
					ParseDecl = true;
					blockStart = DocumentHelper.GetOffsetByRelativeLocation(editor.ModuleCode, editor.CaretLocation, editor.CaretOffset, blockStartLocation = currentScope.Location);
				}
				else
					blockStart = DocumentHelper.GetOffsetByRelativeLocation(editor.ModuleCode, editor.CaretLocation, editor.CaretOffset, currentScope.BlockStartLocation);
			}

			if (blockStart >= 0 && editor.CaretOffset - blockStart > 0)
				using (var sr = new Misc.StringView(editor.ModuleCode, blockStart, editor.CaretOffset - blockStart))
				{
					var psr = DParser.Create(sr);

					/*					 Deadly important! For correct resolution behaviour, 
					 * it is required to set the parser virtually to the blockStart position, 
					 * so that everything using the returned object is always related to 
					 * the original code file, not our code extraction!
					 */
					psr.Lexer.SetInitialLocation(blockStartLocation);

					ISyntaxRegion ret = null;

					if (currentScope == null)
						ret = psr.Parse();
					else if (currentScope is DMethod)
					{
						psr.Step();
						var dm = currentScope as DMethod;
						dm.Clear();

						if ((dm.SpecialType & DMethod.MethodType.Lambda) != 0 &&
							psr.Lexer.LookAhead.Kind != DTokens.OpenCurlyBrace) {
							psr.LambdaSingleStatementBody (dm);
							ret = dm.Body;
						} else {
							var methodRegion = DTokens.Body;

							if (dm.In != null && blockStartLocation == dm.In.Location)
								methodRegion = DTokens.In;

							if (dm.Out != null && blockStartLocation == dm.Out.Location)
								methodRegion = DTokens.Out;

							var newBlock = psr.BlockStatement (currentScope);
							ret = newBlock;

							switch (methodRegion) {
								case DTokens.Body:
									newBlock.EndLocation = dm.Body.EndLocation;
									dm.Body = newBlock;
									break;
								case DTokens.In:
									newBlock.EndLocation = dm.In.EndLocation;
									dm.In = newBlock;
									break;
								case DTokens.Out:
									newBlock.EndLocation = dm.Out.EndLocation;
									dm.Out = newBlock;
									break;
							}
						}
					}
					else if (currentScope is DModule)
						ret = psr.Root();
					else
					{
						psr.Step();
						if (ParseDecl)
						{
							var ret2 = psr.Declaration(currentScope);

							if (ret2 != null && ret2.Length > 0)
								ret = ret2[0];
						}
						else if (currentScope is DClassLike)
						{
							var t = new DClassLike((currentScope as DClassLike).ClassType);
							t.AssignFrom(currentScope);
							t.Clear();
							psr.ClassBody(t);
							ret = t;
						}
						else if (currentScope is DEnum)
						{
							var t = new DEnum();
							t.AssignFrom(currentScope);
							t.Clear();
							psr.EnumBody(t);
							ret = t;
						}
					}

					currentScope = DResolver.SearchBlockAt (currentScope, 
						psr.Lexer.CurrentToken != null ? psr.Lexer.CurrentToken.EndLocation : editor.CaretLocation, 
						out currentStatement);
					trackerVariables = psr.TrackerVariables;
					return ret;
				}

			trackerVariables = null;
			currentStatement = null;
			return null;
		}
Exemple #26
0
		public void EnumBody(DEnum mye)
		{
			var OldPreviousComment = PreviousComment;
			PreviousComment = new StringBuilder();
			mye.BlockStartLocation = la.Location;

			// While there are commas, loop through
			do
			{
				Step();

				if (laKind == CloseCurlyBrace)
					break;

				var ev = new DEnumValue() { Location = la.Location, Description = GetComments(), Parent = mye };
				LastParsedObject = ev;

				if (laKind == Identifier && (
					Lexer.CurrentPeekToken.Kind == Assign ||
					Lexer.CurrentPeekToken.Kind == Comma ||
					Lexer.CurrentPeekToken.Kind == CloseCurlyBrace))
				{
					Step();
					ev.Name = t.Value;
					ev.NameLocation = t.Location;
				}
				else
				{
					ev.Type = Type();
					if (Expect(Identifier))
					{
						ev.Name = t.Value;
						ev.NameLocation = t.Location;
					}
					else if (IsEOF)
						ExpectingNodeName = true;
				}

				if (laKind == (Assign))
				{
					Step();
					ev.Initializer = AssignExpression();
				}

				ev.EndLocation = t.EndLocation;
				ev.Description += CheckForPostSemicolonComment();

				mye.Add(ev);
			}
			while (laKind == Comma);

			Expect(CloseCurlyBrace);
			PreviousComment = OldPreviousComment;

			mye.EndLocation = t.EndLocation;
		}
Exemple #27
0
		public EnumType(DEnum Enum, AbstractType BaseType, ISyntaxRegion td) : base(Enum, BaseType, null, td) { }
        public static ISyntaxRegion FindCurrentCaretContext(IEditorData editor,
                                                            out ParserTrackerVariables trackerVariables,
                                                            ref IBlockNode currentScope,
                                                            out IStatement currentStatement)
        {
            if (currentScope == null)
            {
                currentScope = DResolver.SearchBlockAt(editor.SyntaxTree, editor.CaretLocation, out currentStatement);
            }

            if (currentScope == null)
            {
                trackerVariables = null;
                currentStatement = null;
                return(null);
            }

            bool ParseDecl = false;

            int blockStart         = 0;
            var blockStartLocation = currentScope != null ? currentScope.BlockStartLocation : editor.CaretLocation;

            if (currentScope is DMethod)
            {
                var block = (currentScope as DMethod).GetSubBlockAt(editor.CaretLocation);

                if (block != null)
                {
                    blockStart = DocumentHelper.GetOffsetByRelativeLocation(editor.ModuleCode, editor.CaretLocation, editor.CaretOffset, blockStartLocation = block.Location);
                }
                else
                {
                    currentScope = currentScope.Parent as IBlockNode;
                    return(FindCurrentCaretContext(editor, out trackerVariables, ref currentScope, out currentStatement));
                }
            }
            else if (currentScope != null)
            {
                if (currentScope.BlockStartLocation.IsEmpty || (editor.CaretLocation < currentScope.BlockStartLocation && editor.CaretLocation > currentScope.Location))
                {
                    ParseDecl  = true;
                    blockStart = DocumentHelper.GetOffsetByRelativeLocation(editor.ModuleCode, editor.CaretLocation, editor.CaretOffset, blockStartLocation = currentScope.Location);
                }
                else
                {
                    blockStart = DocumentHelper.GetOffsetByRelativeLocation(editor.ModuleCode, editor.CaretLocation, editor.CaretOffset, currentScope.BlockStartLocation);
                }
            }

            if (blockStart >= 0 && editor.CaretOffset - blockStart > 0)
            {
                using (var sr = new Misc.StringView(editor.ModuleCode, blockStart, editor.CaretOffset - blockStart))
                {
                    var psr = DParser.Create(sr);

                    /*					 Deadly important! For correct resolution behaviour,
                     * it is required to set the parser virtually to the blockStart position,
                     * so that everything using the returned object is always related to
                     * the original code file, not our code extraction!
                     */
                    psr.Lexer.SetInitialLocation(blockStartLocation);

                    ISyntaxRegion ret = null;

                    if (currentScope == null)
                    {
                        ret = psr.Parse();
                    }
                    else if (currentScope is DMethod)
                    {
                        psr.Step();
                        var dm = currentScope as DMethod;
                        dm.Clear();

                        if ((dm.SpecialType & DMethod.MethodType.Lambda) != 0 &&
                            psr.Lexer.LookAhead.Kind != DTokens.OpenCurlyBrace)
                        {
                            psr.LambdaSingleStatementBody(dm);
                            ret = dm.Body;
                        }
                        else
                        {
                            var methodRegion = DTokens.Body;

                            if (dm.In != null && blockStartLocation == dm.In.Location)
                            {
                                methodRegion = DTokens.In;
                            }

                            if (dm.Out != null && blockStartLocation == dm.Out.Location)
                            {
                                methodRegion = DTokens.Out;
                            }

                            var newBlock = psr.BlockStatement(currentScope);
                            ret = newBlock;

                            switch (methodRegion)
                            {
                            case DTokens.Body:
                                newBlock.EndLocation = dm.Body.EndLocation;
                                dm.Body = newBlock;
                                break;

                            case DTokens.In:
                                newBlock.EndLocation = dm.In.EndLocation;
                                dm.In = newBlock;
                                break;

                            case DTokens.Out:
                                newBlock.EndLocation = dm.Out.EndLocation;
                                dm.Out = newBlock;
                                break;
                            }
                        }
                    }
                    else if (currentScope is DModule)
                    {
                        ret = psr.Root();
                    }
                    else
                    {
                        psr.Step();
                        if (ParseDecl)
                        {
                            var ret2 = psr.Declaration(currentScope);

                            if (ret2 != null && ret2.Length > 0)
                            {
                                ret = ret2[0];
                            }
                        }
                        else if (currentScope is DClassLike)
                        {
                            var t = new DClassLike((currentScope as DClassLike).ClassType);
                            t.AssignFrom(currentScope);
                            t.Clear();
                            psr.ClassBody(t);
                            ret = t;
                        }
                        else if (currentScope is DEnum)
                        {
                            var t = new DEnum();
                            t.AssignFrom(currentScope);
                            t.Clear();
                            psr.EnumBody(t);
                            ret = t;
                        }
                    }

                    currentScope = DResolver.SearchBlockAt(currentScope,
                                                           psr.Lexer.CurrentToken != null ? psr.Lexer.CurrentToken.EndLocation : editor.CaretLocation,
                                                           out currentStatement);
                    trackerVariables = psr.TrackerVariables;
                    return(ret);
                }
            }

            trackerVariables = null;
            currentStatement = null;
            return(null);
        }
 public int Accept(DEnum data, TType type, Title x)
 {
     SetTitleValue(x, data.StrValue);
     return(1);
 }
Exemple #30
0
 public IconId Visit(DEnum n)
 {
     // TODO: does declaring an enum private/protected/package actually have a meaning?
     return(iconIdWithProtectionAttr(n, "enum"));
 }
		public virtual void Visit(DEnum n)
		{
			VisitBlock(n);
		}
Exemple #32
0
 public byte Visit(DEnum n)
 {
     return((byte)TypeReferenceKind.Enum);
 }