@Override public SStmCG caseAIfStm(AIfStm node, IRInfo question) throws AnalysisException { SExpCG ifExp = node.getIfExp().apply(question.getExpVisitor(), question); SStmCG thenStm = node.getThenStm().apply(question.getStmVisitor(), question); AIfStmCG ifStm = new AIfStmCG(); ifStm.setIfExp(ifExp); ifStm.setThenStm(thenStm); LinkedList<AElseIfStm> elseIfs = node.getElseIf(); for (AElseIfStm stm : elseIfs) { ifExp = stm.getElseIf().apply(question.getExpVisitor(), question); thenStm = stm.getThenStm().apply(question.getStmVisitor(), question); AElseIfStmCG elseIfStm = new AElseIfStmCG(); elseIfStm.setElseIf(ifExp); elseIfStm.setThenStm(thenStm); ifStm.getElseIf().add(elseIfStm); } if (node.getElseStm() != null) { SStmCG elseStm = node.getElseStm().apply(question.getStmVisitor(), question); ifStm.setElseStm(elseStm); } return ifStm; }
private AMethodDeclCG consGetInstanceMethod(String name) { AClassTypeCG quoteClassType = new AClassTypeCG(); quoteClassType.setName(name); AIdentifierVarExpCG instanceVar = transAssistant.getInfo().getExpAssistant().consIdVar(INSTANCE_FIELD, quoteClassType); AEqualsBinaryExpCG nullCompare = new AEqualsBinaryExpCG(); nullCompare.setType(new ABoolBasicTypeCG()); nullCompare.setLeft(instanceVar); nullCompare.setRight(info.getExpAssistant().consNullExp()); AIdentifierVarExpCG instanceId = transAssistant .getInfo() .getExpAssistant() .consIdVar(INSTANCE_FIELD, quoteClassType.clone()); ATypeNameCG typeName = new ATypeNameCG(); typeName.setDefiningClass(null); typeName.setName(name); ANewExpCG newQuote = new ANewExpCG(); newQuote.setName(typeName); newQuote.setType(quoteClassType); AAssignToExpStmCG assignInstance = new AAssignToExpStmCG(); assignInstance.setTarget(instanceId); assignInstance.setExp(newQuote); AIfStmCG ensureInstance = new AIfStmCG(); ensureInstance.setIfExp(nullCompare); ensureInstance.setThenStm(assignInstance); AReturnStmCG returnInstance = new AReturnStmCG(); returnInstance.setExp(instanceVar.clone()); ABlockStmCG body = new ABlockStmCG(); body.getStatements().add(ensureInstance); body.getStatements().add(returnInstance); AMethodTypeCG methodType = new AMethodTypeCG(); methodType.setResult(quoteClassType.clone()); AMethodDeclCG getInstanceMethod = new AMethodDeclCG(); getInstanceMethod.setImplicit(false); getInstanceMethod.setAbstract(false); getInstanceMethod.setAccess(IJavaConstants.PUBLIC); getInstanceMethod.setIsConstructor(false); getInstanceMethod.setName(GET_INSTANCE_METHOD); getInstanceMethod.setStatic(true); getInstanceMethod.setMethodType(methodType); getInstanceMethod.setBody(body); return getInstanceMethod; }
private AMethodDeclCG consQuoteCtor(String name) { AExternalTypeCG fieldType = new AExternalTypeCG(); fieldType.setName(IJavaConstants.INT); AIdentifierVarExpCG hashcodeVar = transAssistant.getInfo().getExpAssistant().consIdVar(HASHCODE_FIELD, fieldType); AEqualsBinaryExpCG hashcodeCompare = new AEqualsBinaryExpCG(); hashcodeCompare.setType(new ABoolBasicTypeCG()); hashcodeCompare.setLeft(hashcodeVar); hashcodeCompare.setRight(consZero()); AIdentifierVarExpCG hashCodeId = transAssistant.getInfo().getExpAssistant().consIdVar(HASHCODE_FIELD, consFieldType()); AMethodTypeCG hashCodeMethodType = new AMethodTypeCG(); hashCodeMethodType.setResult(consFieldType()); ASuperVarExpCG superVar = new ASuperVarExpCG(); superVar.setName(HASH_CODE_METHOD); superVar.setType(hashCodeMethodType); superVar.setIsLambda(false); superVar.setIsLocal(false); AApplyExpCG superCall = new AApplyExpCG(); superCall.setType(consFieldType()); superCall.setRoot(superVar); AAssignToExpStmCG assignHashcode = new AAssignToExpStmCG(); assignHashcode.setTarget(hashCodeId); assignHashcode.setExp(superCall); AIfStmCG hashcodeCheck = new AIfStmCG(); hashcodeCheck.setIfExp(hashcodeCompare); hashcodeCheck.setThenStm(assignHashcode); ABlockStmCG body = new ABlockStmCG(); body.getStatements().add(hashcodeCheck); AClassTypeCG quoteClassType = new AClassTypeCG(); quoteClassType.setName(name); AMethodTypeCG constructorType = new AMethodTypeCG(); constructorType.setResult(quoteClassType); AMethodDeclCG ctor = consDefaultCtorSignature(name); ctor.setMethodType(constructorType); ctor.setBody(body); return ctor; }