示例#1
0
 public virtual void Dispose()
 {
     this.reader.Close();
     this.reader             = null;
     this.errors             = null;
     this.lastToken          = this.curToken = (LZ.Lexer.Token)(this.peekToken = null);
     this.specialCommentHash = null;
     this.tagComments        = null;
     this.sb = (StringBuilder)(this.originalValue = null);
 }
示例#2
0
 public virtual void Dispose()
 {
     this.reader.Close();
     this.reader = null;
     this.errors = null;
     this.lastToken = this.curToken = (LZ.Lexer.Token) (this.peekToken = null);
     this.specialCommentHash = null;
     this.tagComments = null;
     this.sb = (StringBuilder) (this.originalValue = null);
 }
示例#3
0
 public LZ.Lexer.Token Peek()
 {
     if (this.peekToken.next == null)
     {
         this.peekToken.next = this.Next();
         this.specialTracker.InformToken(this.peekToken.next.kind);
     }
     this.peekToken = this.peekToken.next;
     return(this.peekToken);
 }
示例#4
0
 public virtual LZ.Lexer.Token NextToken()
 {
     if (this.curToken == null)
     {
         this.curToken = this.Next();
         this.specialTracker.InformToken(this.curToken.kind);
         return(this.curToken);
     }
     this.lastToken = this.curToken;
     if (this.curToken.next == null)
     {
         this.curToken.next = this.Next();
         if (this.curToken.next != null)
         {
             this.specialTracker.InformToken(this.curToken.next.kind);
         }
     }
     this.curToken = this.curToken.next;
     return(this.curToken);
 }
示例#5
0
        public void ProcessAssembly(string aName, Encoding encode)
        {
            TextReader reader = new StreamReader(aName, encode);
            StringBuilder sb = new StringBuilder();
            sb.Append(reader.ReadToEnd());
            reader.Close();
            reader = new StreamReader(aName, encode);
            LZ.Lexer.CPP.Lexer lex = new LZ.Lexer.CPP.Lexer(reader);

            string[] list = sb.ToString().Split('\n');
            LZ.Lexer.Token tokenFirst = null, token = null;
            int i = 0;
            do
            {
                i++;
                token = lex.NextToken();
                if (token.kind == 0) break;
                if (tokenFirst == null)
                {
                    tokenFirst = token;
                }

                Debug.WriteLine(string.Format("{0}. {1}", i, GetTokenText(list, token)));
            }
            while (token.kind != 0);

            tokenCurrent = null;
            this._work = new Stack();
            tokenCurrent = tokenFirst;
            string sModifier = "private";  // 0=private;1=protected;2=public;
            while (tokenCurrent != null && tokenCurrent.next != null)
            {
                string line = list[tokenCurrent.line - 1];
                int nLen = tokenCurrent.EndLocation.X - tokenCurrent.Location.X;
                string word = line.Substring(tokenCurrent.Location.X - 1, nLen);


                TypeInfo ti = null;

                switch (word)
                {
                    case "class":
                        sModifier = "private";

                        ProcessAType(ref ti, ref sModifier, list, false);
                        if (ti.IsClass) AddClassifier(ti, true);
                        ////if (!this._work.Contains(ti))
                        ////{
                        ////    this._work.Push(ti);
                        ////}
                        break;
                    case "struct":
                        sModifier = "public";
                        ProcessAType(ref ti, ref sModifier, list, true);
                        if (ti.IsClass) AddClassifier(ti, true);
                        break;
                    default:
                        break;
                }
                ////this._work = new Stack();
                ////foreach (Type type in types)
                ////{
                ////    if (!this._work.Contains(type))
                ////    {
                ////        this._work.Push(type);
                ////    }
                ////}
                ////this.ProcessWork();


                tokenCurrent = tokenCurrent.next;
            }
            reader.Close();

            ////Assembly assembly;
            ////try
            ////{
            ////    assembly = Assembly.LoadFrom(aName);
            ////    LZ.Reverse.Info.Write(new string[] { "... processing assembly \"{0}\"", aName });
            ////}
            ////catch (FileNotFoundException)
            ////{
            ////    LZ.Reverse.Info.Write(new string[] { "*** could not load Assembly: \"{0}\"", aName });
            ////    return;
            ////}
            ////catch (FileLoadException)
            ////{
            ////    LZ.Reverse.Info.Write(new string[] { "*** could not load Assembly: \"{0}\"", aName });
            ////    return;
            ////}
            ////catch (Exception)
            ////{
            ////    LZ.Reverse.Info.Write(new string[] { "*** could not load Assembly: \"{0}\"", aName });
            ////    return;
            ////}
            ////if (this._mdl.Comment == "")
            ////{
            ////    this._mdl.Comment = "Reversed assemblies:\r\n";
            ////}
            ////this._mdl.Comment = string.Concat(new object[] { this._mdl.Comment, aName, " (", assembly.GetName(), ")\r\n" });
            ////Type[] types = new Type[0];
            ////try
            ////{
            ////    if (this._bAllTypes)
            ////    {
            ////        try
            ////        {
            ////            types = assembly.GetTypes();
            ////        }
            ////        catch (ReflectionTypeLoadException exception)
            ////        {
            ////            if (LZ.Reverse.Info._bDebug)
            ////            {
            ////                LZ.Reverse.Info.Write(new string[] { "*** exception accessing the list of all types, replaced by the list of exported types \"{0}\"", exception.ToString() });
            ////            }
            ////            types = assembly.GetExportedTypes();
            ////            if (this._recur == Recursion.NONE)
            ////            {
            ////                this._recur = Recursion.LIMITED;
            ////            }
            ////        }
            ////    }
            ////    else
            ////    {
            ////        types = assembly.GetExportedTypes();
            ////    }
            ////}
            ////catch (Exception exception2)
            ////{
            ////    if (LZ.Reverse.Info._bDebug)
            ////    {
            ////        LZ.Reverse.Info.Write(new string[] { "*** exception during type enumeration \"{0}\"", exception2.ToString() });
            ////    }
            ////}
            ////this._work = new Stack();
            ////foreach (Type type in types)
            ////{
            ////    if (!this._work.Contains(type))
            ////    {
            ////        this._work.Push(type);
            ////    }
            ////}
            ////this.ProcessWork();
        }
示例#6
0
 private string NextTokenText(string[] list)
 {
     tokenCurrent = tokenCurrent.next;
     return GetTokenText(list, tokenCurrent);
 }
示例#7
0
        private void ProcessAType(ref TypeInfo ti, ref string sModifier, bool bIsValueType)
        {
            string word = NextTokenText();
            ti.Name = ti.Code = word;
            word = NextTokenText();
            string wordNext = GetTokenText(tokenCurrent.next);


            if (word == ";" || word == "*" || ";" == wordNext || wordNext == "*")
            {
                ti.IsClass = false;
                return;
            }
            ti.IsClass = true;

            ObjectInfo objTemp = new ObjectInfo(), paramObj = new ObjectInfo();
            List<ObjectInfo> paramList = new List<ObjectInfo>();
            bool isTypeBody = false, isMethord = false;
            Stack<int> stack = new Stack<int>();
            stack.Push(0);
            while (stack.Count > 0)
            {
                switch(word)
                {
                    case "operator":
                        ReadMethordBody(word, null);
                        objTemp.Clear();
                        break;
                    case "volatile":
                        objTemp.IsVolatile = true;
                        break;
                    case "static":
                        objTemp.IsStatic = true;
                        break;
                    case "virtual":
                        objTemp.IsVirtual = true;
                        objTemp.Virtual = word;
                        break;
                    case "WINAPI":
                    case "afx_msg":
                        break;
                    case "private":
                    case "protected":
                    case "public":
                        sModifier = word;
                        break;
                    case "union":
                        objTemp.Type = word;
                        ReadMethordBody(word, null);
                        break;
                    case ":":
                        if (!isTypeBody)
                        {
                            // 处理继承
                            ReadParentInfo(ti, word);
                        }
                        break;
                    case "(":
                        isMethord = true;
                        paramList.Clear();
                        paramObj.Clear();
                        break;
                    case ")":
                        if (isMethord && tokenCurrent.next != null && tokenCurrent.next.next != null && ("=" == GetTokenText(tokenCurrent.next)) && ("0" == GetTokenText(tokenCurrent.next.next)))
                        {
                            objTemp.IsAbstract = true;
                            ti.IsAbstract = true;
                            tokenCurrent = tokenCurrent.next.next;
                        }
                        if (isMethord && wordNext == ":")
                        {
                            // 构造函数后有参数初始化的
                            ReadMethordBody(word, objTemp.Implementation);

                            if (isTypeBody)
                            {
                                if (!string.IsNullOrEmpty(paramObj.Code))
                                {
                                    ObjectInfo param = new ObjectInfo();
                                    param.Store(paramObj);
                                    paramList.Add(param);
                                }
                                paramObj.Clear();

                                // 方法或属性定义结束
                                ti.AddMethord(objTemp, paramList);

                                objTemp.Clear();
                                isMethord = false;
                            }
                        }
                        break;
                    case "}":
                        stack.Pop();
                        break;
                    case "{":
                    case ";":
                    case ",":
                        if (isTypeBody && isMethord)    //  && (word == "," || word == ";")
                        {
                            if (!string.IsNullOrEmpty(paramObj.Code))
                            {
                                ObjectInfo param = new ObjectInfo();
                                param.Store(paramObj);
                                paramList.Add(param);
                            }
                            paramObj.Clear();
                        }

                        if (isTypeBody && word != ",") //  || word == ";"
                        {
                            // 方法或属性定义结束
                            if (isMethord)
                            {
                                // 跳过方法体
                                if (word == "{")
                                {
                                    ReadMethordBody(word, objTemp.Implementation);
                                }

                                ti.AddMethord(objTemp, paramList);
                            }
                            else
                            {
                                ti.AddAttribute(objTemp);
                            }

                            objTemp.Clear();
                            isMethord = false;

                            break;
                        }

                        // 类体定义,方法或属性
                        if (!isTypeBody && word == "{")
                        {
                            isTypeBody = true;
                        }
                        break;
                    case "DECLARE_DYNCREATE":
                    case "DECLARE_MESSAGE_MAP":
                        // 读取到行尾
                        word = ReadToLineEnd();
                        wordNext = GetTokenText(tokenCurrent);
                        continue;
                    default:
                        if (word == "~" && GetTokenText(tokenCurrent.next) == ti.Code)
                        {
                            // 析构函数
                            objTemp.Modifier = sModifier;
                            objTemp.Code = objTemp.Name = word + ti.Code;
                            word = NextTokenText();
                        }
                        else
                        {
                            if (isMethord)
                            {
                                if (word == "=")
                                {
                                    // 忽略参数的默认值
                                    wordNext = GetTokenText(tokenCurrent.next);
                                    Stack sTemp = new Stack();
                                    while ((wordNext != "," && wordNext != ")") || sTemp.Count > 0)
                                    {
                                        switch (wordNext)
                                        {
                                            case "(":
                                                sTemp.Push("(");
                                                break;
                                            case ")":
                                                if (sTemp.Count > 0) sTemp.Pop();
                                                break;
                                        }
                                        word = NextTokenText();
                                        paramObj.Default += word;
                                        if (tokenCurrent == null || tokenCurrent.next == null)
                                        {
                                            break;
                                        }
                                        wordNext = GetTokenText(tokenCurrent.next);
                                    }
                                }
                                else
                                {
                                    // 一般应该为参数
                                    ChangeObjectInfo(paramObj, word, sModifier);
                                }
                            }
                            else
                            {
                                // 可能为构造函数或属性定义【指针】
                                ChangeObjectInfo(objTemp, word, sModifier);
                            }
                        }

                        break;
                }

                if (tokenCurrent == null ||tokenCurrent.next == null)
                {
                    break;
                }
                word = NextTokenText();
                wordNext = GetTokenText(tokenCurrent.next);
            }
        }
示例#8
0
        private string NextTokenText()
        {
            if (tokenCurrent == null) return "";

            tokenCurrent = tokenCurrent.next;
            return GetTokenText(tokenCurrent);
        }
示例#9
0
        public void ProcessAFile(string aName, Encoding encode)
        {

            Debug.WriteLine(string.Format("reverse file: {0}", aName));

            TextReader reader = new StreamReader(aName, encode);
            _lexer = new LZ.Lexer.CPP.Lexer(reader);

            LZ.Lexer.Token tokenFirst = null, token = null;
            int i = 0;
            do
            {
                i++;
                token = _lexer.NextToken();
                if (token.kind == 0) break;
                if (tokenFirst == null)
                {
                    tokenFirst = token;
                }

                //Debug.WriteLine(string.Format("{0}. {1}", i, GetTokenText(token)));
            }
            while (token.kind != 0);

            tokenCurrent = null;
            tokenCurrent = tokenFirst;
            string sModifier = "private";  // 0=private;1=protected;2=public;
            bool isInTypeDef = false, isParameter = false, isGenericType = false;
            while (tokenCurrent != null && tokenCurrent.next != null)
            {
                string word = tokenCurrent.val;
                TypeInfo ti = null;

                switch (word)
                {
                    case "template":
                        isGenericType = true;
                        ReadTemplate();
                        break;
                    case "class":
                        sModifier = "private";
                        ti = new TypeInfo();
                        ti.Comment = aName;
                        ti.IsGenericType = isGenericType;
                        ProcessAType(ref ti, ref sModifier, false);
                        isGenericType = false;
                        ////if (ti.IsClass) AddClassifier(ti, true);
                        if (!this._work.Contains(ti))
                        {
                            this._work.Push(ti);
                        }
                        break;
                    case "struct":
                        // 跳过在类型定义体中的struct关键字
                        if (isParameter) break;

                        ti = new TypeInfo();
                        ti.Comment = aName;
                        sModifier = "public";
                        ti.IsValueType = true;
                        ti.IsGenericType = isGenericType;
                        ProcessAType(ref ti, ref sModifier, true);
                        isGenericType = false;
                        if (ti.IsClass && !this._work.Contains(ti))
                        {
                            this._work.Push(ti);
                        }
                        ////if (ti.IsClass) AddClassifier(ti, true);
                        break;
                    case "typedef":
                        isInTypeDef = true;
                        break;
                    case ";":
                        isInTypeDef = false;
                        break;
                    case "(":
                        isParameter = true;
                        break;
                    case ")":
                        isParameter = false;
                        break;
                    default:
                        break;
                }

                if (tokenCurrent == null) break;
                tokenCurrent = tokenCurrent.next;
            }

            // 关闭文件
            reader.Close();
            _lexer = null;
        }
示例#10
0
 public virtual LZ.Lexer.Token NextToken()
 {
     if (this.curToken == null)
     {
         this.curToken = this.Next();
         this.specialTracker.InformToken(this.curToken.kind);
         return this.curToken;
     }
     this.lastToken = this.curToken;
     if (this.curToken.next == null)
     {
         this.curToken.next = this.Next();
         if (this.curToken.next != null)
         {
             this.specialTracker.InformToken(this.curToken.next.kind);
         }
     }
     this.curToken = this.curToken.next;
     return this.curToken;
 }
示例#11
0
 public void StartPeek()
 {
     this.peekToken = this.curToken;
 }
示例#12
0
 public LZ.Lexer.Token Peek()
 {
     if (this.peekToken.next == null)
     {
         this.peekToken.next = this.Next();
         this.specialTracker.InformToken(this.peekToken.next.kind);
     }
     this.peekToken = this.peekToken.next;
     return this.peekToken;
 }
示例#13
0
 public void StartPeek()
 {
     this.peekToken = this.curToken;
 }