コード例 #1
0
 @Override
 public void visitTypeDef(TypeDef typeDef) {
   super.visitTypeDef(typeDef);
   for (Declarator vs : typeDef.getDeclarators())
     typeDefs.put(vs.resolveName(), new Pair<TypeDef, Declarator>(typeDef, vs));
 }
コード例 #2
0
  @Override
  public void visitEnum(Enum e) {
    super.visitEnum(e);
    if (e.getTag() == null) {
      // Hack to infer the enum name from the next typedef NSUInteger
      // NSSomethingThatLooksLikeTheEnumsIdentifiers
      Element nextDeclaration = e.getNextSibling();
      if (nextDeclaration != null && (nextDeclaration instanceof TypeDef)) {
        TypeDef typeDef = (TypeDef) nextDeclaration;
        TypeRef type = typeDef.getValueType();
        if (type instanceof TypeRef.SimpleTypeRef) {
          String simpleTypeStr = ((TypeRef.SimpleTypeRef) type).getName().toString();
          if (simpleTypeStr.equals("NSUInteger")
              || simpleTypeStr.equals("NSInteger")
              || simpleTypeStr.equals("CFIndex")) {
            Declarator bestPlainStorage = null;
            for (Declarator st : typeDef.getDeclarators()) {
              if (st instanceof DirectDeclarator) {
                String name = st.resolveName();
                boolean niceName = StringUtils.trimUnderscores(name).equals(name);
                ;
                if (bestPlainStorage == null || niceName) {
                  bestPlainStorage = st;
                  if (niceName) break;
                }
              }
            }
            if (bestPlainStorage != null) {
              String name = bestPlainStorage.resolveName();
              System.err.println("Automatic struct name matching : " + name);
              e.setTag(ident(name));
            }
          }
        }
      }
    }

    Identifier name = e.getTag();
    String lib = getLibrary(e);
    if (name == null) getList(enumsByLibrary, lib).add(e);
    else {
      Enum oldEnum = enumsByName.get(name);

      if (oldEnum == null
          || oldEnum.isForwardDeclaration()
          || (!(oldEnum.getParentElement() instanceof TypeDef)
              && oldEnum.getParentElement() instanceof TypeDef)) {
        enumsByName.put(name, e);

        // if (e.getTag() != null) {
        //	enumsByName.put(e.getTag(), e);
        // }
        getList(enumsByLibrary, lib).add(e);

        Identifier identifier = getTaggedTypeIdentifierInJava(e);
        if (identifier != null) {
          enumsFullNames.add(identifier);
        }
      }
    }
  }