Changeset 86f852b


Ignore:
Timestamp:
Oct 19, 2017, 11:15:35 AM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
84733c1
Parents:
b93a3de
git-author:
Rob Schluntz <rschlunt@…> (10/13/17 16:44:00)
git-committer:
Rob Schluntz <rschlunt@…> (10/19/17 11:15:35)
Message:

Update ctor-autogen test case with generic types

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/GenType.cc

    rb93a3de r86f852b  
    210210
    211211        std::string GenType::handleGeneric( ReferenceToType * refType ) {
    212                 if ( ! refType->get_parameters().empty() ) {
     212                if ( ! refType->parameters.empty() ) {
    213213                        std::ostringstream os;
    214214                        PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks );
    215215                        os << "(";
    216                         cg.pass.genCommaList( refType->get_parameters().begin(), refType->get_parameters().end() );
     216                        cg.pass.genCommaList( refType->parameters.begin(), refType->parameters.end() );
    217217                        os << ") ";
    218218                        return os.str();
  • src/tests/ctor-autogen.c

    rb93a3de r86f852b  
    3232};
    3333
     34// dtype-static generic type is otype
     35forall(dtype T)
     36struct DtypeStaticStruct {
     37  T * data;
     38  short size;
     39};
     40
     41forall(dtype T)
     42union DtypeStaticUnion {
     43  T * data;
     44  short size;
     45};
     46
     47// dynamic generic type is otype
     48forall(otype T)
     49struct DynamicStruct {
     50        T x;
     51};
     52
     53forall(otype T)
     54union DynamicUnion {
     55        T x;
     56};
     57
     58// struct/union that contains a generic type is
     59struct GenericContainingStruct {
     60        DynamicStruct(int) dsi;
     61        DynamicStruct(double) dsd;
     62        DynamicUnion(int) dui;
     63        DynamicUnion(double) dud;
     64        DtypeStaticStruct(int) dssi;
     65        DtypeStaticStruct(float) dssf;
     66        DtypeStaticUnion(int) dsui;
     67        DtypeStaticUnion(float) dsuf;
     68};
     69
     70union GenericContainingUnion {
     71        DynamicStruct(int) dsi;
     72        DynamicStruct(double) dsd;
     73        DynamicUnion(int) dui;
     74        DynamicUnion(double) dud;
     75        DtypeStaticStruct(int) dssi;
     76        DtypeStaticStruct(float) dssf;
     77        DtypeStaticUnion(int) dsui;
     78        DtypeStaticUnion(float) dsuf;
     79};
     80
     81
     82forall(otype T)
     83T identity(T x) { return x; }
     84
     85// can identity e if only sized or only the assertion, but the combination breaks...
     86// forall(dtype T | sized(T) | { void ?{}(T &); })
     87// void identity(T x) {  }
     88
     89#if ERR1
    3490// managed type - defines a constructor - can't use field constructors
    3591struct Managed {
     
    44100};
    45101
    46 forall(otype T)
    47 T identity(T x) { return x; }
     102Managed x = { 123 }; // error
     103Managed y;           // okay
    48104
    49 // can identity e if only sized or only the assertion, but the combination breaks...
    50 // forall(dtype T | sized(T) | { void ?{}(T &); })
    51 // void identity(T x) {  }
     105InheritManaged z = { y };  // error?
     106#endif
    52107
    53108int main() {
     
    56111        Color e;
    57112
    58         // identity(R);  // Color should be an otype
    59         // identity((Color)e);
     113        // identity(R);  Color constant should be Color which is otype
     114        identity(e);  // Color should be an otype
    60115        identity(u);  // U should be an otype
    61116        identity(s);  // S should be an otype
     
    73128        identity(pu); // should recursively be an otype
    74129
    75 #if ERR1
    76         Managed x = { 123 }; // error
    77         Managed y;           // okay
     130        DynamicStruct(int) dsi;
     131        DynamicStruct(double) dsd;
     132        DynamicUnion(int) dui;
     133        DynamicUnion(double) dud;
     134        DtypeStaticStruct(int) dssi;
     135        DtypeStaticStruct(float) dssf;
     136        DtypeStaticUnion(int) dsui;
     137        DtypeStaticUnion(float) dsuf;
    78138
    79         InheritManaged z = { y };  // error?
    80 #endif
     139        identity(dsi);
     140        identity(dsd);
     141        // identity(dui); // xxx - codegen errors in generated thunk _temp3 (Box-pass-generated assignment return-temporary)
     142        // identity(dud);
     143        identity(dssi);
     144        identity(dssf);
     145        identity(dsui);
     146        identity(dsuf);
    81147
     148        GenericContainingStruct gcs;
     149        GenericContainingUnion gcu;
     150
     151        identity(gcs);
     152        identity(gcu);
    82153}
Note: See TracChangeset for help on using the changeset viewer.