예제 #1
0
  /**
   * 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;
  }
예제 #2
0
 /** 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);
 }
 @Override
 public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
   if (includeInactive) {
     fAllDeclarations =
         ArrayUtil.trimAt(IASTDeclaration.class, fAllDeclarations, fLastDeclaration);
     return fAllDeclarations;
   }
   return getDeclarations();
 }
예제 #4
0
 @Override
 public void addPointerOperator(IASTPointerOperator operator) {
   assertNotFrozen();
   if (operator != null) {
     operator.setParent(this);
     operator.setPropertyInParent(POINTER_OPERATOR);
     pointerOps = ArrayUtil.append(IASTPointerOperator.class, pointerOps, operator);
   }
 }
 @Override
 public void addExpression(IASTExpression e) {
   assertNotFrozen();
   if (e != null) {
     exp = ArrayUtil.appendAt(IASTExpression.class, exp, ++expPos, e);
     e.setParent(this);
     e.setPropertyInParent(SUBEXPRESSION);
   }
 }
예제 #6
0
 private static IBinding[] getContext(IASTName name) {
   IBinding[] accessibilityContext = IBinding.EMPTY_BINDING_ARRAY;
   for (IBinding binding = CPPVisitor.findEnclosingFunctionOrClass(name);
       binding != null;
       binding = binding.getOwner()) {
     if (binding instanceof ICPPMethod
         ||
         // Definition of an undeclared method.
         binding instanceof IProblemBinding
             && ((IProblemBinding) binding).getID()
                 == IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND) {
       continue;
     }
     if (binding instanceof ICPPFunction || binding instanceof ICPPClassType) {
       accessibilityContext = ArrayUtil.append(accessibilityContext, binding);
     }
   }
   return ArrayUtil.trim(accessibilityContext);
 }
 @Override
 public final void addDeclaration(IASTDeclaration decl) {
   if (decl != null) {
     decl.setParent(this);
     decl.setPropertyInParent(OWNED_DECLARATION);
     fAllDeclarations =
         ArrayUtil.appendAt(IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, decl);
     fActiveDeclarations = null;
   }
 }
예제 #8
0
 @Override
 public IBinding[] getDelegates() {
   if (delegates == null) {
     delegates = new IBinding[1];
     int i = 0;
     PDOMCPPUsingDeclaration alias = this;
     try {
       do {
         IBinding delegate = alias.getBinding();
         if (delegate != null) {
           delegates = ArrayUtil.appendAt(IBinding.class, delegates, i++, delegate);
         }
       } while ((alias = alias.getNext()) != null);
     } catch (CoreException e) {
       CCorePlugin.log(e);
     }
     delegates = ArrayUtil.trim(IBinding.class, delegates);
   }
   return delegates;
 }
예제 #9
0
  private DOMASTNodeLeaf createNode(DOMASTNodeParent parent, IASTNode node) {
    DOMASTNodeParent tree = new DOMASTNodeParent(node);
    parent.addChild(tree);

    // set filter flags
    if (node instanceof IASTProblemHolder || node instanceof IASTProblem) {
      tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PROBLEM);

      if (node instanceof IASTProblemHolder)
        astProblems =
            (IASTProblem[])
                ArrayUtil.append(
                    IASTProblem.class, astProblems, ((IASTProblemHolder) node).getProblem());
      else astProblems = (IASTProblem[]) ArrayUtil.append(IASTProblem.class, astProblems, node);
    }
    if (node instanceof IASTPreprocessorStatement)
      tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR);
    if (node instanceof IASTPreprocessorIncludeStatement)
      tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_INCLUDE_STATEMENTS);

    return tree;
  }
예제 #10
0
 private IName[] findDeclarations(IIndex index, IASTTranslationUnit ast, IBinding binding)
     throws CoreException {
   IName[] declNames = ast.getDeclarationsInAST(binding);
   for (int i = 0; i < declNames.length; i++) {
     IName name = declNames[i];
     if (name.isDefinition()) declNames[i] = null;
   }
   declNames = (IName[]) ArrayUtil.removeNulls(IName.class, declNames);
   if (declNames.length == 0) {
     declNames =
         index.findNames(
             binding, IIndex.FIND_DECLARATIONS | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
   }
   return declNames;
 }
예제 #11
0
 public IBinding[] getFoundBindings() {
   if (foundItems instanceof Object[]) {
     Object[] items = (Object[]) foundItems;
     if (items.length != 0) {
       IBinding[] bindings = new IBinding[items.length];
       int k = 0;
       for (Object item : items) {
         // Exclude using declarations, they have been expanded at this point.
         if (item instanceof IBinding
             && !(item instanceof ICPPUsingDeclaration)
             && !(item instanceof CPPCompositeBinding)) {
           bindings[k++] = (IBinding) item;
         }
       }
       if (k != 0) {
         return ArrayUtil.trimAt(IBinding.class, bindings, k - 1);
       }
     }
   }
   return IBinding.EMPTY_BINDING_ARRAY;
 }
예제 #12
0
  private boolean navigationFallBack(IASTTranslationUnit ast, IASTName sourceName, NameKind kind) {
    // Bug 102643, as a fall-back we look up the selected word in the index.
    if (fSelectedText != null && fSelectedText.length() > 0) {
      try {
        final ICProject project = fTranslationUnit.getCProject();
        final char[] name = fSelectedText.toCharArray();
        List<ICElement> elems = new ArrayList<ICElement>();

        // Bug 252549, search for names in the AST first.
        Set<IBinding> primaryBindings = new HashSet<IBinding>();
        ASTNameCollector nc = new ASTNameCollector(fSelectedText);
        ast.accept(nc);
        IASTName[] candidates = nc.getNames();
        for (IASTName astName : candidates) {
          try {
            IBinding b = astName.resolveBinding();
            if (b != null && !(b instanceof IProblemBinding)) {
              primaryBindings.add(b);
            }
          } catch (RuntimeException e) {
            CUIPlugin.log(e);
          }
        }

        // Search the index, also.
        final IndexFilter filter =
            IndexFilter.getDeclaredBindingFilter(ast.getLinkage().getLinkageID(), false);
        final IIndexBinding[] idxBindings = fIndex.findBindings(name, false, filter, fMonitor);
        for (IIndexBinding idxBinding : idxBindings) {
          primaryBindings.add(idxBinding);
        }

        // Search for a macro in the index.
        IIndexMacro[] macros = fIndex.findMacros(name, filter, fMonitor);
        for (IIndexMacro macro : macros) {
          ICElement elem = IndexUI.getCElementForMacro(project, fIndex, macro);
          if (elem != null) {
            elems.add(elem);
          }
        }

        Collection<IBinding> secondaryBindings;
        if (ast instanceof ICPPASTTranslationUnit) {
          secondaryBindings = cppRemoveSecondaryBindings(primaryBindings, sourceName);
        } else {
          secondaryBindings = defaultRemoveSecondaryBindings(primaryBindings, sourceName);
        }

        // Convert bindings to CElements.
        Collection<IBinding> bs = primaryBindings;
        for (int k = 0; k < 2; k++) {
          for (IBinding binding : bs) {
            IName[] names = findNames(fIndex, ast, kind, binding);
            // Exclude names of the same kind.
            for (int i = 0; i < names.length; i++) {
              if (getNameKind(names[i]) == kind) {
                names[i] = null;
              }
            }
            names = (IName[]) ArrayUtil.removeNulls(IName.class, names);
            convertToCElements(project, fIndex, names, elems);
          }
          // In case we did not find anything, consider the secondary bindings.
          if (!elems.isEmpty()) break;
          bs = secondaryBindings;
        }
        if (navigateCElements(elems)) {
          return true;
        }
        if (sourceName != null && sourceName.isDeclaration()) {
          // Select the name at the current location as the last resort.
          return navigateToName(sourceName);
        }
      } catch (CoreException e) {
        CUIPlugin.log(e);
      }
    }
    return false;
  }
예제 #13
0
  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);
  }
예제 #15
0
 @Override
 public IASTPointerOperator[] getPointerOperators() {
   if (pointerOps == null) return IASTPointerOperator.EMPTY_ARRAY;
   pointerOps = ArrayUtil.trim(IASTPointerOperator.class, pointerOps);
   return pointerOps;
 }
 @Override
 public IASTExpression[] getExpressions() {
   exp = ArrayUtil.trimAt(IASTExpression.class, exp, expPos);
   return exp;
 }