//------------------------------------------------------------ // ERRLOC Constructor (3) // /// <para>Constructor.</para> /// <para>Get the current position from the BASENODE argument and /// mapping information from INFILESYM.SourceData of BSYMMGR.</para> /// <param name="symmgr"></param> /// <param name="node"></param> //------------------------------------------------------------ internal ERRLOC(BSYMMGR symmgr, BASENODE node, bool fullPath) { if (node != null) { DebugUtil.Assert(symmgr != null); string inputFileName = node.GetContainingFileName(fullPath); INFILESYM inputFile = symmgr.FindInfileSym(inputFileName); sourceFileName = inputFileName; sourceMapFileName = inputFileName; if (inputFile != null) { sourceData = inputFile.SourceData; SetLine(node); SetStart(node); SetEnd(node); mapStartPos = (startPos != null ? startPos.Clone() : null); mapEndPos = (endPos != null ? endPos.Clone() : null); string sd; bool bd1, bd2; sourceData.Module.MapLocation(mapStartPos, out sourceMapFileName, out bd1, out bd2); sourceData.Module.MapLocation(mapEndPos, out sd, out bd1, out bd2); return; } } }
//------------------------------------------------------------ // POSDATA Constructor (3) // /// <summary> /// Constructor. Copy from other POSDATA instance. /// </summary> /// <param name="p"></param> //------------------------------------------------------------ internal POSDATA(POSDATA p) { CharIndex = p.CharIndex; UserByte = p.UserByte; LineIndex = p.LineIndex; UserBits = p.UserBits; }
//------------------------------------------------------------ // ERRLOC Constructor (2) // /// <summary> /// <para>Constructor.</para> /// <para>Get the current position from the BASENODE argument and /// mapping information from INFILESYM.SourceData.</para> /// </summary> /// <param name="inputFile"></param> /// <param name="node"></param> //------------------------------------------------------------ internal ERRLOC(INFILESYM inputFile, BASENODE node, bool fullPath) { DebugUtil.Assert(inputFile != null); sourceData = inputFile.SourceData; sourceFileName = (fullPath ? inputFile.FullName : inputFile.Name); sourceMapFileName = inputFile.Name; if (node != null) { SetLine(node); SetStart(node); this.endPos = new POSDATA(); //endPos.SetUninitialized(); SetEnd(node); mapStartPos = (startPos != null ? startPos.Clone() : null); mapEndPos = (endPos != null ? endPos.Clone() : null); string sd; // dummy bool bd1, bd2; // dummy // mapStart、mapEnd の行番号をマップ先のもので置き換え、ファイル名を取得する。 sourceData.Module.MapLocation(mapStartPos, out sourceMapFileName, out bd1, out bd2); sourceData.Module.MapLocation(mapEndPos, out sd, out bd1, out bd2); } }
//------------------------------------------------------------ // POSDATA.Adjust // /// <summary> /// Move this by reference to posOld and posNew. /// </summary> /// <param name="posOld"></param> /// <param name="posNew"></param> /// <returns></returns> /// <remarks> /// <para>Like string insertion of editors.</para> /// <para>Why do nothing when this and old are equal?</para> /// </remarks> //------------------------------------------------------------ internal bool Adjust(POSDATA posOld, POSDATA posNew) { DebugUtil.Assert(posOld != null && posNew != null); DebugUtil.Assert(!this.IsUninitialized && !posOld.IsUninitialized && !posNew.IsUninitialized); // Nothing to adjust if the change is below us, or isn't really a change if (posOld.LineIndex > LineIndex || posOld.Equals(posNew)) { return(false); } if (posOld.LineIndex == LineIndex) { // The old position is on the same line as us. If the // char position is before us, update it. if (posOld.CharIndex < CharIndex) { CharIndex += (posNew.CharIndex - posOld.CharIndex); LineIndex = posNew.LineIndex; return(true); } return(false); } // The line must be above us, so just update our line LineIndex += (posNew.LineIndex - posOld.LineIndex); return(((posNew.LineIndex - posOld.LineIndex) != 0) ? true : false); }
//------------------------------------------------------------ // CSourceData.LookupNode //------------------------------------------------------------ //STDMETHODIMP CSourceData::LookupNode ( // NAME *pKey, long iOrdinal, BASENODE **ppNode, long *piGlobalOrdinal) //virtual internal int LookupNode( // ref string pKey, int iOrdinal, ref BASENODE ppNode, ref int piGlobalOrdinal) //{ // return sourceModuleBase.LookupNode (this, pKey, iOrdinal, ppNode, piGlobalOrdinal); //} //------------------------------------------------------------ // CSourceData.GetNodeKeyOrdinal //------------------------------------------------------------ //STDMETHODIMP CSourceData::GetNodeKeyOrdinal (BASENODE *pNode, NAME **ppKey, long *piKeyOrdinal) //virtual internal int GetNodeKeyOrdinal(BASENODE pNode, ref string ppKey, ref int piKeyOrdinal) //{ // return sourceModuleBase.GetNodeKeyOrdinal (this, pNode, ppKey, piKeyOrdinal); //} //------------------------------------------------------------ // CSourceData.GetGlobalKeyArray //------------------------------------------------------------ //STDMETHODIMP CSourceData::GetGlobalKeyArray (KEYEDNODE *pKeyedNodes, long iSize, long *piCopied) //virtual internal int GetGlobalKeyArray(KEYEDNODE pKeyedNodes, int iSize, ref int piCopied) //{ // return sourceModuleBase.GetGlobalKeyArray (this, pKeyedNodes, iSize, piCopied); //} //------------------------------------------------------------ // CSourceData.ParseForErrors //------------------------------------------------------------ //STDMETHODIMP CSourceData::ParseForErrors () //virtual internal int ParseForErrors() //{ // return sourceModuleBase.ParseForErrors (this); //} //------------------------------------------------------------ // CSourceData.FindLeafNode //------------------------------------------------------------ //STDMETHODIMP CSourceData::FindLeafNode ( // const POSDATA pos, BASENODE **ppNode, ICSInteriorTree **ppTree) //virtual internal int FindLeafNode(POSDATA pos, ref BASENODE ppNode, ref CInteriorTree ppTree) //{ // return FindLeafNodeEx(pos, EF_FULL, ppNode, ppTree); //} //------------------------------------------------------------ // CSourceData.FindLeafNodeForToken //------------------------------------------------------------ //STDMETHODIMP CSourceData::FindLeafNodeForToken ( // long iToken, BASENODE **ppNode, ICSInteriorTree **ppTree) //virtual internal int FindLeafNodeForToken( // int iToken, ref BASENODE ppNode, ref CInteriorTree ppTree) //{ // return FindLeafNodeForTokenEx(iToken, EF_FULL, ppNode, ppTree); //} //------------------------------------------------------------ // CSourceData.FindLeafNodeEx //------------------------------------------------------------ //STDMETHODIMP CSourceData::FindLeafNodeEx ( // const POSDATA pos, ExtentFlags flags, BASENODE **ppNode, ICSInteriorTree **ppTree) //virtual internal int FindLeafNodeEx( // POSDATA pos, ExtentFlags flags, ref BASENODE ppNode, ref CInteriorTree ppTree) //{ // return sourceModuleBase.FindLeafNodeEx (this, pos, flags, ppNode, ppTree); //} //------------------------------------------------------------ // CSourceData.FindLeafNodeForTokenEx //------------------------------------------------------------ //STDMETHODIMP CSourceData::FindLeafNodeForTokenEx ( // long iToken, ExtentFlags flags, BASENODE **ppNode, ICSInteriorTree **ppTree) //virtual internal int FindLeafNodeForTokenEx( // int iToken, ExtentFlags flags, ref BASENODE ppNode, ref CInteriorTree ppTree) //{ // return sourceModuleBase.FindLeafNodeForTokenEx (this, iToken, flags, ppNode, ppTree); //} //------------------------------------------------------------ // CSourceData.GetExtent //------------------------------------------------------------ //virtual internal int GetExtent(BASENODE pNode, POSDATA pposStart, POSDATA pposEnd) //{ //} //STDMETHODIMP CSourceData::GetExtent(BASENODE *pNode, POSDATA *pposStart, POSDATA *pposEnd) { // return GetExtentEx( pNode, pposStart, pposEnd, EF_FULL); //}; //------------------------------------------------------------ // CSourceData.GetExtentEx // /// <summary></summary> /// <param name="node"></param> /// <param name="start"></param> /// <param name="end"></param> /// <param name="flags"></param> /// <returns></returns> //------------------------------------------------------------ virtual internal bool GetExtentEx( BASENODE node, POSDATA start, POSDATA end, ExtentFlags flags) { return(sourceModuleBase.GetExtent(node, start, end, flags)); }
//------------------------------------------------------------ // POSDATA.Compare // /// <summary> /// Compare position with other instance and return a integer. /// <list type="bullet"> /// <item>< 0 : this precedes p.</item> /// <item>= 0 : same position.</item> /// <item>> 0 : p precedes this.</item> /// </list> /// </summary> /// <param name="p"></param> /// <returns></returns> //------------------------------------------------------------ internal int Compare(POSDATA p) { DebugUtil.Assert(!this.IsUninitialized && p != null && !p.IsUninitialized); int ld = this.LineIndex - p.LineIndex; return((ld != 0) ? ld: this.CharIndex - p.CharIndex); }
//------------------------------------------------------------ // POSDATA.Before // /// <summary></summary> /// <param name="pos"></param> /// <returns></returns> //------------------------------------------------------------ internal bool Before(POSDATA pos) { DebugUtil.Assert(pos != null); int ld = this.LineIndex - pos.LineIndex; return((ld != 0) ? ld < 0 : (this.CharIndex < pos.CharIndex)); }
//------------------------------------------------------------ // CSourceText.GetText (ICSSourceText) // /// <summary> /// Return the text and initialize the argument posEnd. /// </summary> /// <param name="posEnd"></param> /// <returns></returns> //------------------------------------------------------------ virtual public string GetText(ref POSDATA posEnd) { if (posEnd != null) { posEnd.LineIndex = 0; posEnd.CharIndex = 0; } return(sourceText); }
//------------------------------------------------------------ // ERRLOC Constructor (8) // /// <summary></summary> /// <param name="filename"></param> /// <param name="start"></param> /// <param name="end"></param> //------------------------------------------------------------ internal ERRLOC(string filename, POSDATA start, POSDATA end) { sourceData = null; this.startPos = start; this.endPos = end; this.mapStartPos = (start != null ? start.Clone() : null); this.mapEndPos = (end != null ? end.Clone() : null); sourceMapFileName = sourceFileName = filename; }
//------------------------------------------------------------ // POSDATA.CopyFrom // /// <summary> /// Set fields by the values which other holds. /// </summary> /// <param name="other"></param> //------------------------------------------------------------ internal void CopyFrom(POSDATA other) { if (other == null) { return; } this.CharIndex = other.CharIndex; this.UserByte = other.UserByte; this.LineIndex = other.LineIndex; this.UserBits = other.UserBits; }
//------------------------------------------------------------ // CLineMap.Map (2) // /// <summary> /// <para>Search a PPLINE instance for the line number of pos, and return its data.</para> /// <para>Set the line found to pos.</para> /// </summary> /// <param name="pos"></param> /// <param name="fileName"></param> /// <param name="isHidden"></param> /// <param name="isMapped"></param> //------------------------------------------------------------ internal void Map(POSDATA pos, out string fileName, out bool isHidden, out bool isMapped) { fileName = null; isHidden = false; isMapped = false; if (mapList != null) { pos.LineIndex = InternalMap(pos.LineIndex, out fileName, out isHidden, out isMapped); } }
//------------------------------------------------------------ // ERRLOC Constructor (6) // /// <summary></summary> /// <param name="data"></param> /// <param name="start"></param> /// <param name="end"></param> //------------------------------------------------------------ internal ERRLOC(CSourceData data, POSDATA start, POSDATA end) { DebugUtil.Assert(data != null); this.sourceData = data; this.startPos = start; this.endPos = end; mapStartPos = (start != null ? start.Clone() : null); mapEndPos = (end != null ? end.Clone() : null); InitFromSourceModule(this.sourceData.Module); }
//------------------------------------------------------------ // ERRLOC Constructor (7) // /// <summary></summary> /// <param name="sourceModule"></param> /// <param name="start"></param> /// <param name="end"></param> //------------------------------------------------------------ internal ERRLOC(CSourceModuleBase sourceModule, POSDATA start, POSDATA end) { DebugUtil.Assert(sourceModule != null); this.sourceData = null; this.startPos = start; this.endPos = end; this.mapStartPos = (start != null ? start.Clone() : null); this.mapEndPos = (end != null ? end.Clone() : null); InitFromSourceModule(sourceModule); }
//------------------------------------------------------------ // ERRLOC.SetStartInternal (2) // /// <summary> /// <para>only set the start if it is on the same line /// as we want to report the error on</para> /// </summary> /// <param name="lexData"></param> /// <param name="tokenIndex"></param> /// <param name="tokenOffset"></param> //------------------------------------------------------------ private void SetStartInternal( LEXDATA lexData, int tokenIndex, int tokenOffset) // = 0 { DebugUtil.Assert(!startPos.IsUninitialized); if (tokenIndex >= 0) { //tokenIndex = CParser.PeekTokenIndexFrom(lexData, (int)tokenIndex, (int)tokenOffset); tokenIndex = lexData.PeekTokenIndexFrom(tokenIndex, tokenOffset); if (lexData.TokenAt((int)tokenIndex).LineIndex == startPos.LineIndex) { startPos = lexData.TokenAt(tokenIndex); } } }
//------------------------------------------------------------ // ERRLOC.SetEndInternal (2) // /// <summary> /// If the endPos is on the same line to startPos, /// set the StopPosition of the error token to endPos. /// </summary> /// <param name="ld"></param> /// <param name="tokidx"></param> /// <param name="tokOffset"></param> //------------------------------------------------------------ private void SetEndInternal( LEXDATA ld, int tokidx, int tokOffset) // = 0 { DebugUtil.Assert(!startPos.IsUninitialized); if (tokidx >= 0) { //tokidx = CParser.PeekTokenIndexFrom(ld, (int)tokidx, (int)tokOffset); tokidx = ld.PeekTokenIndexFrom(tokidx, tokOffset); if (ld.TokenAt(tokidx).LineIndex == startPos.LineIndex) { endPos = ld.TokenAt(tokidx).StopPosition(); } } }
//------------------------------------------------------------ // POSDATA.Clone // /// <summary> /// Duplicate this. /// </summary> /// <returns></returns> //------------------------------------------------------------ internal POSDATA Clone() { POSDATA pd = new POSDATA(this); return(pd); }
//------------------------------------------------------------ // ERRLOC.SetLine // // UNDONE: REVIEW THIS FUNCTION THOROUGHLY /// <summary> /// <para>Sets start to correct line for given node</para> /// </summary> /// <param name="node"></param> //------------------------------------------------------------ internal void SetLine(BASENODE node) { LEXDATA ld = sourceData.LexData; if (node == null || node.TokenIndex == -1 || ld == null) { return; } // default if no special processing below. startPos = ld.TokenAt(node.TokenIndex); switch (node.Kind) { case NODEKIND.ACCESSOR: // Get and Set always are the token before the '{' startPos = ld.TokenAt(ld.PeekTokenIndexFrom((int)(node as ACCESSORNODE).OpenCurlyIndex, -1)); return; case NODEKIND.CLASS: case NODEKIND.INTERFACE: case NODEKIND.STRUCT: if (node.AsAGGREGATE.NameNode != null) { SetLine(node.AsAGGREGATE.NameNode); } return; case NODEKIND.CTOR: case NODEKIND.DTOR: { int i; // Find the indentifier which must be the ctor/dtor name for (i = node.TokenIndex; i < ld.TokenCount && ld.TokenAt(i).TokenID != TOKENID.IDENTIFIER; i++) { ; } startPos = ld.TokenAt(i); return; } case NODEKIND.DELEGATE: if ((node as DELEGATENODE).NameNode != null) { SetLine((node as DELEGATENODE).NameNode); } return; case NODEKIND.ENUM: if ((node as ENUMNODE).NameNode != null) { SetLine((node as ENUMNODE).NameNode); } return; case NODEKIND.INDEXER: if (node.AsANYPROPERTY.NameNode != null) { SetLine(node.AsANYPROPERTY.NameNode); } else { long i; for (i = node.TokenIndex; i < ld.TokenCount && ld.TokenAt((int)i).TokenID != TOKENID.THIS; i++) { ; } startPos = ld.TokenAt((int)i); } return; case NODEKIND.METHOD: // METHODNODE // use the name to keep the the same as fields if ((node as METHODNODE).NameNode != null) { SetLine((node as METHODNODE).NameNode); } return; case NODEKIND.NAMESPACE: // use the name to keep the the same as fields if ((node as NAMESPACENODE).NameNode != null) { SetLine((node as NAMESPACENODE).NameNode); } else if ((node as NAMESPACENODE).UsingNode != null) { SetLine((node as NAMESPACENODE).UsingNode); } return; case NODEKIND.OPERATOR: { TOKENID tok; long i; for (i = node.TokenIndex; i < ld.TokenCount && (tok = ld.TokenAt((int)i).TokenID) != TOKENID.OPERATOR && tok != TOKENID.EXPLICIT && tok != TOKENID.IMPLICIT; i++) { ; } startPos = ld.TokenAt((int)i); return; } case NODEKIND.NEW: SetLine((node as NEWNODE).TypeNode); return; case NODEKIND.PROPERTY: if (node.AsANYPROPERTY.NameNode != null) { SetLine(node.AsANYPROPERTY.NameNode); } return; case NODEKIND.PREDEFINEDTYPE: return; case NODEKIND.ARRAYTYPE: SetLine((node as ARRAYTYPENODE).ElementTypeNode); return; case NODEKIND.NAMEDTYPE: SetLine((node as NAMEDTYPENODE).NameNode); return; case NODEKIND.POINTERTYPE: SetLine((node as POINTERTYPENODE).ElementTypeNode); return; case NODEKIND.NULLABLETYPE: SetLine((node as NULLABLETYPENODE).ElementTypeNode); return; case NODEKIND.ATTRDECL: SetLine((node as ATTRDECLNODE).NameNode); return; default: break; } }