@Test public final void testRecordFieldRecordTwice() throws Exception { final JPRAJavaGeneratorType g = this.getJavaGenerator(); final GlobalContextType gc = GlobalContexts.newContext(new AlwaysEmptyLoader()); final PackageContextType pc = gc.loadPackage( new PackageNameQualified( Lists.immutable.of( PackageNameUnqualified.of("x"), PackageNameUnqualified.of("y"), PackageNameUnqualified.of("z")))); final IdentifierType id = gc.getFreshIdentifier(); final Optional<ImmutableLexicalPositionType<Path>> no_lex = Optional.empty(); final Path path = JPRAJavaGeneratorContract.createTemporaryDir(); final TypeName t_name = new TypeName(no_lex, "Empty"); final TRecordBuilderType teb = TRecord.newBuilder(pc, id, t_name); final TRecord te = teb.build(); final TypeName tr_name = new TypeName(no_lex, "RecordRecordTwice"); final TRecordBuilderType rb = TRecord.newBuilder(pc, id, tr_name); rb.addField(new FieldName(no_lex, "r0"), gc.getFreshIdentifier(), te); rb.addField(new FieldName(no_lex, "r1"), gc.getFreshIdentifier(), te); final TRecord r = rb.build(); JPRAJavaGeneratorContract.compileRecords( path, g, Lists.immutable.of(te, r)); }
private RecordFieldDeclType<IdentifierType, TType> checkTypeDeclRecordFieldPaddingOctets( final RecordFieldDeclPaddingOctets<IdentifierType, Untyped> r, final MutableList<RecordFieldDeclType<IdentifierType, TType>> fields_ordered, final TRecordBuilderType b) throws JPRACompilerCheckerException { final RecordFieldDeclPaddingOctets<IdentifierType, TType> rv = this.checkRecordFieldPaddingOctets(r); final Size<SizeUnitOctetsType> size = JPRAChecker.evaluateSize(rv.getSizeExpression()); if (size.getValue().compareTo(BigInteger.ZERO) <= 0) { throw JPRACompilerCheckerException.paddingSizeInvalid( r.getLexicalInformation(), size.getValue()); } fields_ordered.add(rv); b.addPaddingOctets(r.getLexicalInformation(), size); return rv; }
@Test public final void testRecordPaddingExhaustive() throws Exception { final JPRAJavaGeneratorType g = this.getJavaGenerator(); final GlobalContextType gc = GlobalContexts.newContext(new AlwaysEmptyLoader()); final PackageContextType pc = gc.loadPackage( new PackageNameQualified( Lists.immutable.of( PackageNameUnqualified.of("x"), PackageNameUnqualified.of("y"), PackageNameUnqualified.of("z")))); final IdentifierType id = gc.getFreshIdentifier(); final Optional<ImmutableLexicalPositionType<Path>> no_lex = Optional.empty(); final TypeName t_name = new TypeName(no_lex, "RecordPadding"); final TRecordBuilderType rb = TRecord.newBuilder(pc, id, t_name); rb.addPaddingOctets(no_lex, Size.valueOf(100L)); final TRecord r = rb.build(); JPRAJavaGeneratorContract.compileRecords( JPRAJavaGeneratorContract.createTemporaryDir(), g, Lists.immutable.of(r)); }
orig_named.containsKey(k), "Names must contain %s", k)); final TRecord type = b.build(); Preconditions.checkPreconditionV( type.getFieldsInDeclarationOrder().size() == orig_ordered.size(),
private RecordFieldDeclType<IdentifierType, TType> checkTypeDeclRecordFieldValue( final RecordFieldDeclValue<IdentifierType, Untyped> r, final MutableList<RecordFieldDeclType<IdentifierType, TType>> fields_ordered, final MutableMap<FieldName, RecordFieldDeclValue<IdentifierType, TType>> fields_named, final TRecordBuilderType b) throws JPRACompilerCheckerException { final RecordFieldDeclValue<IdentifierType, TType> rv = this.checkRecordFieldValue(r); final TypeExprType<IdentifierType, TType> rvt = rv.getType(); fields_ordered.add(rv); fields_named.put(rv.getName(), rv); b.addField(rv.getName(), rv.getIdentifier(), rvt.getType()); return rv; }
@Test public final void testRecordEmpty() throws Exception { final JPRAJavaGeneratorType g = this.getJavaGenerator(); final GlobalContextType gc = GlobalContexts.newContext(new AlwaysEmptyLoader()); final PackageContextType pc = gc.loadPackage( new PackageNameQualified( Lists.immutable.of( PackageNameUnqualified.of("x"), PackageNameUnqualified.of("y"), PackageNameUnqualified.of("z")))); final IdentifierType id = gc.getFreshIdentifier(); final Optional<ImmutableLexicalPositionType<Path>> no_lex = Optional.empty(); final TypeName t_name = new TypeName(no_lex, "Empty"); final TRecordBuilderType rb = TRecord.newBuilder(pc, id, t_name); final TRecord r = rb.build(); JPRAJavaGeneratorContract.compileRecords( JPRAJavaGeneratorContract.createTemporaryDir(), g, Lists.immutable.of(r)); }
private RecordFieldDeclType<IdentifierType, TType> checkTypeDeclRecordFieldValue( final RecordFieldDeclValue<IdentifierType, Untyped> r, final MutableList<RecordFieldDeclType<IdentifierType, TType>> fields_ordered, final MutableMap<FieldName, RecordFieldDeclValue<IdentifierType, TType>> fields_named, final TRecordBuilderType b) throws JPRACompilerCheckerException { final RecordFieldDeclValue<IdentifierType, TType> rv = this.checkRecordFieldValue(r); final TypeExprType<IdentifierType, TType> rvt = rv.getType(); fields_ordered.add(rv); fields_named.put(rv.getName(), rv); b.addField(rv.getName(), rv.getIdentifier(), rvt.getType()); return rv; }
@Test public final void testRecordFieldRecord() throws Exception { final JPRAJavaGeneratorType g = this.getJavaGenerator(); final GlobalContextType gc = GlobalContexts.newContext(new AlwaysEmptyLoader()); final PackageContextType pc = gc.loadPackage( new PackageNameQualified( Lists.immutable.of( PackageNameUnqualified.of("x"), PackageNameUnqualified.of("y"), PackageNameUnqualified.of("z")))); final IdentifierType id = gc.getFreshIdentifier(); final Optional<ImmutableLexicalPositionType<Path>> no_lex = Optional.empty(); final Path path = JPRAJavaGeneratorContract.createTemporaryDir(); final TypeName t_name = new TypeName(no_lex, "Empty"); final TRecordBuilderType teb = TRecord.newBuilder(pc, id, t_name); final TRecord te = teb.build(); final TypeName tr_name = new TypeName(no_lex, "RecordRecord"); final TRecordBuilderType rb = TRecord.newBuilder(pc, id, tr_name); rb.addField(new FieldName(no_lex, "r"), gc.getFreshIdentifier(), te); final TRecord r = rb.build(); JPRAJavaGeneratorContract.compileRecords( path, g, Lists.immutable.of(te, r)); }
k -> Assertive.require(orig_named.containsKey(k))); final TRecord type = b.build(); Assertive.require( type.getFieldsInDeclarationOrder().size() == orig_ordered.size());
private RecordFieldDeclType<IdentifierType, TType> checkTypeDeclRecordFieldPaddingOctets( final RecordFieldDeclPaddingOctets<IdentifierType, Untyped> r, final MutableList<RecordFieldDeclType<IdentifierType, TType>> fields_ordered, final TRecordBuilderType b) throws JPRACompilerCheckerException { final RecordFieldDeclPaddingOctets<IdentifierType, TType> rv = this.checkRecordFieldPaddingOctets(r); final Size<SizeUnitOctetsType> size = this.evaluateSize(rv.getSizeExpression()); if (size.getValue().compareTo(BigInteger.ZERO) <= 0) { throw JPRACompilerCheckerException.paddingSizeInvalid( r.getLexicalInformation(), size.getValue()); } fields_ordered.add(rv); b.addPaddingOctets(r.getLexicalInformation(), size); return rv; }
rb.addField( new FieldName(no_lex, "i8"), gc.getFreshIdentifier(), new TIntegerSigned(no_lex, Size.valueOf(8L))); rb.addField( new FieldName(no_lex, "i16"), gc.getFreshIdentifier(), new TIntegerSigned(no_lex, Size.valueOf(16L))); rb.addField( new FieldName(no_lex, "i32"), gc.getFreshIdentifier(), new TIntegerSigned(no_lex, Size.valueOf(32L))); rb.addField( new FieldName(no_lex, "i64"), gc.getFreshIdentifier(), new TIntegerSigned(no_lex, Size.valueOf(64L))); rb.addField( new FieldName(no_lex, "u8"), gc.getFreshIdentifier(), new TIntegerUnsigned(no_lex, Size.valueOf(8L))); rb.addField( new FieldName(no_lex, "u16"), gc.getFreshIdentifier(), new TIntegerUnsigned(no_lex, Size.valueOf(16L))); rb.addField( new FieldName(no_lex, "u32"), gc.getFreshIdentifier(), new TIntegerUnsigned(no_lex, Size.valueOf(32L)));
rb.addField( new FieldName(no_lex, "isn8"), gc.getFreshIdentifier(), new TIntegerSignedNormalized(no_lex, Size.valueOf(8L))); rb.addField( new FieldName(no_lex, "isn16"), gc.getFreshIdentifier(), new TIntegerSignedNormalized(no_lex, Size.valueOf(16L))); rb.addField( new FieldName(no_lex, "isn32"), gc.getFreshIdentifier(), new TIntegerSignedNormalized(no_lex, Size.valueOf(32L))); rb.addField( new FieldName(no_lex, "isn64"), gc.getFreshIdentifier(), new TIntegerSignedNormalized(no_lex, Size.valueOf(64L))); rb.addField( new FieldName(no_lex, "usn8"), gc.getFreshIdentifier(), new TIntegerUnsignedNormalized(no_lex, Size.valueOf(8L))); rb.addField( new FieldName(no_lex, "usn16"), gc.getFreshIdentifier(), new TIntegerUnsignedNormalized(no_lex, Size.valueOf(16L))); rb.addField( new FieldName(no_lex, "usn32"), gc.getFreshIdentifier(), new TIntegerUnsignedNormalized(no_lex, Size.valueOf(32L)));
rb.addField( new FieldName(no_lex, "v2i"), gc.getFreshIdentifier(), new TVector(no_lex, Size.valueOf(2L), t_int)); rb.addField( new FieldName(no_lex, "v3i"), gc.getFreshIdentifier(), new TVector(no_lex, Size.valueOf(3L), t_int)); rb.addField( new FieldName(no_lex, "v4i"), gc.getFreshIdentifier(), new TVector(no_lex, Size.valueOf(4L), t_int)); rb.addField( new FieldName(no_lex, "v2l"), gc.getFreshIdentifier(), new TVector(no_lex, Size.valueOf(2L), t_long)); rb.addField( new FieldName(no_lex, "v3l"), gc.getFreshIdentifier(), new TVector(no_lex, Size.valueOf(3L), t_long)); rb.addField( new FieldName(no_lex, "v4l"), gc.getFreshIdentifier(), new TVector(no_lex, Size.valueOf(4L), t_long)); rb.addField( new FieldName(no_lex, "v2f"), gc.getFreshIdentifier(), new TVector(no_lex, Size.valueOf(2L), t_float)); rb.addField( new FieldName(no_lex, "v3f"), gc.getFreshIdentifier(), new TVector(no_lex, Size.valueOf(3L), t_float)); rb.addField( new FieldName(no_lex, "v4f"), gc.getFreshIdentifier(), new TVector(no_lex, Size.valueOf(4L), t_float));
final TRecordBuilderType rb = TRecord.newBuilder(pc, id, t_name); rb.addField( new FieldName(no_lex, "f16"), gc.getFreshIdentifier(), new TFloat(no_lex, Size.valueOf(16L))); rb.addField( new FieldName(no_lex, "f32"), gc.getFreshIdentifier(), new TFloat(no_lex, Size.valueOf(32L))); rb.addField( new FieldName(no_lex, "f64"), gc.getFreshIdentifier(), new TFloat(no_lex, Size.valueOf(64L))); final TRecord r = rb.build(); JPRAJavaGeneratorContract.compileRecords( JPRAJavaGeneratorContract.createTemporaryDir(), g, Lists.immutable.of(r));
final TRecordBuilderType rb = TRecord.newBuilder(pc, id, t_name); rb.addField( new FieldName(no_lex, "bool"), gc.getFreshIdentifier(), new TBooleanSet( no_lex, Lists.immutable.of( new FieldName(no_lex, "flag_k")), Size.valueOf(2L))); final TRecord r = rb.build(); JPRAJavaGeneratorContract.compileRecords( JPRAJavaGeneratorContract.createTemporaryDir(), g, Lists.immutable.of(r));