⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lookuptablevisitor.cs

📁 c#源代码
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;

using ICSharpCode.SharpRefactory.Parser.AST.VB;

namespace ICSharpCode.SharpRefactory.Parser.VB
{
	public class LocalLookupVariable
	{
		TypeReference typeRef;
		Point         startPos;
		Point         endPos;
		
		public TypeReference TypeRef {
			get {
				return typeRef;
			}
		}
		public Point StartPos {
			get {
				return startPos;
			}
		}
		public Point EndPos {
			get {
				return endPos;
			}
		}
		
		public LocalLookupVariable(TypeReference typeRef, Point startPos, Point endPos)
		{
			this.typeRef = typeRef;
			this.startPos = startPos;
			this.endPos = endPos;
		}
	}
	
	public class LookupTableVisitor : AbstractASTVisitor
	{
		Hashtable variables      = CollectionsUtil.CreateCaseInsensitiveHashtable();
		ArrayList withStatements = new ArrayList();
		
		public Hashtable Variables {
			get {
				return variables;
			}
		}
		
		public ArrayList WithStatements {
			get {
				return withStatements;
			}
		}
		
		public void AddVariable(TypeReference typeRef, string name, Point startPos, Point endPos)
		{
			if (name == null || name.Length == 0) {
				return;
			}
			ArrayList list;
			if (variables[name] == null) {
				variables[name] = list = new ArrayList();
			} else {
				list = (ArrayList)variables[name];
			}
			list.Add(new LocalLookupVariable(typeRef, startPos, endPos));
		}
		
		public override object Visit(LocalVariableDeclaration localVariableDeclaration, object data)
		{
			TypeReference lastType = null;
			if (localVariableDeclaration.Variables.Count > 1) {
				bool ok = true;
				for (int i = 0; i < localVariableDeclaration.Variables.Count - 1; ++i) {
					if (((VariableDeclaration)localVariableDeclaration.Variables[i]).Type != null) {
						ok = false;
						break;
					}
				}
				if (ok) {
					lastType = ((VariableDeclaration)localVariableDeclaration.Variables[localVariableDeclaration.Variables.Count - 1]).Type;
				}
			}
			foreach (VariableDeclaration varDecl in localVariableDeclaration.Variables) {
				AddVariable(lastType == null ? varDecl.Type : lastType,
				            varDecl.Name,
				            localVariableDeclaration.StartLocation,
				            CurrentBlock == null ? new Point(-1, -1) : CurrentBlock.EndLocation);
			}
			return data;
		}
		
		public override object Visit(LoopControlVariableExpression loopControlVariableExpression, object data)
		{
			AddVariable(loopControlVariableExpression.Type, 
			            loopControlVariableExpression.Name,
			            loopControlVariableExpression.StartLocation,
			            CurrentBlock == null ? new Point(-1, -1) : CurrentBlock.EndLocation);
			return data;
		}
		
		public override object Visit(WithStatement withStatement, object data)
		{
			withStatements.Add(withStatement);
			return base.Visit(withStatement, data);
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -