@Override
 public void writeToParcel(Parcel in, int flags) {
   in.writeString(classModel.getTitle());
   in.writeString(classModel.getAuthor());
   in.writeString(classModel.getSummary());
   in.writeParcelable(classModel.getPic(), PARCELABLE_WRITE_RETURN_VALUE);
 }
 private ClassModelParcelable(Parcel in) {
   classModel = new ClassModel();
   classModel.setTitle(in.readString());
   classModel.setAuthor(in.readString());
   classModel.setSummary(in.readString());
   classModel.setPic((Bitmap) in.readParcelable(Bitmap.class.getClassLoader()));
 }
 public void postProcess() {
   for (ClassModel cm : getClasses()) {
     cm.postProcess();
     totalPassed += cm.getTotalPassed();
     totalFailed += cm.getTotalFailed();
     totalSkipped += cm.getTotalSkipped();
   }
 }
示例#4
0
  private ClassModel createExample() {

    // Prepare model
    ClassModel model = new ClassModel("UML Class model");

    // Create sample Class
    UMLClass c1 = new UMLClass("Class 1");
    c1.setPos(100, 100);

    model.addNode(c1);

    return model;
  }
示例#5
0
 /**
  * These three convert functions are here to perform any type conversion that may be required
  * between Java and OpenCL.
  *
  * @param _typeDesc String in the Java JNI notation, [I, etc
  * @return Suitably converted string, "char*", etc
  */
 @Override
 protected String convertType(String _typeDesc, boolean useClassModel) {
   if (_typeDesc.equals("Z") || _typeDesc.equals("boolean")) {
     return (cvtBooleanToChar);
   } else if (_typeDesc.equals("[Z") || _typeDesc.equals("boolean[]")) {
     return (cvtBooleanArrayToCharStar);
   } else if (_typeDesc.equals("B") || _typeDesc.equals("byte")) {
     return (cvtByteToChar);
   } else if (_typeDesc.equals("[B") || _typeDesc.equals("byte[]")) {
     return (cvtByteArrayToCharStar);
   } else if (_typeDesc.equals("C") || _typeDesc.equals("char")) {
     return (cvtCharToShort);
   } else if (_typeDesc.equals("[C") || _typeDesc.equals("char[]")) {
     return (cvtCharArrayToShortStar);
   } else if (_typeDesc.equals("[I") || _typeDesc.equals("int[]")) {
     return (cvtIntArrayToIntStar);
   } else if (_typeDesc.equals("[F") || _typeDesc.equals("float[]")) {
     return (cvtFloatArrayToFloatStar);
   } else if (_typeDesc.equals("[D") || _typeDesc.equals("double[]")) {
     return (cvtDoubleArrayToDoubleStar);
   } else if (_typeDesc.equals("[J") || _typeDesc.equals("long[]")) {
     return (cvtLongArrayToLongStar);
   } else if (_typeDesc.equals("[S") || _typeDesc.equals("short[]")) {
     return (cvtShortArrayToShortStar);
   }
   // if we get this far, we haven't matched anything yet
   if (useClassModel) {
     return (ClassModel.convert(_typeDesc, "", true));
   } else {
     return _typeDesc;
   }
 }
示例#6
0
  public static void main(String[] args) throws Exception {
    String projectPath = "E:/Project/sanhangJob_inner";
    // 创建模型
    ClassModel classModel = new ClassModel("MyMajor");
    classModel.addClassAttr("String", "code");
    classModel.addClassAttr("String", "mainCatagory");
    classModel.addClassAttr("String", "majorCategory");
    classModel.addClassAttr("String", "name");
    classModel.addClassAttr("Company", "company");
    /*todo
     * table connection
     * hibernate config file
     * 格式化
     * 配置文件读取
     * */

    //		for(String modelName : modelNames){
    //
    //		}

    AutoGen autoGenTool = new AutoGen(classModel, projectPath);
    // autoGenTool.alterServiceLocatorFile();
    // autoGenTool.alterSpringHibernateCfgFile();//生成spring-hibernate配置文件
    // autoGenTool.alterSpringDaoCfgFile();//生成spring-dao配置文件
    // autoGenTool.alterSpringServiceCfgFile();//生成spring-service配置文件
  }
  @Override
  public View getView(int pos, View convertView, ViewGroup parent) {
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View classView = inflater.inflate(R.layout.navbar_class, parent, false);

    ClassModel classModel = ClassDataManager.getClassById(classList.get(pos));

    TextView text = (TextView) classView.findViewById(R.id.navbar_classname);
    text.setText(classModel.getName());

    /*LinearLayout layout = (LinearLayout) classView.findViewById(R.id.navbar_layout);

    for(AssignmentModel assignment: AssignmentDataManager.getAssignmentsByIds(classModel.getAssignments())) {
        View aView = inflater.inflate(R.layout.navbar_assignment, parent, false);

        text = (TextView) aView.findViewById(R.id.navbar_assignment_name);
        text.setText(assignment.getName());


        text = (TextView) aView.findViewById(R.id.navbar_assignment_due);
        Log.d("due2?", assignment.getDue());
        text.setText(assignment.getDue());

        layout.addView(aView);
    }*/

    ListView assignments = (ListView) classView.findViewById(R.id.navbar_assignments);
    NavDrawerAssignmentAdapter asAdapter =
        new NavDrawerAssignmentAdapter(context, classList.get(pos));
    // asAdapter.setData(AssignmentDataManager.getAssignmentsByIds(ClassDataManager.getClassById(classList.get(pos)).getAssignments()));
    // asAdapter.notifyDataSetChanged();
    assignments.setAdapter(asAdapter);

    // notifyDataSetChanged();
    // assignments.setEnabled(false);

    return classView;
  }
示例#8
0
  @Override
  void write(Entrypoint _entryPoint) throws CodeGenException {
    List<String> thisStruct = new ArrayList<String>();
    List<String> argLines = new ArrayList<String>();
    List<String> assigns = new ArrayList<String>();

    entryPoint = _entryPoint;

    for (ClassModelField field : _entryPoint.getReferencedClassModelFields()) {
      // Field field = _entryPoint.getClassModel().getField(f.getName());
      StringBuilder thisStructLine = new StringBuilder();
      StringBuilder argLine = new StringBuilder();
      StringBuilder assignLine = new StringBuilder();

      String signature = field.getDescriptor();

      boolean isPointer = false;

      // check the suffix
      String type =
          field.getName().endsWith(Kernel.LOCAL_SUFFIX)
              ? __local
              : (field.getName().endsWith(Kernel.CONSTANT_SUFFIX) ? __constant : __global);
      RuntimeAnnotationsEntry visibleAnnotations =
          field.fieldAttributePool.getRuntimeVisibleAnnotationsEntry();

      if (visibleAnnotations != null) {
        for (AnnotationInfo ai : visibleAnnotations) {
          String typeDescriptor = ai.getTypeDescriptor();
          if (typeDescriptor.equals(LOCAL_ANNOTATION_NAME)) {
            type = __local;
          } else if (typeDescriptor.equals(CONSTANT_ANNOTATION_NAME)) {
            type = __constant;
          }
        }
      }

      if (signature.startsWith("[")) {
        argLine.append(type + " ");
        thisStructLine.append(type + " ");
        isPointer = true;
        signature = signature.substring(1);
      }

      // If it is a converted array of objects, emit the struct param
      String className = null;
      if (signature.startsWith("L")) {
        // Turn Lcom/amd/javalabs/opencl/demo/DummyOOA; into com_amd_javalabs_opencl_demo_DummyOOA
        // for example
        className = (signature.substring(1, signature.length() - 1)).replace("/", "_");
        // if (logger.isLoggable(Level.FINE)) {
        // logger.fine("Examining object parameter: " + signature + " new: " + className);
        // }

        argLine.append(className);
        thisStructLine.append(className);
      } else {
        argLine.append(convertType(ClassModel.typeName(signature.charAt(0)), false));
        thisStructLine.append(convertType(ClassModel.typeName(signature.charAt(0)), false));
      }

      argLine.append(" ");
      thisStructLine.append(" ");

      if (isPointer) {
        argLine.append("*");
        thisStructLine.append("*");
      }
      assignLine.append("this->");
      assignLine.append(field.getName());
      assignLine.append(" = ");
      assignLine.append(field.getName());
      argLine.append(field.getName());
      thisStructLine.append(field.getName());
      assigns.add(assignLine.toString());
      argLines.add(argLine.toString());
      thisStruct.add(thisStructLine.toString());

      // Add int field into "this" struct for supporting java arraylength op
      // named like foo__javaArrayLength
      if (isPointer && _entryPoint.getArrayFieldArrayLengthUsed().contains(field.getName())) {
        StringBuilder lenStructLine = new StringBuilder();
        StringBuilder lenArgLine = new StringBuilder();
        StringBuilder lenAssignLine = new StringBuilder();

        lenStructLine.append("int " + field.getName() + BlockWriter.arrayLengthMangleSuffix);

        lenAssignLine.append("this->");
        lenAssignLine.append(field.getName() + BlockWriter.arrayLengthMangleSuffix);
        lenAssignLine.append(" = ");
        lenAssignLine.append(field.getName() + BlockWriter.arrayLengthMangleSuffix);

        lenArgLine.append("int " + field.getName() + BlockWriter.arrayLengthMangleSuffix);

        assigns.add(lenAssignLine.toString());
        argLines.add(lenArgLine.toString());
        thisStruct.add(lenStructLine.toString());
      }
    }

    if (Config.enableByteWrites || _entryPoint.requiresByteAddressableStorePragma()) {
      // Starting with OpenCL 1.1 (which is as far back as we support)
      // this feature is part of the core, so we no longer need this pragma
      if (false) {
        writePragma("cl_khr_byte_addressable_store", true);
        newLine();
      }
    }

    boolean usesAtomics = false;
    if (Config.enableAtomic32 || _entryPoint.requiresAtomic32Pragma()) {
      usesAtomics = true;
      writePragma("cl_khr_global_int32_base_atomics", true);
      writePragma("cl_khr_global_int32_extended_atomics", true);
      writePragma("cl_khr_local_int32_base_atomics", true);
      writePragma("cl_khr_local_int32_extended_atomics", true);
    }
    if (Config.enableAtomic64 || _entryPoint.requiresAtomic64Pragma()) {
      usesAtomics = true;
      writePragma("cl_khr_int64_base_atomics", true);
      writePragma("cl_khr_int64_extended_atomics", true);
    }
    if (usesAtomics) {
      write("int atomicAdd(__global int *_arr, int _index, int _delta){");
      in();
      {
        newLine();
        write("return atomic_add(&_arr[_index], _delta);");
        out();
        newLine();
      }
      write("}");

      newLine();
    }

    if (Config.enableDoubles || _entryPoint.requiresDoublePragma()) {
      writePragma("cl_khr_fp64", true);
      newLine();
    }

    // Emit structs for oop transformation accessors
    for (ClassModel cm : _entryPoint.getObjectArrayFieldsClasses().values()) {
      ArrayList<FieldEntry> fieldSet = cm.getStructMembers();
      if (fieldSet.size() > 0) {
        String mangledClassName = cm.getClassWeAreModelling().getName().replace(".", "_");
        newLine();
        write("typedef struct " + mangledClassName + "_s{");
        in();
        newLine();

        int totalSize = 0;
        int alignTo = 0;

        Iterator<FieldEntry> it = fieldSet.iterator();
        while (it.hasNext()) {
          FieldEntry field = it.next();
          String fType = field.getNameAndTypeEntry().getDescriptorUTF8Entry().getUTF8();
          int fSize = InstructionSet.TypeSpec.valueOf(fType.equals("Z") ? "B" : fType).getSize();

          if (fSize > alignTo) {
            alignTo = fSize;
          }
          totalSize += fSize;

          String cType =
              convertType(field.getNameAndTypeEntry().getDescriptorUTF8Entry().getUTF8(), true);
          assert cType != null
              : "could not find type for "
                  + field.getNameAndTypeEntry().getDescriptorUTF8Entry().getUTF8();
          writeln(cType + " " + field.getNameAndTypeEntry().getNameUTF8Entry().getUTF8() + ";");
        }

        // compute total size for OpenCL buffer
        int totalStructSize = 0;
        if (totalSize % alignTo == 0) {
          totalStructSize = totalSize;
        } else {
          // Pad up if necessary
          totalStructSize = ((totalSize / alignTo) + 1) * alignTo;
        }
        if (totalStructSize > alignTo) {
          while (totalSize < totalStructSize) {
            // structBuffer.put((byte)-1);
            writeln("char _pad_" + totalSize + ";");
            totalSize++;
          }
        }

        out();
        newLine();
        write("} " + mangledClassName + ";");
        newLine();
      }
    }

    write("typedef struct This_s{");

    in();
    newLine();
    for (String line : thisStruct) {
      write(line);
      writeln(";");
    }
    write("int passid");
    out();
    writeln(";");
    // out();
    // newLine();
    write("}This;");
    newLine();
    write("int get_pass_id(This *this){");
    in();
    {
      newLine();
      write("return this->passid;");
      out();
      newLine();
    }
    write("}");
    newLine();

    for (MethodModel mm : _entryPoint.getCalledMethods()) {
      // write declaration :)

      String returnType = mm.getReturnType();
      // Arrays always map to __global arrays
      if (returnType.startsWith("[")) {
        write(" __global ");
      }
      write(convertType(returnType, true));

      write(mm.getName() + "(");

      if (!mm.getMethod().isStatic()) {
        if ((mm.getMethod().getClassModel() == _entryPoint.getClassModel())
            || mm.getMethod()
                .getClassModel()
                .isSuperClass(_entryPoint.getClassModel().getClassWeAreModelling())) {
          write("This *this");
        } else {
          // Call to an object member or superclass of member
          for (ClassModel c : _entryPoint.getObjectArrayFieldsClasses().values()) {
            if (mm.getMethod().getClassModel() == c) {
              write(
                  "__global "
                      + mm.getMethod()
                          .getClassModel()
                          .getClassWeAreModelling()
                          .getName()
                          .replace(".", "_")
                      + " *this");
              break;
            } else if (mm.getMethod().getClassModel().isSuperClass(c.getClassWeAreModelling())) {
              write(
                  "__global " + c.getClassWeAreModelling().getName().replace(".", "_") + " *this");
              break;
            }
          }
        }
      }

      boolean alreadyHasFirstArg = !mm.getMethod().isStatic();

      LocalVariableTableEntry<LocalVariableInfo> lvte = mm.getLocalVariableTableEntry();
      for (LocalVariableInfo lvi : lvte) {
        if ((lvi.getStart() == 0)
            && ((lvi.getVariableIndex() != 0)
                || mm.getMethod().isStatic())) { // full scope but skip this
          String descriptor = lvi.getVariableDescriptor();
          if (alreadyHasFirstArg) {
            write(", ");
          }

          // Arrays always map to __global arrays
          if (descriptor.startsWith("[")) {
            write(" __global ");
          }

          write(convertType(descriptor, true));
          write(lvi.getVariableName());
          alreadyHasFirstArg = true;
        }
      }
      write(")");
      writeMethodBody(mm);
      newLine();
    }

    write("__kernel void " + _entryPoint.getMethodModel().getSimpleName() + "(");

    in();
    boolean first = true;
    for (String line : argLines) {

      if (first) {
        first = false;
      } else {
        write(", ");
      }

      newLine();
      write(line);
    }

    if (first) {
      first = false;
    } else {
      write(", ");
    }
    newLine();
    write("int passid");
    out();
    newLine();
    write("){");
    in();
    newLine();
    writeln("This thisStruct;");
    writeln("This* this=&thisStruct;");
    for (String line : assigns) {
      write(line);
      writeln(";");
    }
    write("this->passid = passid");
    writeln(";");

    writeMethodBody(_entryPoint.getMethodModel());
    out();
    newLine();
    writeln("}");
    out();
  }