コード例 #1
0
  public Pair<List<VariablesDeclaration>, List<VariablesDeclaration>> getParentAndOwnDeclarations(
      Struct structJavaClass, Struct nativeStruct) throws IOException {
    Pair<List<VariablesDeclaration>, List<VariablesDeclaration>> ret =
        new Pair<List<VariablesDeclaration>, List<VariablesDeclaration>>(
            new ArrayList<VariablesDeclaration>(), new ArrayList<VariablesDeclaration>());
    if (!nativeStruct.getParents().isEmpty()) {
      for (SimpleTypeRef parentName : nativeStruct.getParents()) {
        Struct parent = result.structsByName.get(parentName.getName());
        if (parent == null) {
          // TODO report error
          continue;
        }
        Struct parentJavaClass = convertStruct(parent, new Signatures(), null, null, true);
        Pair<List<VariablesDeclaration>, List<VariablesDeclaration>> parentDecls =
            getParentAndOwnDeclarations(parentJavaClass, parent);
        ret.getFirst().addAll(parentDecls.getFirst());
        ret.getFirst().addAll(parentDecls.getSecond());
      }
    }
    for (Declaration d : structJavaClass.getDeclarations()) {
      if (!(d instanceof VariablesDeclaration)) continue;
      VariablesDeclaration vd = (VariablesDeclaration) d;
      if (vd.getDeclarators().size() != 1) continue; // should not happen !
      if (!isField(vd)) continue;

      ret.getSecond().add(vd);
    }

    return ret;
  }
コード例 #2
0
  public int countFieldsInStruct(Struct s) throws UnsupportedConversionException {
    int count = 0;
    for (Declaration declaration : s.getDeclarations()) {
      if (declaration instanceof VariablesDeclaration) {
        count += ((VariablesDeclaration) declaration).getDeclarators().size();
      }
    }
    for (SimpleTypeRef parentName : s.getParents()) {
      Struct parent = result.structsByName.get(parentName.getName());
      if (parent == null)
        throw new UnsupportedConversionException(
            s, "Cannot find parent " + parentName + " of struct " + s);

      count += countFieldsInStruct(parent);
    }
    return count;
  }
コード例 #3
0
  public void visitSimpleTypeRef(SimpleTypeRef simpleTypeRef) {
    visitTypeRef(simpleTypeRef);

    visit(simpleTypeRef.getName());
  }