protected void createLabel(CElement parent, IToken token) throws CModelException { String labelName = token.getImage(); int index = getGlobalLabelIndex(labelName); boolean global = index > 0; if (!global) { index = registerLabel(labelName); } AsmLabel label = new AsmLabel(parent, labelName, global, index); SourceManipulationInfo labelInfo = label.getSourceManipulationInfo(); labelInfo.setIdPos(token.getOffset(), token.getLength()); labelInfo.setPos(token.getOffset(), token.getLength()); if (fLastLabel != null) { fixupLastLabel(); } if (global) { // new global label if (fLastGlobalLabel != null) { fixupLastGlobalLabel(); } fLastGlobalLabel = label; } else { // add under global label if available if (fLastGlobalLabel != null) { parent = fLastGlobalLabel; } } fLastLabel = label; parent.addChild(label); }
/** * Set the body position of the last label. * * @throws CModelException */ private void fixupLastLabel() throws CModelException { if (fLastLabelEndOffset > 0) { SourceManipulationInfo labelInfo = fLastLabel.getSourceManipulationInfo(); labelInfo.setPos(labelInfo.getStartPos(), fLastLabelEndOffset - labelInfo.getStartPos()); // TLETODO set line info fLastLabelEndOffset = 0; } }
/** * Set the body position of the last global label. * * @throws CModelException */ private void fixupLastGlobalLabel() throws CModelException { if (fLastLabel != null && fLastLabel != fLastGlobalLabel) { SourceManipulationInfo globalLabelInfo = fLastGlobalLabel.getSourceManipulationInfo(); SourceManipulationInfo labelInfo = fLastLabel.getSourceManipulationInfo(); globalLabelInfo.setPos( globalLabelInfo.getStartPos(), labelInfo.getStartPos() + labelInfo.getLength() - globalLabelInfo.getStartPos()); // TLETODO set line info } }
private void parsePPDefine(CElement parent) throws CModelException, OffsetLimitReachedException { int startOffset = fLexer.currentToken().getOffset(); int nameStart = 0; int nameEnd = 0; String name = null; IToken t = nextToken(); if (t.getType() == IToken.tIDENTIFIER) { nameStart = fLexer.currentToken().getOffset(); nameEnd = fLexer.currentToken().getEndOffset(); name = t.getImage(); } if (name == null) { return; } int endOffset = skipToNewLine(); Macro macro = new Macro(parent, name); SourceManipulationInfo macroInfo = macro.getSourceManipulationInfo(); macroInfo.setIdPos(nameStart, nameEnd - nameStart); macroInfo.setPos(startOffset, endOffset - startOffset); parent.addChild(macro); }
private void parsePPInclude(CElement parent) throws CModelException, OffsetLimitReachedException { int startOffset = fLexer.currentToken().getOffset(); int nameStart = 0; int nameEnd = 0; String name = null; boolean isStandard = false; IToken t = nextToken(); switch (t.getType()) { case IToken.tLT: nameStart = fLexer.currentToken().getOffset(); do { t = nextToken(); } while (t.getType() != IToken.tGT); nameEnd = fLexer.currentToken().getEndOffset(); name = new String(fLexer.getInputChars(nameStart + 1, nameEnd - 1)); isStandard = true; break; case IToken.tSTRING: nameStart = fLexer.currentToken().getOffset(); nameEnd = fLexer.currentToken().getEndOffset(); name = t.getImage().substring(1, t.getLength() - 1); break; case IToken.tIDENTIFIER: nameStart = fLexer.currentToken().getOffset(); nameEnd = fLexer.currentToken().getEndOffset(); name = t.getImage(); break; default: } if (name == null) { return; } int endOffset = skipToNewLine(); Include include = new Include(parent, name, isStandard); SourceManipulationInfo includeInfo = include.getSourceManipulationInfo(); includeInfo.setIdPos(nameStart, nameEnd - nameStart); includeInfo.setPos(startOffset, endOffset - startOffset); parent.addChild(include); }