| 2209 | } |
| 2210 | |
| 2211 | FunctionPtr makeClassFinalize ( Structure * baseClass ) { |
| 2212 | // add __finalize field |
| 2213 | auto fname = baseClass->name + "'__finalize"; |
| 2214 | ExpressionPtr finit = new ExprAddr(baseClass->at, "_::" + fname); |
| 2215 | if ( baseClass->parent ) { |
| 2216 | auto fd = (Structure::FieldDeclaration *) baseClass->findField("__finalize"); |
| 2217 | fd->init = new ExprCast(baseClass->at, finit, new TypeDecl(Type::autoinfer)); |
| 2218 | fd->parentType = fd->type->isAuto(); |
| 2219 | fd->generated = true; |
| 2220 | } else { |
| 2221 | baseClass->fields.emplace_back( |
| 2222 | "__finalize", |
| 2223 | new TypeDecl(Type::autoinfer), |
| 2224 | finit, |
| 2225 | AnnotationArgumentList(), |
| 2226 | false, |
| 2227 | baseClass->at |
| 2228 | ); |
| 2229 | baseClass->fields.back().generated = true; |
| 2230 | } |
| 2231 | // make a function |
| 2232 | auto func = new Function(); |
| 2233 | func->generated = true; |
| 2234 | func->at = baseClass->at; |
| 2235 | func->atDecl = baseClass->at; |
| 2236 | func->name = fname; |
| 2237 | func->result = new TypeDecl(Type::tVoid); |
| 2238 | func->isClassMethod = true; |
| 2239 | func->classParent = baseClass; |
| 2240 | func->isTemplate = baseClass->isTemplate; |
| 2241 | DAS_ASSERT(func->classParent); |
| 2242 | if ( baseClass->macroInterface ) func->macroFunction = true; |
| 2243 | auto block = new ExprBlock(); |
| 2244 | block->at = func->at; |
| 2245 | func->body = block; |
| 2246 | // only one argument, and its 'self' |
| 2247 | auto argT = new TypeDecl(baseClass); |
| 2248 | argT->constant = false; |
| 2249 | auto argV = new Variable(); |
| 2250 | argV->name = "self"; |
| 2251 | argV->type = argT; |
| 2252 | argV->at = func->at; |
| 2253 | argV->generated = true; |
| 2254 | argV->capture_as_ref = true; |
| 2255 | func->arguments.push_back(argV); |
| 2256 | // delete |
| 2257 | auto vself = new ExprVar(func->at, "self"); |
| 2258 | auto edel = new ExprDelete(func->at, vself); |
| 2259 | edel->alwaysSafe = true; |
| 2260 | block->list.push_back(edel); |
| 2261 | // and done |
| 2262 | verifyGenerated(func->body); |
| 2263 | return func; |
| 2264 | } |
| 2265 | |
| 2266 | ExpressionPtr convertToCloneExpr ( ExprMakeStruct * expr, int index, MakeFieldDecl * decl, bool ignoreCaptureConst ) { |
| 2267 | bool needIndex = expr->structs.size()>1; |
no test coverage detected