MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / ast_structVarDefAbstract

Function ast_structVarDefAbstract

src/parser/parser_impl.cpp:634–688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

632 }
633
634 vector<VariableDeclaration*> * ast_structVarDefAbstract ( yyscan_t scanner, vector<VariableDeclaration*> * list,
635 AnnotationList * annL, bool isPrivate, bool cnst, Function * func ) {
636 if ( yyextra->g_thisStructure ) {
637 if ( yyextra->g_Program->policies.no_members_functions_in_struct && !yyextra->g_thisStructure->isClass ) {
638 das_yyerror(scanner,"structure can't have a member function",
639 func->at, CompilationError::invalid_function);
640 } else if ( func->isGeneric() ) {
641 das_yyerror(scanner,"generic function can't be a member of a class " + func->getMangledName(),
642 func->at, CompilationError::invalid_function);
643 } else if ( func->name==yyextra->g_thisStructure->name || func->name=="finalize" ) {
644 das_yyerror(scanner,"initializers and finalizers can't be abstract " + func->getMangledName(),
645 func->at, CompilationError::invalid_function);
646 } else if ( annL!=nullptr ) {
647 das_yyerror(scanner,"abstract functions can't have annotations " + func->getMangledName(),
648 func->at, CompilationError::invalid_function_annotation);
649 delete annL;
650 } else if ( func->result->baseType==Type::autoinfer ) {
651 das_yyerror(scanner,"abstract functions must specify return type explicitly " + func->getMangledName(),
652 func->at, CompilationError::missing_function_result);
653 } else if ( isOpName(func->name) ) {
654 das_yyerror(scanner,"abstract functions can't be operators " + func->getMangledName(),
655 func->at, CompilationError::invalid_function);
656 } else {
657 auto varName = func->name;
658 func->name = yyextra->g_thisStructure->name + "`" + func->name;
659 auto vars = new vector<VariableNameAndPosition>();
660 vars->emplace_back(VariableNameAndPosition(varName,"",func->at));
661 TypeDecl * funcType = new TypeDecl(Type::tFunction);
662 funcType->at = func->at;
663 swap ( funcType->firstType, func->result );
664 funcType->argTypes.reserve ( func->arguments.size() );
665 if ( yyextra->g_thisStructure->isClass ) {
666 auto selfType = new TypeDecl(yyextra->g_thisStructure);
667 selfType->constant = cnst;
668 funcType->argTypes.push_back(selfType);
669 funcType->argNames.push_back("self");
670 }
671 for ( auto & arg : func->arguments ) {
672 funcType->argTypes.push_back(arg->type);
673 funcType->argNames.push_back(arg->name);
674 }
675 VariableDeclaration * decl = new VariableDeclaration(
676 vars,
677 funcType,
678 nullptr
679 );
680 decl->isPrivate = isPrivate;
681 decl->isClassMethod = true;
682 decl->isAbstract = true;
683 list->push_back(decl);
684 }
685 }
686 func->delRef();
687 return list;
688 }
689
690 void implAddGenericFunction ( yyscan_t scanner, Function * func ) {
691 for ( auto & arg : func->arguments ) {

Callers 3

yyparseFunction · 0.85
yyparseFunction · 0.85
yyparseFunction · 0.85

Calls 10

isOpNameFunction · 0.85
das_yyerrorFunction · 0.70
swapFunction · 0.50
isGenericMethod · 0.45
getMangledNameMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
delRefMethod · 0.45

Tested by

no test coverage detected