Ejemplo n.º 1
0
  public static void setup() {
    typeDeclarationList_ = new ArrayList<TypeDeclaration>();
    final StaticScope globalScope = StaticScope.globalScope();
    final Type integerType = StaticScope.globalScope().lookupTypeDeclaration("int");
    assert null != integerType;
    final Type voidType = StaticScope.globalScope().lookupTypeDeclaration("void");
    assert null != voidType;
    final Type booleanType = StaticScope.globalScope().lookupTypeDeclaration("boolean");
    assert null != booleanType;

    if (null == globalScope.lookupTypeDeclaration("Map")) {
      final StaticScope newScope = new StaticScope(globalScope);
      final ClassDeclaration objectBaseClass = globalScope.lookupClassDeclaration("Object");
      assert null != objectBaseClass;
      final TemplateDeclaration templateDecl =
          new TemplateDeclaration("Map", newScope, objectBaseClass, 0);
      newScope.setDeclaration(templateDecl);
      final Type K = new TemplateParameterType("K", null);
      final Type V = new TemplateParameterType("V", null);
      final IdentifierExpression keyTypeParamID = new IdentifierExpression("K", K, newScope, 0);
      final IdentifierExpression valueTypeParamID = new IdentifierExpression("V", V, newScope, 0);
      templateDecl.addTypeParameter(keyTypeParamID, 2);
      templateDecl.addTypeParameter(valueTypeParamID, 2);
      mapType_ = new TemplateType("Map", newScope, null);
      templateDecl.setType(mapType_);
      typeDeclarationList_.add(templateDecl);

      final Type intType = globalScope.lookupTypeDeclaration("int");

      declareMapMethod("Map", mapType_, null, null);

      declareMapMethod("put", voidType, asList("value", "key"), asList(V, K));

      declareMapMethod("get", V, asList("key"), asList(K));

      declareMapMethod("containsKey", booleanType, asList("key"), asList(K));

      declareMapMethod("containsValue", booleanType, asList("value"), asList(V));

      declareMapMethod("remove", V, asList("key"), asList(K));

      declareMapMethod("size", intType, null, null);

      // Declare the type
      globalScope.declareType(mapType_);
      globalScope.declareTemplate(templateDecl);
    }
  }
Ejemplo n.º 2
0
  public static void setup() {
    typeDeclarationList_ = new ArrayList<TypeDeclaration>();
    final StaticScope globalScope = StaticScope.globalScope();
    final Type integerType = StaticScope.globalScope().lookupTypeDeclaration("int");
    assert null != integerType;
    final Type voidType = StaticScope.globalScope().lookupTypeDeclaration("void");
    assert null != voidType;
    final Type booleanType = StaticScope.globalScope().lookupTypeDeclaration("boolean");
    assert null != booleanType;

    if (null == globalScope.lookupTypeDeclaration("Set")) {
      final StaticScope newScope = new StaticScope(globalScope);
      final TemplateDeclaration templateDecl =
          new TemplateDeclaration("Set", newScope, /*Base Class*/ null, 0);
      newScope.setDeclaration(templateDecl);
      final Type T = new TemplateParameterType("T", null);
      final IdentifierExpression typeParamId = new IdentifierExpression("T", T, newScope, 0);
      templateDecl.addTypeParameter(typeParamId, 1);
      listType_ = new TemplateType("Set", newScope, null);
      templateDecl.setType(listType_);
      typeDeclarationList_.add(templateDecl);

      final Type intType = globalScope.lookupTypeDeclaration("int");

      declareSetMethod("Set", listType_, null, null, false);

      declareSetMethod("add", voidType, "element", T, false);

      declareSetMethod("remove", booleanType, "element", T, false);

      declareSetMethod("contains", booleanType, "element", T, true);

      declareSetMethod("size", intType, null, null, true);

      declareSetMethod("isEmpty", booleanType, null, null, true);

      // Declare the type
      globalScope.declareType(listType_);
      globalScope.declareTemplate(templateDecl);
    }
  }