| 707 | } |
| 708 | |
| 709 | vector<VariableDeclaration*> * ast_structVarDef ( yyscan_t scanner, vector<VariableDeclaration*> * list, |
| 710 | AnnotationList * annL, bool isStatic, bool isPrivate, int ovr, bool cnst, Function * func, Expression * block, |
| 711 | const LineInfo & fromBlock, const LineInfo & annLAt ) { |
| 712 | func->atDecl = fromBlock; |
| 713 | func->body = block; |
| 714 | func->isConstClassMethod = cnst; |
| 715 | auto isGeneric = func->isGeneric(); |
| 716 | if ( !yyextra->g_thisStructure ) { |
| 717 | das_yyerror(scanner,"internal error or invalid macro. member function is declared outside of a class", |
| 718 | func->at, CompilationError::internal_function); |
| 719 | } else if ( yyextra->g_Program->policies.no_members_functions_in_struct && !yyextra->g_thisStructure->isClass ) { |
| 720 | das_yyerror(scanner,"structure can't have a member function", |
| 721 | func->at, CompilationError::invalid_function); |
| 722 | } else if ( isGeneric && !isStatic ) { |
| 723 | das_yyerror(scanner,"generic function can't be a member of a class " + func->getMangledName(), |
| 724 | func->at, CompilationError::invalid_function); |
| 725 | } else if ( isOpName(func->name) ) { |
| 726 | if ( ovr ) { |
| 727 | das_yyerror(scanner,"can't override an operator " + func->getMangledName(), |
| 728 | func->at, CompilationError::invalid_function); |
| 729 | } |
| 730 | if ( isStatic ) { |
| 731 | func->isClassMethod = true; |
| 732 | func->isStaticClassMethod = true; |
| 733 | func->classParent = yyextra->g_thisStructure; |
| 734 | func->privateFunction = isPrivate || yyextra->g_thisStructure->privateStructure; |
| 735 | } else { |
| 736 | modifyToClassMember(func, yyextra->g_thisStructure, false, cnst); |
| 737 | } |
| 738 | assignDefaultArguments(func); |
| 739 | runFunctionAnnotations(scanner, nullptr, func, annL, annLAt); |
| 740 | if ( !yyextra->g_Program->addFunction(func) ) { |
| 741 | das_yyerror(scanner,"function is already defined " + func->getMangledName(), |
| 742 | func->at, CompilationError::already_declared_function); |
| 743 | } |
| 744 | func->delRef(); |
| 745 | } else { |
| 746 | func->privateFunction = yyextra->g_thisStructure->privateStructure; |
| 747 | if ( func->name != yyextra->g_thisStructure->name && func->name != "finalize") { |
| 748 | if ( isStatic ) { |
| 749 | func->name = yyextra->g_thisStructure->name + "`" + func->name; |
| 750 | func->isClassMethod = true; |
| 751 | func->isStaticClassMethod = true; |
| 752 | func->classParent = yyextra->g_thisStructure; |
| 753 | func->privateFunction = isPrivate || yyextra->g_thisStructure->privateStructure; |
| 754 | } else { |
| 755 | auto varName = func->name; |
| 756 | func->name = yyextra->g_thisStructure->name + "`" + func->name; |
| 757 | auto vars = new vector<VariableNameAndPosition>(); |
| 758 | vars->emplace_back(VariableNameAndPosition(varName,"",func->at)); |
| 759 | Expression * finit = new ExprAddr(func->at, inThisModule(func->name)); |
| 760 | if ( ovr == OVERRIDE_OVERRIDE ) { |
| 761 | finit = new ExprCast(func->at, finit, new TypeDecl(Type::autoinfer)); |
| 762 | } else if ( ovr == OVERRIDE_SEALED ) { |
| 763 | if ( yyextra->g_thisStructure->findField(varName) ) { // only if we are actually overriding a field |
| 764 | finit = new ExprCast(func->at, finit, new TypeDecl(Type::autoinfer)); |
| 765 | } |
| 766 | } |
no test coverage detected