Пример #1
0
 private HashMap<String, HashMap<String, IVariable>> getModuleDescriptors(
     IVariable[] variables, NesCVariableNameParser varPars) {
   HashMap<String, HashMap<String, IVariable>> res =
       new HashMap<String, HashMap<String, IVariable>>();
   for (IVariable var : variables) {
     try {
       if (varPars.isNesCVariable(var.getName())) {
         String name = var.getName();
         String desc = varPars.getModuleName(name);
         String varName = varPars.getVariableName(name);
         if (desc != null) {
           HashMap<String, IVariable> modVars = res.get(desc);
           if (modVars == null) {
             modVars = new HashMap<String, IVariable>();
             res.put(desc, modVars);
           }
           modVars.put(varName, var);
         }
       }
     } catch (DebugException e) {
       TinyOSDebugPlugin.getDefault().log("Exception while extracting module descriptors.", e);
     }
   }
   return res;
 }
Пример #2
0
    private void addVariable(IVariable var, NesCVariableNameParser varPars, TreeParent parent) {
      try {
        IValue val = var.getValue();
        String cVarName = var.getName();
        String name = varPars.getVariableName(cVarName);
        TreeNode node = parent.hasChild(name);
        if (val.hasVariables()) {
          // var consists of multiple inner variables... (like for example a struct)
          if (node == null) {
            node = new TreeParent(name);
            node.setData(var);
            parent.addChild(node);
          }
          for (IVariable innerVar : val.getVariables()) {
            addVariable(innerVar, varPars, (TreeParent) node);
          }
        } else {
          if (node == null) {
            node = new TreeParent(name); // Leaf
            node.setData(var);
            parent.addChild(node);
          }
        }

      } catch (DebugException e) {
        TinyOSDebugPlugin.getDefault().log("Exception while adding variable to tree.", e);
      }
    }
Пример #3
0
 public String toString() {
   String res = getName();
   if (data instanceof IVariable) {
     IVariable var = (IVariable) data;
     try {
       String value = var.getValue().getValueString();
       res += " " + ASSIGNMENT + " " + value;
     } catch (DebugException e) {
       TinyOSDebugPlugin.getDefault().log("Could not get value from variable", e);
     }
   }
   return res;
 }
Пример #4
0
  private void addNescVariables(DebugEvent[] events) {
    if (m_isTerminated) return;

    for (DebugEvent event : events) {
      Object element = event.getSource();

      if (element instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) element;

        ILaunch launch = (ILaunch) adaptable.getAdapter(ILaunch.class);
        NesCVariableNameParser varPars =
            new NesCVariableNameParser(new NesCSeparatorFromCDTLaunch(launch));

        IVariable[] variables = m_varMan.getRegisteredVariables(adaptable);
        if (variables != null) {
          // Save the name of all registered variables
          Vector<String> existingVars = new Vector<String>();
          for (IVariable var : variables) {
            try {
              existingVars.add(var.getName());
            } catch (DebugException ex) {
              TinyOSDebugPlugin.getDefault()
                  .log("Exception while adding variable: " + var.toString(), ex);
            }
          }
          // Compile a list of all potential NescC Variables that are not yet registered
          Vector<IVariableDescriptor> descriptors = new Vector<IVariableDescriptor>();
          for (IVariableDescriptor globDesc : m_varMan.getAvailableVariableDescriptors(adaptable)) {
            if (varPars.isNesCVariable(globDesc.getName())
                && !existingVars.contains(globDesc.getName())) {
              descriptors.add(globDesc);
            }
          }
          // Add all NesC variables
          if (descriptors.size() > 0) {
            descriptors.addAll(Arrays.asList(m_varMan.getRegisteredVariableDescriptors(adaptable)));
            IVariableDescriptor[] array =
                (IVariableDescriptor[])
                    descriptors.toArray(new IVariableDescriptor[descriptors.size()]);
            m_varMan.registerVariables(array, adaptable);
          }
        }
      }
    }
  }
Пример #5
0
 private void populate(Object o) {
   if (o instanceof IStackFrame) {
     IStackFrame f = (IStackFrame) o;
     NesCVariableNameParser varPars =
         new NesCVariableNameParser(
             new NesCSeparatorFromCDTLaunch(f.getDebugTarget().getLaunch()));
     try {
       if (f.hasVariables()) {
         IVariable[] vars = f.getVariables();
         populate(vars, varPars);
       }
     } catch (DebugException e) {
       TinyOSDebugPlugin.getDefault().log("Exception while populating viewer.", e);
     }
   } else {
     clear();
   }
 }
Пример #6
0
 public Image getImage(Object obj) {
   if (obj instanceof TreeNode) {
     TreeNode to = (TreeNode) obj;
     IVariable var = (IVariable) to.getAdapter(IVariable.class);
     if (var != null) {
       try {
         if (var.getValue().hasVariables()) {
           return NesCDebugIcons.get(NesCDebugIcons.ICON_VAR_AGGR);
         } else {
           return NesCDebugIcons.get(NesCDebugIcons.ICON_VAR_SIMPLE);
         }
       } catch (DebugException e) {
         TinyOSDebugPlugin.getDefault().log("Exception while getting image.", e);
       }
     } else if (to.getAdapter(IModuleDescriptor.class) != null) {
       return NesCDebugIcons.get(NesCDebugIcons.ICON_COMPONENT);
     }
   }
   String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
   return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
 }