/** * Attempts to resolve the function using the parameters of a function call. * * @param args the arguments of a function call * @param point the name lookup context * @return the resolved or the original evaluation depending on whether function resolution * succeeded or not */ public ICPPEvaluation resolveFunction(ICPPEvaluation[] args, IASTNode point) { // Set up the LookupData. LookupData data; ICPPFunction[] functions = null; if (fFunctionSet == null) { data = new LookupData(fName, null, point); } else { functions = fFunctionSet.getBindings(); data = new LookupData( functions[0].getNameCharArray(), fFunctionSet.getTemplateArguments(), point); data.foundItems = functions; } data.setFunctionArguments(false, args); if (fImpliedObjectType != null) data.setImpliedObjectType(fImpliedObjectType); try { // Perform ADL if appropriate. if (!fQualified && fImpliedObjectType == null && !data.hasTypeOrMemberFunctionOrVariableResult()) { CPPSemantics.doKoenigLookup(data); Object[] foundItems = (Object[]) data.foundItems; if (foundItems != null && (functions == null || foundItems.length > functions.length)) { // ADL found additional functions. int start = functions == null ? 0 : functions.length; for (int i = start; i < foundItems.length; i++) { Object obj = foundItems[i]; if (obj instanceof ICPPFunction) { functions = ArrayUtil.append(ICPPFunction.class, functions, (ICPPFunction) obj); } else if (obj instanceof ICPPClassType) { functions = ArrayUtil.addAll( ICPPFunction.class, functions, ClassTypeHelper.getConstructors((ICPPClassType) obj, point)); } } // doKoenigLookup() may introduce duplicates into the result. These must be // eliminated to avoid resolveFunction() reporting an ambiguity. (Normally, when // lookup() and doKoenigLookup() are called on the same LookupData object, the // two functions coordinate using data stored in that object to eliminate // duplicates, but in this case lookup() was called before with a different // LookupData object and now we are only calling doKoenigLookup()). functions = ArrayUtil.removeDuplicates(functions); } } // Perform template instantiation and overload resolution. IBinding binding = CPPSemantics.resolveFunction(data, functions, true); if (binding instanceof ICPPFunction && !(binding instanceof ICPPUnknownBinding)) return new EvalBinding(binding, null, getTemplateDefinition()); } catch (DOMException e) { CCorePlugin.log(e); } return this; }
/** Returns definitions of bindings referenced by implicit name at the given location. */ private IName[] findImplicitTargets( IASTTranslationUnit ast, IASTNodeSelector nodeSelector, int offset, int length) throws CoreException { IName[] definitions = IName.EMPTY_ARRAY; IASTName firstName = nodeSelector.findEnclosingImplicitName(offset, length); if (firstName != null) { IASTImplicitNameOwner owner = (IASTImplicitNameOwner) firstName.getParent(); for (IASTImplicitName name : owner.getImplicitNames()) { if (((ASTNode) name).getOffset() == ((ASTNode) firstName).getOffset()) { IBinding binding = name.resolveBinding(); // Guaranteed to resolve. IName[] declNames = findDeclNames(ast, NameKind.REFERENCE, binding); definitions = ArrayUtil.addAll(definitions, declNames); } } } return ArrayUtil.trim(definitions); }
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException { if (ast == null) { return Status.OK_STATUS; } int selectionStart = fTextSelection.getOffset(); int selectionLength = fTextSelection.getLength(); final IASTNodeSelector nodeSelector = ast.getNodeSelector(null); IASTName sourceName = nodeSelector.findEnclosingName(selectionStart, selectionLength); IName[] implicitTargets = findImplicitTargets(ast, nodeSelector, selectionStart, selectionLength); if (sourceName == null) { if (implicitTargets.length > 0) { if (navigateViaCElements(fTranslationUnit.getCProject(), fIndex, implicitTargets)) return Status.OK_STATUS; } } else { boolean found = false; final IASTNode parent = sourceName.getParent(); if (parent instanceof IASTPreprocessorIncludeStatement) { openInclude(((IASTPreprocessorIncludeStatement) parent)); return Status.OK_STATUS; } NameKind kind = getNameKind(sourceName); IBinding b = sourceName.resolveBinding(); IBinding[] bindings = new IBinding[] {b}; if (b instanceof IProblemBinding) { IBinding[] candidateBindings = ((IProblemBinding) b).getCandidateBindings(); if (candidateBindings.length != 0) { bindings = candidateBindings; } } else if (kind == NameKind.DEFINITION && b instanceof IType) { // Don't navigate away from a type definition. // Select the name at the current location instead. navigateToName(sourceName); return Status.OK_STATUS; } IName[] targets = IName.EMPTY_ARRAY; String filename = ast.getFilePath(); for (IBinding binding : bindings) { if (binding != null && !(binding instanceof IProblemBinding)) { IName[] names = findDeclNames(ast, kind, binding); for (final IName name : names) { if (name != null) { if (name instanceof IIndexName && filename.equals(((IIndexName) name).getFileLocation().getFileName())) { // Exclude index names from the current file. } else if (areOverlappingNames(name, sourceName)) { // Exclude the current location. } else if (binding instanceof IParameter) { if (isInSameFunction(sourceName, name)) { targets = ArrayUtil.append(targets, name); } } else if (binding instanceof ICPPTemplateParameter) { if (isInSameTemplate(sourceName, name)) { targets = ArrayUtil.append(targets, name); } } else { targets = ArrayUtil.append(targets, name); } } } } } targets = ArrayUtil.trim(ArrayUtil.addAll(targets, implicitTargets)); if (navigateViaCElements(fTranslationUnit.getCProject(), fIndex, targets)) { found = true; } else { // Leave old method as fallback for local variables, parameters and // everything else not covered by ICElementHandle. found = navigateOneLocation(targets); } if (!found && !navigationFallBack(ast, sourceName, kind)) { fAction.reportSymbolLookupFailure(new String(sourceName.toCharArray())); } return Status.OK_STATUS; } // No enclosing name, check if we're in an include statement IASTNode node = nodeSelector.findEnclosingNode(selectionStart, selectionLength); if (node instanceof IASTPreprocessorIncludeStatement) { openInclude((IASTPreprocessorIncludeStatement) node); return Status.OK_STATUS; } else if (node instanceof IASTPreprocessorFunctionStyleMacroDefinition) { IASTPreprocessorFunctionStyleMacroDefinition mdef = (IASTPreprocessorFunctionStyleMacroDefinition) node; for (IASTFunctionStyleMacroParameter par : mdef.getParameters()) { String parName = par.getParameter(); if (parName.equals(fSelectedText)) { if (navigateToLocation(par.getFileLocation())) { return Status.OK_STATUS; } } } } if (!navigationFallBack(ast, null, NameKind.REFERENCE)) { fAction.reportSelectionMatchFailure(); } return Status.OK_STATUS; }
public void draw(Composite composite) { // create the desired layout for this wizard page ICConfigurationDescription confdesc = getConfdesc(); GridLayout theGridLayout = new GridLayout(); theGridLayout.numColumns = this.ncol; composite.setLayout(theGridLayout); GridData theGriddata; this.mAllBoardsFileNames = Helpers.getBoardsFiles(); if (this.mAllBoardsFileNames == null) { Common.log( new Status( IStatus.ERROR, Const.CORE_PLUGIN_ID, "ArduinoHelpers.getBoardsFiles() returns null.\nThis should not happen.\nIt looks like the download of the boards failed.")); //$NON-NLS-1$ } Arrays.sort(this.mAllBoardsFileNames); this.mAllBoardsFiles = new Boards[this.mAllBoardsFileNames.length]; for (int currentBoardFile = 0; currentBoardFile < this.mAllBoardsFileNames.length; currentBoardFile++) { this.mAllBoardsFiles[currentBoardFile] = new Boards(new File(this.mAllBoardsFileNames[currentBoardFile])); } switch (this.mAllBoardsFileNames.length) { case 0: Common.log( new Status( IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.error_no_platform_files_found, null)); break; case 1: { break; } default: { // create a combo to select the boards createLabel(composite, this.ncol, "The boards.txt file you want to use"); // $NON-NLS-1$ new Label(composite, SWT.NONE).setText("Boards.txt file:"); // $NON-NLS-1$ } } this.mControlBoardsTxtFile = new Combo(composite, SWT.BORDER | SWT.READ_ONLY); theGriddata = new GridData(); theGriddata.horizontalAlignment = SWT.FILL; theGriddata.horizontalSpan = (this.ncol - 1); this.mControlBoardsTxtFile.setLayoutData(theGriddata); this.mControlBoardsTxtFile.setEnabled(false); this.mControlBoardsTxtFile.setItems(this.mAllBoardsFileNames); createLine(composite, this.ncol); // ------- // ------ createLabel(composite, this.ncol, "Your Arduino board specifications"); // $NON-NLS-1$ new Label(composite, SWT.NONE).setText("Board:"); // $NON-NLS-1$ this.mcontrolBoardName = new Combo(composite, SWT.BORDER | SWT.READ_ONLY); theGriddata = new GridData(); theGriddata.horizontalAlignment = SWT.FILL; theGriddata.horizontalSpan = (this.ncol - 1); this.mcontrolBoardName.setLayoutData(theGriddata); this.mcontrolBoardName.setEnabled(false); // ---- this.mControlUploadPort = new LabelCombo( composite, Messages.ui_port, this.ncol - 1, Const.ENV_KEY_JANTJE_COM_PORT, false); this.mControlUploadPort.setItems( ArrayUtil.addAll(Activator.bonjourDiscovery.getList(), Common.listComPorts())); createLine(composite, this.ncol); String[] menuNames = new String[30]; for (int curBoardsFile = 0; curBoardsFile < this.mAllBoardsFiles.length; curBoardsFile++) { ArrayUtil.addAll(menuNames, this.mAllBoardsFiles[curBoardsFile].getMenuNames()); } menuNames = ArrayUtil.removeDuplicates(menuNames); this.mBoardOptionCombos = new LabelCombo[menuNames.length]; for (int currentOption = 0; currentOption < menuNames.length; currentOption++) { String menuName = menuNames[currentOption]; this.mBoardOptionCombos[currentOption] = new LabelCombo( composite, menuName, this.ncol - 1, Const.ENV_KEY_JANTJE_START + menuName, true); } // Create the control to alert parents of changes this.mFeedbackControl = new Text(composite, SWT.None); this.mFeedbackControl.setVisible(false); this.mFeedbackControl.setEnabled(false); theGriddata = new GridData(); theGriddata.horizontalSpan = 0; this.mFeedbackControl.setLayoutData(theGriddata); // End of special controls setValues(confdesc); // enable the listeners childFieldListener controlUploadPortlistener = new childFieldListener(); controlUploadPortlistener.setInfo(this.mControlUploadPort); this.mControlUploadPort.addListener(controlUploadPortlistener); this.mcontrolBoardName.addListener(SWT.Modify, this.BoardModifyListener); this.mControlBoardsTxtFile.addListener(SWT.Modify, this.boardFileModifyListener); for (LabelCombo curLabelCombo : this.mBoardOptionCombos) { childFieldListener comboboxModifyListener = new childFieldListener(); comboboxModifyListener.setInfo(curLabelCombo); curLabelCombo.addListener(comboboxModifyListener); } EnableControls(); Dialog.applyDialogFont(composite); }