コード例 #1
0
        //fetch the primary key for the dataset or set to invalid
        int RefreshObjDeclID(ObjDecl theObj)
        {
            String _SQL = ("SELECT ID from ObjectDecl where ClassID=='");

            _SQL += theObj.ClassID() + "' AND Function='" + theObj.Function() + "';";
            int     Return = 0;
            Boolean Exists = false;

            try {
                SQLiteCommand    command = new SQLiteCommand(_SQL, m_dbConnection);
                SQLiteDataReader reader  = command.ExecuteReader();
                while (reader.Read())
                {
                    //Todo fix non exist
                    Exists = true;
                    Return = reader.GetInt32(reader.GetOrdinal("ID"));
                }
                reader.Dispose();
                command.Dispose();
            } catch (Exception e) {
                HandleDBError(e);
            }
            theObj.updateID(Return);
            return(Return);
        }
コード例 #2
0
        //insert/update ObjectDeclaration
        public void UpdateObjDecl(ObjDecl theObj)
        {
            RefreshObjDeclID(theObj);

            DateTime Now = DateTime.Now;
            String   _SQL;

            if (theObj.ID() > 0)
            {
                _SQL = "Update ObjectDecl Set ClassID='" +
                       theObj.ClassID() +
                       "',Function='" + theObj.Function() +
                       "',Params='" + theObj.Params() +
                       "',Returns='" + theObj.Returns() +
                       "',ClassType=" + ((int)theObj.ClassType()).ToString() +
                       " ,State=1" +
                       " ,Descr='" + theObj.Description() +
                       " ',Time=" + (Now.ToBinary().ToString()) +
                       " ,Start=" + theObj.StartPos() +
                       " ,Length=" + theObj.Length() +
                       " where ID=" + (theObj.ID().ToString());
            }
            else
            {
                _SQL = "INSERT INTO ObjectDecl (ClassID, Function, Params, Returns, ClassType, State, Time,Descr,Start,Length) VALUES('" +
                       theObj.ClassID() +
                       "', '" + theObj.Function() + "', '" + theObj.Params() +
                       "', '" + theObj.Returns() + "', " + ((int)theObj.ClassType()).ToString() +
                       ",1" + "," + (Now.ToBinary().ToString()) + ",'" + theObj.Description() + "'," + theObj.StartPos() + "," + theObj.Length() + ");";
            }

            ExecuteSimpleQuery(_SQL);
            RefreshObjDeclID(theObj);   //get Ids after insert
        }
コード例 #3
0
 void PublishCmdToDB(String Scope, Parser2.CmdBase Cmd)
 {
     if (Scope != m_LastScope)
     {
         m_LastCmd = null;
     }
     if (Cmd.GetType().Equals(typeof(Parser2.CmdComment)))
     {
         Parser2.CmdComment Cmd2 = (Parser2.CmdComment)Cmd;
         m_LastCmd = Cmd2;
     }
     else if (Cmd.GetType().Equals(typeof(Parser2.CmdDecl)))
     {
         Parser2.CmdDecl Cmd2 = (Parser2.CmdDecl)Cmd;
         Obj             _obj = new Obj(Scope, Cmd2.m_Name, Cmd2.m_Type, Cmd2.Description(), Cmd2.StartPos(), Cmd2.Length());
         UpdateObjList(_obj);
     }
     else if (Cmd.GetType().Equals(typeof(Parser2.CmdInclude)))
     {
         Parser2.CmdInclude Cmd2 = (Parser2.CmdInclude)Cmd;
         Obj _obj = new Obj(Scope, Cmd2.m_Path,
                            /*m_ProjectDir +*/ getSeqDir(getSubProj()[0] /*??*/) + "\\" + Cmd2.m_Path, Cmd2.Description(), Cmd2.StartPos(), Cmd2.Length()); //Todo das ist falsch bei Subproject-Includes
         UpdateObjList(_obj);
     }
     else if (Cmd.GetType().Equals(typeof(Parser2.CmdUsing)))
     {
         Parser2.CmdUsing Cmd2 = (Parser2.CmdUsing)Cmd;
         Obj _obj = new Obj(Scope, Cmd2.m_Name,
                            /*m_ProjectDir +*/ getSourceDir() + "\\" + Cmd2.m_Path, Cmd2.Description(), Cmd2.StartPos(), Cmd2.Length());
         UpdateObjList(_obj);
         //Todo need to get the functions for this lvclass to put them into ObjDecl
         UpdateObjDecl(new ObjDecl(_obj.ClassID(), ObjDecl.TClassType.tCTClass, "Init", "", "", "", 0, 0));
     }
     else if (Cmd.GetType().Equals(typeof(Parser2.CmdFunctionDecl)))
     {
         Parser2.CmdFunctionDecl Cmd2 = (Parser2.CmdFunctionDecl)Cmd;
         ObjDecl _objDecl             = new ObjDecl(Scope,
                                                    /* m_IsClassDef*/ false ? ObjDecl.TClassType.tCTFunc : ObjDecl.TClassType.tCTSeq,
                                                    Cmd2.m_Name, Cmd2.m_Params.ToString(), Cmd2.m_Returns.ToString(),
                                                    (m_LastCmd != null ? m_LastCmd.AsText():Cmd2.Description()),
                                                    Cmd2.StartPos(), Cmd2.Length());
         UpdateObjDecl(_objDecl);
         m_LastCmd = null;
     }
     m_LastScope = Scope;
 }
コード例 #4
0
        /*assumption:
         * - pro Zeile nur ein Kommando
         * - Kommando nicht über mehrere Zeilen verteilt
         * - Zeile wird mit \r,\n oder \r\n abgeschlossen
         * - nach functionskopf oder Variablendeklaration kann Kommentar eingeschoben sein
         */
        private void evaluate(String Line, int LineNo)
        {
            Obj     _obj;
            ObjDecl _objDecl;
            int     _offset = 0;
            int     _found, _foundB, _foundC;
            String  _A, _B, _C;

            Line = parseComment(Line);
            //whitespaces should be normalized and comments removed
            Line = NormalizeWhitespace(Line);

            // using "Objects\Calculator\Calculator_Commander.vi" as Calc
            _found = Line.IndexOf("using ", _offset); // das wäre sicherer mit #using
            if (_found != -1 && _found < 5)
            {
                _offset = _offset + _found + 7;                          // after using "
                _found  = Line.IndexOf(" as ", _offset);
                _A      = Line.Substring(_offset, _found - _offset - 1); //strip of ""
                _A      = _A.Replace(".vi", ".seq");                     //classID should point to description file, not commander
                _B      = Line.Substring(_found + 4);
                _obj    = new Obj(m_Scope, _B,
                                  m_Project + m_Model.getSourceDir() + "\\" + _A, m_Comment);
                m_Model.UpdateObjList(_obj);
                m_Comment = ""; m_SlashStarComment = false;
                //return;
            }
            // #include test1.seq
            _found = Line.IndexOf("#include", _offset);
            if (_found != -1)
            {
                _offset = _offset + _found + 9;                                            // after #include
                _A      = Line.Substring(_offset);
                _A      = _A.Substring(1, _A.Length - 1 - 1);                              //strip off ""
                _obj    = new Obj(m_Scope, _A,
                                  m_Project + m_Model.getSeqDir() + "\\" + _A, m_Comment); //Todo das ist falsch bei Subproject-Includes
                m_Model.UpdateObjList(_obj);
                m_Comment = ""; m_SlashStarComment = false;
                //return;
            }
            // function boolAnd (bool bA, bool bB) ->bool bReturn
            //or  function boolAnd (bool bA, bool bB)
            _found = Line.IndexOf("function", _offset);
            if (_found != -1)
            {
                _C      = "";
                _offset = _offset + _found + 9; // after function
                _foundC = Line.IndexOf("->", _offset);
                if (_foundC != -1)
                {
                    _C = Line.Substring(_foundC + 2);   // after ->
                }
                else
                {
                    _foundC = Line.Length;
                }
                _foundB = Line.IndexOf("(", _offset);
                if (_foundB != -1)
                {
                    _B       = Line.Substring(_foundB + 1, _foundC - _foundB - 2); // in between ( )
                    _A       = Line.Substring(_offset, _foundB - _offset);
                    _objDecl = new ObjDecl(m_Scope,
                                           m_IsClassDef ? ObjDecl.TClassType.tCTFunc : ObjDecl.TClassType.tCTSeq,
                                           _A, _B, _C, m_Comment);
                    m_Model.UpdateObjDecl(_objDecl);
                    m_Comment = ""; m_SlashStarComment = false;
                }
                //return;
            }
            //is it some variable initializer?
            for (int i = 0; i < ModelDocument.BASIC_TYPES.Count; i++)
            {
                _found = Line.IndexOf(ModelDocument.BASIC_TYPES[i] + " ", 0);
                if (_found == 0)   //datatype should be at start of line, not in between ()
                {
                    _A      = ModelDocument.BASIC_TYPES[i];
                    _foundB = _found + (_A.Length + 1);
                    _foundC = Line.IndexOf('=', _foundB);       // double fVolt=2.5
                    if (_foundC == -1)
                    {
                        _foundC = Line.IndexOf(';', _foundB);   // int iX;
                        if (_foundC == -1)
                        {
                            _foundC = Line.Length; // int iX<lf>
                        }
                    }
                    _B   = Line.Substring(_foundB, _foundC - _foundB);
                    _obj = new Obj(m_Scope, _B, _A, m_Comment);
                    m_Model.UpdateObjList(_obj);
                    m_Comment = ""; m_SlashStarComment = false;
                }
            }

            /*
             * _found = Line.indexOf("{", _offset);
             * if (_found != -1) {
             *  _offset = _offset + _found + 1;
             *  m_FoldMarkersDepth = m_FoldMarkersDepth + 1;
             *  if (m_FoldMarkersDepth == 1)    //Todo we actually only create foldmarkers for functions; not for/While/if
             *      m_FoldMarkers.add(new Position(TextOffset, 0));
             * }
             * _found = Line.indexOf("}", _offset);
             * if (_found != -1) {
             *  _offset = _offset + _found + 1;
             *  m_FoldMarkersDepth = m_FoldMarkersDepth - 1;
             *  if (m_FoldMarkersDepth == 1) {
             *      Position p = m_FoldMarkers.get(m_FoldMarkers.size() - 1);
             *      p.setLength(TextOffset - p.getOffset());
             *  }
             * }*/
        }
コード例 #5
0
        void RebuildObjList()
        {
            // add the basic types to Intelisense
            ObjDecl _A;

            for (int i = 0; i < BASIC_TYPES.Count; i++)
            {
                _A = new ObjDecl(BASIC_TYPES[i], ObjDecl.TClassType.tCTType, "", "", "", "", 0, 0);
                UpdateObjDecl(_A);
            }
            DateTime _start = DateTime.Now;
            //Log.getInstance().Add("collecting files ", Log.EnuSeverity.Info, "");
            Tokenizer _tokenizer = new Tokenizer();
            LinkedList <Tokenizer.Token> _Tokens = new LinkedList <Tokenizer.Token>();
            List <String> Dirs = new List <String>(); //stack of directories relative to _path
            int           k    = 0;

            try {
                String[] _SubProj = getSubProj();
                for (int i = 0; i < _SubProj.Length; i++)
                {
                    Dirs.Add(Path.Combine(m_ProjectDir, getSeqDir(_SubProj[i])));
                }

                while (k < Dirs.Count)
                {
                    FileInfo[] _files = new DirectoryInfo(Dirs[k]).GetFiles();
                    for (int i = 0; i < _files.Length; i++)
                    {
                        if (_files[i].Extension.Equals(".seq", StringComparison.OrdinalIgnoreCase))
                        {
                            _Tokens.AddLast(_tokenizer.TokenizeFile(_files[i].FullName));
                            NPP.SetFoldLevel(1, 1, true); //Todo !!
                            NPP.SetFoldLevel(2, 2, false);
                            NPP.SetFoldLevel(3, 2, false);
                            NPP.SetFoldLevel(4, 1, false);
                        }
                    }
                    DirectoryInfo[] _Dirs = new DirectoryInfo(Dirs[k]).GetDirectories();
                    for (int i = 0; i < _Dirs.Length; i++)
                    {
                        // If the file is a directory (or is in some way invalid) we'll skip it
                        Dirs.Insert(k + 1, _Dirs[i].FullName);
                    }
                    k++;
                }
                //Log.getInstance().Add("Tokenized all" , Log.EnuSeverity.Info, "");
                Parser2 _parser2 = new Parser2(this, m_ProjectDir);
                _parser2.ParseTokens(_Tokens);
                LinkedList <Parser2.Context.Log> .Enumerator _l = _parser2.GetLogs().GetEnumerator();
                while (_l.MoveNext())
                {
                    Log.getInstance().Add(_l.Current.m_Text, Log.EnuSeverity.Warn, _l.Current.m_Cmd.AsText());
                }
                //update database with parserresult
                LinkedList <Parser2.CmdBase> .Enumerator _Cmds;
                List <String> .Enumerator _Scopes = _parser2.GetScopes().GetEnumerator();
                while (_Scopes.MoveNext())
                {
                    //Log.getInstance().Add("write DB " + _Scopes.Current, Log.EnuSeverity.Info, "");
                    // if(!m_IsClassDef) {
                    { //each SEQ includes itself
                        this.UpdateObjList(new Obj(_Scopes.Current, "", _Scopes.Current, "", 0, 0));
                    }
                    _Cmds = _parser2.GetCmds(_Scopes.Current).GetEnumerator();
                    while (_Cmds.MoveNext())
                    {
                        PublishCmdToDB(_Scopes.Current, _Cmds.Current);
                    }
                }
                Log.getInstance().Add("Parsing done ", Log.EnuSeverity.Info, "");
            } catch (Exception ex) {
                Log.getInstance().Add(ex.Message, Log.EnuSeverity.Error, "");
            }
            finally {
            }
        }