| 301 | } |
| 302 | |
| 303 | void ast_structureDeclaration ( yyscan_t scanner, AnnotationList * annL, const LineInfo & loc, Structure * ps, |
| 304 | const LineInfo & atPs, vector<VariableDeclaration*> * list ) { |
| 305 | if ( ps ) { |
| 306 | auto pStruct = ps; |
| 307 | pStruct->at = atPs; |
| 308 | if ( pStruct->parent && pStruct->parent->isClass != pStruct->isClass ) { |
| 309 | if ( pStruct->isClass ) { |
| 310 | das_yyerror(scanner,"class can only derive from a class", pStruct->at, |
| 311 | CompilationError::invalid_class); |
| 312 | } else { |
| 313 | das_yyerror(scanner,"structure can only derive from a structure", pStruct->at, |
| 314 | CompilationError::invalid_structure); |
| 315 | } |
| 316 | delete annL; |
| 317 | deleteVariableDeclarationList(list); |
| 318 | return; |
| 319 | } |
| 320 | if ( pStruct->isClass ) { |
| 321 | makeClassRtti(pStruct); |
| 322 | auto virtfin = makeClassFinalize(pStruct); |
| 323 | if ( !yyextra->g_Program->addFunction(virtfin) ) { |
| 324 | das_yyerror(scanner,"built-in finalizer is already defined " + virtfin->getMangledName(), |
| 325 | virtfin->at, CompilationError::internal_function); |
| 326 | } |
| 327 | } |
| 328 | const bool hasParent = (pStruct->parent != nullptr); |
| 329 | for ( auto & ffd : pStruct->fields ) { |
| 330 | ffd.implemented = false; |
| 331 | ffd.inherited = hasParent; |
| 332 | } |
| 333 | for ( auto pDecl : *list ) { |
| 334 | for ( const auto & name_at : *pDecl->pNameList ) { |
| 335 | /* |
| 336 | if ( !pStruct->isClass && pDecl->isPrivate ) { |
| 337 | das_yyerror(scanner,"only class member can be private "+name_at.name,name_at.at, |
| 338 | CompilationError::invalid_private); |
| 339 | } |
| 340 | if ( !pStruct->isClass && pDecl->isStatic ) { |
| 341 | das_yyerror(scanner,"only class member can be static "+name_at.name,name_at.at, |
| 342 | CompilationError::invalid_static); |
| 343 | } |
| 344 | */ |
| 345 | if ( (pDecl->override || pDecl->sealed) && pDecl->isStatic ) { |
| 346 | das_yyerror(scanner,"static member can't be sealed or override "+name_at.name,name_at.at, |
| 347 | CompilationError::invalid_field_static); |
| 348 | } |
| 349 | if ( pDecl->isStatic && pDecl->annotation ) { |
| 350 | das_yyerror(scanner,"static member can't have an annotation "+name_at.name,name_at.at, |
| 351 | CompilationError::invalid_field_static); |
| 352 | } |
| 353 | auto oldFd = (Structure::FieldDeclaration *) pStruct->findField(name_at.name); |
| 354 | if ( !oldFd ) { |
| 355 | if ( pDecl->override ) { |
| 356 | das_yyerror(scanner,"structure field is not overriding anything "+name_at.name,name_at.at, |
| 357 | CompilationError::invalid_field); |
| 358 | } else { |
| 359 | TypeDeclPtr td = nullptr; |
| 360 | ExpressionPtr init = nullptr; |
no test coverage detected