private ARecordTypeIR consRecordType(ARecordPatternIR pat) { if(pat != null) { STypeIR patType = pat.getType(); if (patType instanceof ARecordTypeIR) { ARecordTypeIR recType = (ARecordTypeIR) patType; return recType.clone(); } else { ARecordTypeIR type = new ARecordTypeIR(); ATypeNameIR typeName = new ATypeNameIR(); typeName.setName(pat.getTypename()); typeName.setDefiningClass("?"); type.setName(typeName); log.warn("Could not determine defining class for record pattern " + pat); return type; } } else { return new ARecordTypeIR(); } }
public ABlockStmIR consVarFromCastedExp(ARecordDeclIR record, String formalParamName, String varName) throws AnalysisException { // Construct a local var in a statement: RecordType varName = ((RecordType) formalParamName); ARecordTypeIR recordType = new ARecordTypeIR(); recordType.setName(consTypeName(record)); AIdentifierPatternIR idPattern = new AIdentifierPatternIR(); idPattern.setName(varName); ACastUnaryExpIR cast = new ACastUnaryExpIR(); cast.setType(recordType.clone()); AIdentifierVarExpIR varExp = new AIdentifierVarExpIR(); varExp.setType(new AObjectTypeIR()); varExp.setName(formalParamName); varExp.setIsLocal(true); cast.setExp(varExp); AVarDeclIR localVar = info.getDeclAssistant().consLocalVarDecl(recordType, idPattern, cast); ABlockStmIR stm = new ABlockStmIR(); stm.getLocalDefs().add(localVar); return stm; }
private SExpIR consRecFieldExp(AIdentifierVarExpIR patternVar, int i, STypeIR currentType, boolean cast) { ARecordTypeIR recordType = (ARecordTypeIR) patternVar.getType(); AFieldDeclIR recordField = transAssistant.getInfo().getAssistantManager().getDeclAssistant().getFieldDecl(transAssistant.getInfo().getClasses(), recordType, i); String fieldName = recordField.getName(); AFieldExpIR fieldExp = consRecFieldExp(patternVar, currentType, fieldName); if (cast) { ACastUnaryExpIR casted = new ACastUnaryExpIR(); casted.setType(recordType.clone()); casted.setExp(fieldExp.getObject()); fieldExp.setObject(casted); } return fieldExp; }
newExp.setType(returnType.clone()); newExp.setName(typeName.clone()); List<SExpIR> args = newExp.getArgs();