Project

General

Profile

Bug #9606 ยป 0001-Proper-dynamic-cast.patch

Raf Pauwels, 01/11/2022 01:38 PM

View differences:

java/src/eu/webtoolkit/jwt/utils/ObjectUtils.java
32 32

  
33 33
	}
34 34

  
35
    @SuppressWarnings("unchecked")
36
    public static <T> T cast(Object object, Class<T> clazz) {
37
      return clazz.isInstance(object) ? (T)object : null;
38
    }
35 39
}
oink/elsa-stack/elsa/java_print.cc
4230 4230
  TreeWalkDebug treeDebug("E_keywordCast::iprint");
4231 4231

  
4232 4232
  if (key == CK_DYNAMIC){
4233
    // dynamic_cast<T>(o) -> ( o instanceof T ? (T)o : null )
4234
    *env.out << "((";
4233
    // dynamic_cast<T>(o) -> ObjectUtils.cast(o, T.class)
4234
    *env.out << "ObjectUtils.cast(";
4235 4235
    expr->jprint(env);
4236
    *env.out << ") instanceof ";
4236
    *env.out << ", ";
4237 4237
    ctype->jprint(env);
4238
    *env.out << " ? (";
4239
    ctype->jprint(env);
4240
    *env.out << ")(";
4241
    expr->jprint(env);
4242
    *env.out << ") : null)";
4238
    *env.out << ".class)";
4243 4239
  }
4244 4240
  else{
4245 4241
    //map static_cast<Enum>0 -> null
oink/elsa-stack/elsa/mapper_filler.cc
202 202
	mapper.addFunction("", "Utils.stoll", "Long.parseLong", 1);
203 203
	mapper.addFunction("", "Utils.stof", "Float.parseFloat", 1);
204 204
	mapper.addFunction("", "Utils.stod", "Double.parseDouble", 1);
205
	mapper.addFunction("", "Utils.dynamic_unique_ptr_cast", "", 1, "(($templates(cppfunction);)$0;)");
205
	mapper.addFunction("", "Utils.dynamic_unique_ptr_cast", "", 1, "ObjectUtils.cast($0;, $templates(cppfunction);.class)");
206 206
	mapper.addFunction("", "Utils.keyForUniquePtrValue", "CollectionUtils.keyForValue", 2);
207
	mapper.addFunction("", "std.dynamic_pointer_cast", "", 1, "(($templates(cppfunction);)$0;)");
207
	mapper.addFunction("", "std.dynamic_pointer_cast", "", 1, "ObjectUtils.cast($0;, $templates(cppfunction);.class)");
208 208

  
209 209
	mapper.addClass("boost.intrusive.list", "LinkedList");
210 210
	mapper.addFunction("boost.intrusive.list", "begin", "iterator", 0);
211
- 
    (1-1/1)