• R/O
  • SSH
  • HTTPS

eircompile: Commit


Commit MetaInfo

Revision72 (tree)
Time2022-01-06 01:41:24
Authorquiret

Log Message

- added COS descriptive declarations unit tests

Change Summary

Incremental Difference

--- testcompiler/src/cos_tests.cpp (revision 71)
+++ testcompiler/src/cos_tests.cpp (revision 72)
@@ -8542,4 +8542,1026 @@
85428542 }
85438543 }
85448544 printf( "ok.\n" );
8545+
8546+ printf( "testing COS descriptive declarations..." );
8547+ {
8548+ // 1)
8549+ {
8550+ COSNode *_root = lexer.StartProduction( "int a;" );
8551+
8552+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8553+
8554+ assert( root != nullptr );
8555+ assert( root->initializer == nullptr );
8556+
8557+ SpecifierString *type = dynamic_cast <SpecifierString*> ( root->type );
8558+
8559+ assert( type != nullptr );
8560+ assert( type->string == "int" );
8561+
8562+ type->Delete();
8563+
8564+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8565+
8566+ assert( name != nullptr );
8567+ assert( name->string == "a" );
8568+
8569+ name->Delete();
8570+ root->Delete();
8571+ }
8572+
8573+ // 2)
8574+ {
8575+ COSNode *_root = lexer.StartProduction( "int *a;" );
8576+
8577+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8578+
8579+ assert( root != nullptr );
8580+ assert( root->initializer == nullptr );
8581+
8582+ PointerTypeSpecifier *type = dynamic_cast <PointerTypeSpecifier*> ( root->type );
8583+
8584+ assert( type != nullptr );
8585+
8586+ SpecifierString *type_spec = dynamic_cast <SpecifierString*> ( type->spec );
8587+
8588+ assert( type_spec != nullptr );
8589+ assert( type_spec->string == "int" );
8590+
8591+ type_spec->Delete();
8592+ type->Delete();
8593+
8594+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8595+
8596+ assert( name != nullptr );
8597+ assert( name->string == "a" );
8598+
8599+ name->Delete();
8600+ root->Delete();
8601+ }
8602+
8603+ // 3)
8604+ {
8605+ COSNode *_root = lexer.StartProduction( "int **b;" );
8606+
8607+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8608+
8609+ assert( root != nullptr );
8610+ assert( root->initializer == nullptr );
8611+
8612+ PointerTypeSpecifier *type = dynamic_cast <PointerTypeSpecifier*> ( root->type );
8613+
8614+ assert( type != nullptr );
8615+
8616+ PointerTypeSpecifier *type_spec = dynamic_cast <PointerTypeSpecifier*> ( type->spec );
8617+
8618+ assert( type_spec != nullptr );
8619+
8620+ SpecifierString *type_spec_spec = dynamic_cast <SpecifierString*> ( type_spec->spec );
8621+
8622+ assert( type_spec_spec != nullptr );
8623+ assert( type_spec_spec->string == "int" );
8624+
8625+ type_spec_spec->Delete();
8626+ type_spec->Delete();
8627+ type->Delete();
8628+
8629+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8630+
8631+ assert( name != nullptr );
8632+ assert( name->string == "b" );
8633+
8634+ name->Delete();
8635+ root->Delete();
8636+ }
8637+
8638+ // 4)
8639+ {
8640+ COSNode *_root = lexer.StartProduction( "bool& a;" );
8641+
8642+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8643+
8644+ assert( root != nullptr );
8645+ assert( root->initializer == nullptr );
8646+
8647+ RefTypeSpecifier *type = dynamic_cast <RefTypeSpecifier*> ( root->type );
8648+
8649+ assert( type != nullptr );
8650+
8651+ SpecifierString *type_spec = dynamic_cast <SpecifierString*> ( type->spec );
8652+
8653+ assert( type_spec != nullptr );
8654+ assert( type_spec->string == "bool" );
8655+
8656+ type_spec->Delete();
8657+ type->Delete();
8658+
8659+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8660+
8661+ assert( name != nullptr );
8662+ assert( name->string == "a" );
8663+
8664+ name->Delete();
8665+ root->Delete();
8666+ }
8667+
8668+ // 5)
8669+ {
8670+ COSNode *_root = lexer.StartProduction( "bool*& c;" );
8671+
8672+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8673+
8674+ assert( root != nullptr );
8675+ assert( root->initializer == nullptr );
8676+
8677+ RefTypeSpecifier *type = dynamic_cast <RefTypeSpecifier*> ( root->type );
8678+
8679+ assert( type != nullptr );
8680+
8681+ PointerTypeSpecifier *type_spec = dynamic_cast <PointerTypeSpecifier*> ( type->spec );
8682+
8683+ assert( type_spec != nullptr );
8684+
8685+ SpecifierString *type_spec_spec = dynamic_cast <SpecifierString*> ( type_spec->spec );
8686+
8687+ assert( type_spec_spec != nullptr );
8688+ assert( type_spec_spec->string == "bool" );
8689+
8690+ type_spec_spec->Delete();
8691+ type_spec->Delete();
8692+ type->Delete();
8693+
8694+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8695+
8696+ assert( name != nullptr );
8697+ assert( name->string == "c" );
8698+
8699+ name->Delete();
8700+ root->Delete();
8701+ }
8702+
8703+ // 6)
8704+ {
8705+ COSNode *_root = lexer.StartProduction( "void func (*proto)(int p1, int p2);" );
8706+
8707+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8708+
8709+ assert( root != nullptr );
8710+ assert( root->initializer == nullptr );
8711+
8712+ PointerTypeSpecifier *type = dynamic_cast <PointerTypeSpecifier*> ( root->type );
8713+
8714+ assert( type != nullptr );
8715+
8716+ FuncsigDefinition *type_spec = dynamic_cast <FuncsigDefinition*> ( type->spec );
8717+
8718+ assert( type_spec != nullptr );
8719+ assert( type_spec->params.GetCount() == 2 );
8720+
8721+ SpecifierString *type_spec_rtype = dynamic_cast <SpecifierString*> ( type_spec->return_type );
8722+
8723+ assert( type_spec_rtype != nullptr );
8724+ assert( type_spec_rtype->string == "void" );
8725+
8726+ type_spec_rtype->Delete();
8727+
8728+ DeclarationStatement *type_spec_p1 = dynamic_cast <DeclarationStatement*> ( type_spec->params[0] );
8729+
8730+ assert( type_spec_p1 != nullptr );
8731+ assert( type_spec_p1->initializer == nullptr );
8732+
8733+ SpecifierString *type_spec_p1_name = dynamic_cast <SpecifierString*> ( type_spec_p1->name );
8734+
8735+ assert( type_spec_p1_name != nullptr );
8736+ assert( type_spec_p1_name->string == "p1" );
8737+
8738+ type_spec_p1_name->Delete();
8739+
8740+ SpecifierString *type_spec_p1_type = dynamic_cast <SpecifierString*> ( type_spec_p1->type );
8741+
8742+ assert( type_spec_p1_type != nullptr );
8743+ assert( type_spec_p1_type->string == "int" );
8744+
8745+ type_spec_p1_type->Delete();
8746+ type_spec_p1->Delete();
8747+
8748+ DeclarationStatement *type_spec_p2 = dynamic_cast <DeclarationStatement*> ( type_spec->params[1] );
8749+
8750+ assert( type_spec_p2 != nullptr );
8751+ assert( type_spec_p2->initializer == nullptr );
8752+
8753+ SpecifierString *type_spec_p2_name = dynamic_cast <SpecifierString*> ( type_spec_p2->name );
8754+
8755+ assert( type_spec_p2_name != nullptr );
8756+ assert( type_spec_p2_name->string == "p2" );
8757+
8758+ type_spec_p2_name->Delete();
8759+
8760+ SpecifierString *type_spec_p2_type = dynamic_cast <SpecifierString*> ( type_spec_p2->type );
8761+
8762+ assert( type_spec_p2_type != nullptr );
8763+ assert( type_spec_p2_type->string == "int" );
8764+
8765+ type_spec_p2_type->Delete();
8766+ type_spec_p2->Delete();
8767+
8768+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8769+
8770+ assert( name != nullptr );
8771+ assert( name->string == "proto" );
8772+
8773+ name->Delete();
8774+ root->Delete();
8775+ }
8776+
8777+ // 7)
8778+ {
8779+ COSNode *_root = lexer.StartProduction( "int func (**pproto)();" );
8780+
8781+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8782+
8783+ assert( root != nullptr );
8784+ assert( root->initializer == nullptr );
8785+
8786+ PointerTypeSpecifier *type = dynamic_cast <PointerTypeSpecifier*> ( root->type );
8787+
8788+ assert( type != nullptr );
8789+
8790+ PointerTypeSpecifier *type_spec = dynamic_cast <PointerTypeSpecifier*> ( type->spec );
8791+
8792+ assert( type_spec != nullptr );
8793+
8794+ FuncsigDefinition *type_spec_spec = dynamic_cast <FuncsigDefinition*> ( type_spec->spec );
8795+
8796+ assert( type_spec_spec != nullptr );
8797+ assert( type_spec_spec->params.GetCount() == 0 );
8798+
8799+ SpecifierString *type_spec_spec_rtype = dynamic_cast <SpecifierString*> ( type_spec_spec->return_type );
8800+
8801+ assert( type_spec_spec_rtype != nullptr );
8802+ assert( type_spec_spec_rtype->string == "int" );
8803+
8804+ type_spec_spec_rtype->Delete();
8805+ type_spec_spec->Delete();
8806+ type_spec->Delete();
8807+ type->Delete();
8808+
8809+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8810+
8811+ assert( name != nullptr );
8812+ assert( name->string == "pproto" );
8813+
8814+ name->Delete();
8815+ root->Delete();
8816+ }
8817+
8818+ // 8)
8819+ {
8820+ COSNode *_root = lexer.StartProduction( "void *unk[];" );
8821+
8822+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8823+
8824+ assert( root != nullptr );
8825+
8826+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8827+
8828+ assert( name != nullptr );
8829+ assert( name->string == "unk" );
8830+
8831+ name->Delete();
8832+
8833+ ArrayTypeSpecifier *type = dynamic_cast <ArrayTypeSpecifier*> ( root->type );
8834+
8835+ assert( type != nullptr );
8836+ assert( type->array_size_op == nullptr );
8837+
8838+ PointerTypeSpecifier *type_spec = dynamic_cast <PointerTypeSpecifier*> ( type->spec );
8839+
8840+ assert( type_spec != nullptr );
8841+
8842+ SpecifierString *type_spec_spec = dynamic_cast <SpecifierString*> ( type_spec->spec );
8843+
8844+ assert( type_spec_spec != nullptr );
8845+ assert( type_spec_spec->string == "void" );
8846+
8847+ type_spec_spec->Delete();
8848+ type_spec->Delete();
8849+ type->Delete();
8850+ root->Delete();
8851+ }
8852+
8853+ // 9)
8854+ {
8855+ COSNode *_root = lexer.StartProduction( "any var;" );
8856+
8857+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8858+
8859+ assert( root != nullptr );
8860+ assert( root->initializer == nullptr );
8861+
8862+ SpecifierString *type = dynamic_cast <SpecifierString*> ( root->type );
8863+
8864+ assert( type != nullptr );
8865+ assert( type->string == "any" );
8866+
8867+ type->Delete();
8868+
8869+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8870+
8871+ assert( name != nullptr );
8872+ assert( name->string == "var" );
8873+
8874+ name->Delete();
8875+ root->Delete();
8876+ }
8877+
8878+ // 10)
8879+ {
8880+ COSNode *_root = lexer.StartProduction( "template variant <int, void*> tvar;" );
8881+
8882+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8883+
8884+ assert( root != nullptr );
8885+ assert( root->initializer == nullptr );
8886+
8887+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8888+
8889+ assert( name != nullptr );
8890+ assert( name->string == "tvar" );
8891+
8892+ name->Delete();
8893+
8894+ TemplateInstantiationOperation *type = dynamic_cast <TemplateInstantiationOperation*> ( root->type );
8895+
8896+ assert( type != nullptr );
8897+ assert( type->tparams.GetCount() == 2 );
8898+
8899+ SpecifierString *type_tname = dynamic_cast <SpecifierString*> ( type->templ );
8900+
8901+ assert( type_tname != nullptr );
8902+ assert( type_tname->string == "variant" );
8903+
8904+ type_tname->Delete();
8905+
8906+ SpecifierString *type_tp1 = dynamic_cast <SpecifierString*> ( type->tparams[0] );
8907+
8908+ assert( type_tp1 != nullptr );
8909+ assert( type_tp1->string == "int" );
8910+
8911+ type_tp1->Delete();
8912+
8913+ PointerTypeSpecifier *type_tp2 = dynamic_cast <PointerTypeSpecifier*> ( type->tparams[1] );
8914+
8915+ assert( type_tp2 != nullptr );
8916+
8917+ SpecifierString *type_tp2_spec = dynamic_cast <SpecifierString*> ( type_tp2->spec );
8918+
8919+ assert( type_tp2_spec != nullptr );
8920+ assert( type_tp2_spec->string == "void" );
8921+
8922+ type_tp2_spec->Delete();
8923+ type_tp2->Delete();
8924+ type->Delete();
8925+ root->Delete();
8926+ }
8927+
8928+ // 11)
8929+ {
8930+ COSNode *_root = lexer.StartProduction( "template variant <bool,int> func (*proto)(bool);" );
8931+
8932+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
8933+
8934+ assert( root != nullptr );
8935+ assert( root->initializer == nullptr );
8936+
8937+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
8938+
8939+ assert( name != nullptr );
8940+ assert( name->string == "proto" );
8941+
8942+ name->Delete();
8943+
8944+ PointerTypeSpecifier *type = dynamic_cast <PointerTypeSpecifier*> ( root->type );
8945+
8946+ assert( type != nullptr );
8947+
8948+ FuncsigDefinition *type_spec = dynamic_cast <FuncsigDefinition*> ( type->spec );
8949+
8950+ assert( type_spec != nullptr );
8951+ assert( type_spec->params.GetCount() == 1 );
8952+
8953+ DeclarationStatement *type_spec_p1 = dynamic_cast <DeclarationStatement*> ( type_spec->params[0] );
8954+
8955+ assert( type_spec_p1 != nullptr );
8956+ assert( type_spec_p1->initializer == nullptr );
8957+ assert( type_spec_p1->name == nullptr );
8958+
8959+ SpecifierString *type_spec_p1_type = dynamic_cast <SpecifierString*> ( type_spec_p1->type );
8960+
8961+ assert( type_spec_p1_type != nullptr );
8962+ assert( type_spec_p1_type->string == "bool" );
8963+
8964+ type_spec_p1_type->Delete();
8965+ type_spec_p1->Delete();
8966+
8967+ TemplateInstantiationOperation *type_spec_rtype = dynamic_cast <TemplateInstantiationOperation*> ( type_spec->return_type );
8968+
8969+ assert( type_spec_rtype != nullptr );
8970+ assert( type_spec_rtype->tparams.GetCount() == 2 );
8971+
8972+ SpecifierString *type_spec_rtype_tname = dynamic_cast <SpecifierString*> ( type_spec_rtype->templ );
8973+
8974+ assert( type_spec_rtype_tname != nullptr );
8975+ assert( type_spec_rtype_tname->string == "variant" );
8976+
8977+ type_spec_rtype_tname->Delete();
8978+
8979+ SpecifierString *type_spec_rtype_tp1 = dynamic_cast <SpecifierString*> ( type_spec_rtype->tparams[0] );
8980+
8981+ assert( type_spec_rtype_tp1 != nullptr );
8982+ assert( type_spec_rtype_tp1->string == "bool" );
8983+
8984+ type_spec_rtype_tp1->Delete();
8985+
8986+ SpecifierString *type_spec_rtype_tp2 = dynamic_cast <SpecifierString*> ( type_spec_rtype->tparams[1] );
8987+
8988+ assert( type_spec_rtype_tp2 != nullptr );
8989+ assert( type_spec_rtype_tp2->string == "int" );
8990+
8991+ type_spec_rtype_tp2->Delete();
8992+ type_spec_rtype->Delete();
8993+ type_spec->Delete();
8994+ type->Delete();
8995+ root->Delete();
8996+ }
8997+
8998+ // 12)
8999+ {
9000+#if 0
9001+ COSNode *_root = lexer.StartProduction( "template (template templ <a>) <b> notimpl;" );
9002+
9003+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
9004+
9005+ assert( root != nullptr );
9006+ assert( root->initializer == nullptr );
9007+
9008+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
9009+
9010+ assert( name != nullptr );
9011+ assert( name->string == "notimpl" );
9012+
9013+ name->Delete();
9014+
9015+ TemplateInstantiationOperation *type = dynamic_cast <TemplateInstantiationOperation*> ( root->type );
9016+
9017+ assert( type != nullptr );
9018+ assert( type->tparams.GetCount() == 1 );
9019+
9020+ SpecifierString *type_tp1 = dynamic_cast <SpecifierString*> ( type->tparams[0] );
9021+
9022+ assert( type_tp1 != nullptr );
9023+ assert( type_tp1->string == "b" );
9024+
9025+ type_tp1->Delete();
9026+
9027+ TemplateInstantiationOperation *type_tname = dynamic_cast <TemplateInstantiationOperation*> ( type->templ );
9028+
9029+ assert( type_tname != nullptr );
9030+ assert( type_tname->tparams.GetCount() == 1 );
9031+
9032+ SpecifierString *type_tname_tp1 = dynamic_cast <SpecifierString*> ( type_tname->tparams[0] );
9033+
9034+ assert( type_tname_tp1 != nullptr );
9035+ assert( type_tname_tp1->string == "a" );
9036+
9037+ type_tname_tp1->Delete();
9038+
9039+ SpecifierString *type_tname_tname = dynamic_cast <SpecifierString*> ( type_tname->templ );
9040+
9041+ assert( type_tname_tname != nullptr );
9042+ assert( type_tname_tname->string == "templ" );
9043+
9044+ type_tname_tname->Delete();
9045+ type_tname->Delete();
9046+ type->Delete();
9047+ root->Delete();
9048+#endif //0
9049+ }
9050+
9051+ // 13)
9052+ {
9053+ COSNode *_root = lexer.StartProduction( "void func (&refproto)();" );
9054+
9055+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
9056+
9057+ assert( root != nullptr );
9058+ assert( root->initializer == nullptr );
9059+
9060+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
9061+
9062+ assert( name != nullptr );
9063+ assert( name->string == "refproto" );
9064+
9065+ name->Delete();
9066+
9067+ RefTypeSpecifier *type = dynamic_cast <RefTypeSpecifier*> ( root->type );
9068+
9069+ assert( type != nullptr );
9070+
9071+ FuncsigDefinition *type_spec = dynamic_cast <FuncsigDefinition*> ( type->spec );
9072+
9073+ assert( type_spec != nullptr );
9074+ assert( type_spec->params.GetCount() == 0 );
9075+
9076+ SpecifierString *type_spec_rtype = dynamic_cast <SpecifierString*> ( type_spec->return_type );
9077+
9078+ assert( type_spec_rtype != nullptr );
9079+ assert( type_spec_rtype->string == "void" );
9080+
9081+ type_spec_rtype->Delete();
9082+ type_spec->Delete();
9083+ type->Delete();
9084+ root->Delete();
9085+ }
9086+
9087+ // 14)
9088+ {
9089+ COSNode *_root = lexer.StartProduction( "int* func (*f)();" );
9090+
9091+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
9092+
9093+ assert( root != nullptr );
9094+ assert( root->initializer == nullptr );
9095+
9096+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
9097+
9098+ assert( name != nullptr );
9099+ assert( name->string == "f" );
9100+
9101+ name->Delete();
9102+
9103+ PointerTypeSpecifier *type = dynamic_cast <PointerTypeSpecifier*> ( root->type );
9104+
9105+ assert( type != nullptr );
9106+
9107+ FuncsigDefinition *type_spec = dynamic_cast <FuncsigDefinition*> ( type->spec );
9108+
9109+ assert( type_spec != nullptr );
9110+ assert( type_spec->params.GetCount() == 0 );
9111+
9112+ PointerTypeSpecifier *type_spec_rtype = dynamic_cast <PointerTypeSpecifier*> ( type_spec->return_type );
9113+
9114+ assert( type_spec_rtype != nullptr );
9115+
9116+ SpecifierString *type_spec_rtype_spec = dynamic_cast <SpecifierString*> ( type_spec_rtype->spec );
9117+
9118+ assert( type_spec_rtype_spec != nullptr );
9119+ assert( type_spec_rtype_spec->string == "int" );
9120+
9121+ type_spec_rtype_spec->Delete();
9122+ type_spec_rtype->Delete();
9123+ type_spec->Delete();
9124+ type->Delete();
9125+ root->Delete();
9126+ }
9127+
9128+ // 15)
9129+ {
9130+ COSNode *_root = lexer.StartProduction( "void proc (*proto)(float);" );
9131+
9132+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
9133+
9134+ assert( root != nullptr );
9135+ assert( root->initializer == nullptr );
9136+
9137+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
9138+
9139+ assert( name != nullptr );
9140+ assert( name->string == "proto" );
9141+
9142+ name->Delete();
9143+
9144+ PointerTypeSpecifier *type = dynamic_cast <PointerTypeSpecifier*> ( root->type );
9145+
9146+ assert( type != nullptr );
9147+
9148+ FuncsigDefinition *type_spec = dynamic_cast <FuncsigDefinition*> ( type->spec );
9149+
9150+ assert( type_spec != nullptr );
9151+ assert( type_spec->params.GetCount() == 1 );
9152+
9153+ SpecifierString *type_spec_rtype = dynamic_cast <SpecifierString*> ( type_spec->return_type );
9154+
9155+ assert( type_spec_rtype != nullptr );
9156+ assert( type_spec_rtype->string == "void" );
9157+
9158+ type_spec_rtype->Delete();
9159+
9160+ DeclarationStatement *type_spec_p1 = dynamic_cast <DeclarationStatement*> ( type_spec->params[0] );
9161+
9162+ assert( type_spec_p1 != nullptr );
9163+ assert( type_spec_p1->initializer == nullptr );
9164+ assert( type_spec_p1->name == nullptr );
9165+
9166+ SpecifierString *type_spec_p1_type = dynamic_cast <SpecifierString*> ( type_spec_p1->type );
9167+
9168+ assert( type_spec_p1_type != nullptr );
9169+ assert( type_spec_p1_type->string == "float" );
9170+
9171+ type_spec_p1_type->Delete();
9172+ type_spec_p1->Delete();
9173+ type_spec->Delete();
9174+ type->Delete();
9175+ root->Delete();
9176+ }
9177+
9178+ // 16)
9179+ {
9180+ COSNode *_root = lexer.StartProduction( "int a, b;" );
9181+
9182+ MultiDeclarationStatement *root = dynamic_cast <MultiDeclarationStatement*> ( _root );
9183+
9184+ assert( root != nullptr );
9185+ assert( root->decls.GetCount() == 2 );
9186+
9187+ DeclarationStatement *first = dynamic_cast <DeclarationStatement*> ( root->decls[0] );
9188+
9189+ assert( first != nullptr );
9190+ assert( first->initializer == nullptr );
9191+
9192+ SpecifierString *first_name = dynamic_cast <SpecifierString*> ( first->name );
9193+
9194+ assert( first_name != nullptr );
9195+ assert( first_name->string == "a" );
9196+
9197+ first_name->Delete();
9198+
9199+ SpecifierString *first_type = dynamic_cast <SpecifierString*> ( first->type );
9200+
9201+ assert( first_type != nullptr );
9202+ assert( first_type->string == "int" );
9203+
9204+ first_type->Delete();
9205+ first->Delete();
9206+
9207+ DeclarationStatement *second = dynamic_cast <DeclarationStatement*> ( root->decls[1] );
9208+
9209+ assert( second != nullptr );
9210+ assert( second->initializer == nullptr );
9211+
9212+ SpecifierString *second_name = dynamic_cast <SpecifierString*> ( second->name );
9213+
9214+ assert( second_name != nullptr );
9215+ assert( second_name->string == "b" );
9216+
9217+ second_name->Delete();
9218+
9219+ assert( second->type == first_type );
9220+
9221+ second->Delete();
9222+ root->Delete();
9223+ }
9224+
9225+ // 17)
9226+ {
9227+ COSNode *_root = lexer.StartProduction( "void func (*p)(int), *unk;" );
9228+
9229+ MultiDeclarationStatement *root = dynamic_cast <MultiDeclarationStatement*> ( _root );
9230+
9231+ assert( root != nullptr );
9232+ assert( root->decls.GetCount() == 2 );
9233+
9234+ DeclarationStatement *first = dynamic_cast <DeclarationStatement*> ( root->decls[0] );
9235+
9236+ assert( first != nullptr );
9237+ assert( first->initializer == nullptr );
9238+
9239+ SpecifierString *first_name = dynamic_cast <SpecifierString*> ( first->name );
9240+
9241+ assert( first_name != nullptr );
9242+ assert( first_name->string == "p" );
9243+
9244+ first_name->Delete();
9245+
9246+ PointerTypeSpecifier *first_type = dynamic_cast <PointerTypeSpecifier*> ( first->type );
9247+
9248+ assert( first_type != nullptr );
9249+
9250+ FuncsigDefinition *first_type_spec = dynamic_cast <FuncsigDefinition*> ( first_type->spec );
9251+
9252+ assert( first_type_spec != nullptr );
9253+ assert( first_type_spec->params.GetCount() == 1 );
9254+
9255+ DeclarationStatement *first_type_spec_p1 = dynamic_cast <DeclarationStatement*> ( first_type_spec->params[0] );
9256+
9257+ assert( first_type_spec_p1 != nullptr );
9258+ assert( first_type_spec_p1->initializer == nullptr );
9259+ assert( first_type_spec_p1->name == nullptr );
9260+
9261+ SpecifierString *first_type_spec_p1_type = dynamic_cast <SpecifierString*> ( first_type_spec_p1->type );
9262+
9263+ assert( first_type_spec_p1_type != nullptr );
9264+ assert( first_type_spec_p1_type->string == "int" );
9265+
9266+ first_type_spec_p1_type->Delete();
9267+ first_type_spec_p1->Delete();
9268+
9269+ SpecifierString *first_type_spec_rtype = dynamic_cast <SpecifierString*> ( first_type_spec->return_type );
9270+
9271+ assert( first_type_spec_rtype != nullptr );
9272+ assert( first_type_spec_rtype->string == "void" );
9273+
9274+ first_type_spec_rtype->Delete();
9275+ first_type_spec->Delete();
9276+ first_type->Delete();
9277+ first->Delete();
9278+
9279+ DeclarationStatement *second = dynamic_cast <DeclarationStatement*> ( root->decls[1] );
9280+
9281+ assert( second != nullptr );
9282+ assert( second->initializer == nullptr );
9283+
9284+ SpecifierString *second_name = dynamic_cast <SpecifierString*> ( second->name );
9285+
9286+ assert( second_name != nullptr );
9287+ assert( second_name->string == "unk" );
9288+
9289+ second_name->Delete();
9290+
9291+ PointerTypeSpecifier *second_type = dynamic_cast <PointerTypeSpecifier*> ( second->type );
9292+
9293+ assert( second_type != nullptr );
9294+ assert( second_type->spec == first_type_spec_rtype );
9295+
9296+ second_type->Delete();
9297+ second->Delete();
9298+ root->Delete();
9299+ }
9300+
9301+ // 18)
9302+ {
9303+ COSNode *_root = lexer.StartProduction( "bool func (*p1)(), func (*p2)();" );
9304+
9305+ MultiDeclarationStatement *root = dynamic_cast <MultiDeclarationStatement*> ( _root );
9306+
9307+ assert( root != nullptr );
9308+ assert( root->decls.GetCount() == 2 );
9309+
9310+ DeclarationStatement *first = dynamic_cast <DeclarationStatement*> ( root->decls[0] );
9311+
9312+ assert( first != nullptr );
9313+ assert( first->initializer == nullptr );
9314+
9315+ SpecifierString *first_name = dynamic_cast <SpecifierString*> ( first->name );
9316+
9317+ assert( first_name != nullptr );
9318+ assert( first_name->string == "p1" );
9319+
9320+ first_name->Delete();
9321+
9322+ PointerTypeSpecifier *first_type = dynamic_cast <PointerTypeSpecifier*> ( first->type );
9323+
9324+ assert( first_type != nullptr );
9325+
9326+ FuncsigDefinition *first_type_spec = dynamic_cast <FuncsigDefinition*> ( first_type->spec );
9327+
9328+ assert( first_type_spec != nullptr );
9329+ assert( first_type_spec->params.GetCount() == 0 );
9330+
9331+ SpecifierString *first_type_spec_rtype = dynamic_cast <SpecifierString*> ( first_type_spec->return_type );
9332+
9333+ assert( first_type_spec_rtype != nullptr );
9334+ assert( first_type_spec_rtype->string == "bool" );
9335+
9336+ first_type_spec_rtype->Delete();
9337+ first_type_spec->Delete();
9338+ first_type->Delete();
9339+ first->Delete();
9340+
9341+ DeclarationStatement *second = dynamic_cast <DeclarationStatement*> ( root->decls[1] );
9342+
9343+ assert( second != nullptr );
9344+ assert( second->initializer == nullptr );
9345+
9346+ SpecifierString *second_name = dynamic_cast <SpecifierString*> ( second->name );
9347+
9348+ assert( second_name != nullptr );
9349+ assert( second_name->string == "p2" );
9350+
9351+ second_name->Delete();
9352+
9353+ PointerTypeSpecifier *second_type = dynamic_cast <PointerTypeSpecifier*> ( second->type );
9354+
9355+ assert( second_type != nullptr );
9356+
9357+ FuncsigDefinition *second_type_spec = dynamic_cast <FuncsigDefinition*> ( second_type->spec );
9358+
9359+ assert( second_type_spec != nullptr );
9360+ assert( second_type_spec->params.GetCount() == 0 );
9361+ assert( second_type_spec->return_type == first_type_spec_rtype );
9362+
9363+ second_type_spec->Delete();
9364+ second_type->Delete();
9365+ second->Delete();
9366+ root->Delete();
9367+ }
9368+
9369+ // 19)
9370+ {
9371+ COSNode *_root = lexer.StartProduction( "int *arr[2];" );
9372+
9373+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
9374+
9375+ assert( root != nullptr );
9376+ assert( root->initializer == nullptr );
9377+
9378+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
9379+
9380+ assert( name != nullptr );
9381+ assert( name->string == "arr" );
9382+
9383+ name->Delete();
9384+
9385+ ArrayTypeSpecifier *type = dynamic_cast <ArrayTypeSpecifier*> ( root->type );
9386+
9387+ assert( type != nullptr );
9388+
9389+ NumberString *type_idx = dynamic_cast <NumberString*> ( type->array_size_op );
9390+
9391+ assert( type_idx != nullptr );
9392+ assert( type_idx->numeric_string == "2" );
9393+
9394+ type_idx->Delete();
9395+
9396+ PointerTypeSpecifier *type_spec = dynamic_cast <PointerTypeSpecifier*> ( type->spec );
9397+
9398+ assert( type_spec != nullptr );
9399+
9400+ SpecifierString *type_spec_spec = dynamic_cast <SpecifierString*> ( type_spec->spec );
9401+
9402+ assert( type_spec_spec != nullptr );
9403+ assert( type_spec_spec->string == "int" );
9404+
9405+ type_spec_spec->Delete();
9406+ type_spec->Delete();
9407+ type->Delete();
9408+ root->Delete();
9409+ }
9410+
9411+ // 20)
9412+ {
9413+ COSNode *_root = lexer.StartProduction( "int func (*func (*getprotop)(int))(bool);" );
9414+
9415+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
9416+
9417+ assert( root != nullptr );
9418+ assert( root->initializer == nullptr );
9419+
9420+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->name );
9421+
9422+ assert( name != nullptr );
9423+ assert( name->string == "getprotop" );
9424+
9425+ name->Delete();
9426+
9427+ PointerTypeSpecifier *type = dynamic_cast <PointerTypeSpecifier*> ( root->type );
9428+
9429+ assert( type != nullptr );
9430+
9431+ FuncsigDefinition *type_spec = dynamic_cast <FuncsigDefinition*> ( type->spec );
9432+
9433+ assert( type_spec != nullptr );
9434+ assert( type_spec->params.GetCount() == 1 );
9435+
9436+ DeclarationStatement *type_spec_p1 = dynamic_cast <DeclarationStatement*> ( type_spec->params[0] );
9437+
9438+ assert( type_spec_p1 != nullptr );
9439+ assert( type_spec_p1->initializer == nullptr );
9440+ assert( type_spec_p1->name == nullptr );
9441+
9442+ SpecifierString *type_spec_p1_type = dynamic_cast <SpecifierString*> ( type_spec_p1->type );
9443+
9444+ assert( type_spec_p1_type != nullptr );
9445+ assert( type_spec_p1_type->string == "int" );
9446+
9447+ type_spec_p1_type->Delete();
9448+
9449+ PointerTypeSpecifier *type_spec_rtype = dynamic_cast <PointerTypeSpecifier*> ( type_spec->return_type );
9450+
9451+ assert( type_spec_rtype != nullptr );
9452+
9453+ FuncsigDefinition *type_spec_rtype_spec = dynamic_cast <FuncsigDefinition*> ( type_spec_rtype->spec );
9454+
9455+ assert( type_spec_rtype_spec != nullptr );
9456+ assert( type_spec_rtype_spec->params.GetCount() == 1 );
9457+
9458+ DeclarationStatement *type_spec_rtype_spec_p1 = dynamic_cast <DeclarationStatement*> ( type_spec_rtype_spec->params[0] );
9459+
9460+ assert( type_spec_rtype_spec_p1 != nullptr );
9461+ assert( type_spec_rtype_spec_p1->initializer == nullptr );
9462+ assert( type_spec_rtype_spec_p1->name == nullptr );
9463+
9464+ SpecifierString *type_spec_rtype_spec_p1_type = dynamic_cast <SpecifierString*> ( type_spec_rtype_spec_p1->type );
9465+
9466+ assert( type_spec_rtype_spec_p1_type != nullptr );
9467+ assert( type_spec_rtype_spec_p1_type->string == "bool" );
9468+
9469+ type_spec_rtype_spec_p1_type->Delete();
9470+ type_spec_rtype_spec_p1->Delete();
9471+
9472+ SpecifierString *type_spec_rtype_spec_rtype = dynamic_cast <SpecifierString*> ( type_spec_rtype_spec->return_type );
9473+
9474+ assert( type_spec_rtype_spec_rtype != nullptr );
9475+ assert( type_spec_rtype_spec_rtype->string == "int" );
9476+
9477+ type_spec_rtype_spec_rtype->Delete();
9478+ type_spec_rtype_spec->Delete();
9479+ type_spec_rtype->Delete();
9480+ type_spec->Delete();
9481+ type->Delete();
9482+ root->Delete();
9483+ }
9484+
9485+ // 21)
9486+ {
9487+ COSNode *_root = lexer.StartProduction( "float myvar, func (*func(*getp)())(float);" );
9488+
9489+ MultiDeclarationStatement *root = dynamic_cast <MultiDeclarationStatement*> ( _root );
9490+
9491+ assert( root != nullptr );
9492+ assert( root->decls.GetCount() == 2 );
9493+
9494+ DeclarationStatement *first = dynamic_cast <DeclarationStatement*> ( root->decls[0] );
9495+
9496+ assert( first != nullptr );
9497+ assert( first->initializer == nullptr );
9498+
9499+ SpecifierString *first_type = dynamic_cast <SpecifierString*> ( first->type );
9500+
9501+ assert( first_type != nullptr );
9502+ assert( first_type->string == "float" );
9503+
9504+ first_type->Delete();
9505+
9506+ SpecifierString *first_name = dynamic_cast <SpecifierString*> ( first->name );
9507+
9508+ assert( first_name != nullptr );
9509+ assert( first_name->string == "myvar" );
9510+
9511+ first_name->Delete();
9512+ first->Delete();
9513+
9514+ DeclarationStatement *second = dynamic_cast <DeclarationStatement*> ( root->decls[1] );
9515+
9516+ assert( second != nullptr );
9517+ assert( second->initializer == nullptr );
9518+
9519+ SpecifierString *second_name = dynamic_cast <SpecifierString*> ( second->name );
9520+
9521+ assert( second_name != nullptr );
9522+ assert( second_name->string == "getp" );
9523+
9524+ second_name->Delete();
9525+
9526+ PointerTypeSpecifier *second_type = dynamic_cast <PointerTypeSpecifier*> ( second->type );
9527+
9528+ assert( second_type != nullptr );
9529+
9530+ FuncsigDefinition *second_type_spec = dynamic_cast <FuncsigDefinition*> ( second_type->spec );
9531+
9532+ assert( second_type_spec != nullptr );
9533+ assert( second_type_spec->params.GetCount() == 0 );
9534+
9535+ PointerTypeSpecifier *second_type_spec_rtype = dynamic_cast <PointerTypeSpecifier*> ( second_type_spec->return_type );
9536+
9537+ assert( second_type_spec_rtype != nullptr );
9538+
9539+ FuncsigDefinition *second_type_spec_rtype_spec = dynamic_cast <FuncsigDefinition*> ( second_type_spec_rtype->spec );
9540+
9541+ assert( second_type_spec_rtype_spec != nullptr );
9542+ assert( second_type_spec_rtype_spec->params.GetCount() == 1 );
9543+ assert( second_type_spec_rtype_spec->return_type == first_type );
9544+
9545+ DeclarationStatement *second_type_spec_rtype_spec_p1 = dynamic_cast <DeclarationStatement*> ( second_type_spec_rtype_spec->params[0] );
9546+
9547+ assert( second_type_spec_rtype_spec_p1 != nullptr );
9548+ assert( second_type_spec_rtype_spec_p1->initializer == nullptr );
9549+ assert( second_type_spec_rtype_spec_p1->name == nullptr );
9550+
9551+ SpecifierString *second_type_spec_rtype_spec_p1_type = dynamic_cast <SpecifierString*> ( second_type_spec_rtype_spec_p1->type );
9552+
9553+ assert( second_type_spec_rtype_spec_p1_type != nullptr );
9554+ assert( second_type_spec_rtype_spec_p1_type->string == "float" );
9555+
9556+ second_type_spec_rtype_spec_p1_type->Delete();
9557+ second_type_spec_rtype_spec_p1->Delete();
9558+ second_type_spec_rtype_spec->Delete();
9559+ second_type_spec_rtype->Delete();
9560+ second_type_spec->Delete();
9561+ second_type->Delete();
9562+ second->Delete();
9563+ root->Delete();
9564+ }
9565+ }
9566+ printf( "ok.\n" );
85459567 }
\ No newline at end of file
Show on old repository browser