Changeset View
Changeset View
Standalone View
Standalone View
duchain/builders/typebuilder.cpp
Show First 20 Lines • Show All 222 Lines • ▼ Show 20 Line(s) | 202 | { | |||
---|---|---|---|---|---|
223 | currentType<go::GoStructureType>()->setInterfaceType(); | 223 | currentType<go::GoStructureType>()->setInterfaceType(); | ||
224 | closeType(); | 224 | closeType(); | ||
225 | } | 225 | } | ||
226 | 226 | | |||
227 | void TypeBuilder::visitMethodSpec(go::MethodSpecAst* node) | 227 | void TypeBuilder::visitMethodSpec(go::MethodSpecAst* node) | ||
228 | { | 228 | { | ||
229 | if(node->signature) | 229 | if(node->signature) | ||
230 | { | 230 | { | ||
231 | parseSignature(node->signature, true, node->methodName); | 231 | parseSignature(node->signature, true, nullptr, node->methodName); | ||
232 | }else{ | 232 | }else{ | ||
233 | buildTypeName(node->methodName, node->fullName); | 233 | buildTypeName(node->methodName, node->fullName); | ||
234 | go::IdentifierAst* id = node->fullName ? node->fullName : node->methodName; | 234 | go::IdentifierAst* id = node->fullName ? node->fullName : node->methodName; | ||
235 | { | 235 | { | ||
236 | declareVariable(id, lastType()); | 236 | declareVariable(id, lastType()); | ||
237 | } | 237 | } | ||
238 | } | 238 | } | ||
239 | } | 239 | } | ||
Show All 36 Lines | 273 | { | |||
276 | //also if type is just identifier it is impossible to say right now whether it is really a type | 276 | //also if type is just identifier it is impossible to say right now whether it is really a type | ||
277 | //or a identifier. This will be decided in parseParameres method | 277 | //or a identifier. This will be decided in parseParameres method | ||
278 | if(node->idOrType && node->fulltype) | 278 | if(node->idOrType && node->fulltype) | ||
279 | buildTypeName(node->idOrType, node->fulltype); | 279 | buildTypeName(node->idOrType, node->fulltype); | ||
280 | TypeBuilderBase::visitParameter(node); | 280 | TypeBuilderBase::visitParameter(node); | ||
281 | } | 281 | } | ||
282 | 282 | | |||
283 | 283 | | |||
284 | go::GoFunctionDeclaration* TypeBuilder::parseSignature(go::SignatureAst* node, bool declareParameters, go::IdentifierAst* name, const QByteArray& comment) | 284 | go::GoFunctionDeclaration* TypeBuilder::parseSignature(go::SignatureAst* node, bool declareParameters, DUContext* bodyContext, go::IdentifierAst* name, const QByteArray& comment) | ||
285 | { | 285 | { | ||
286 | go::GoFunctionType::Ptr type(new go::GoFunctionType()); | 286 | go::GoFunctionType::Ptr type(new go::GoFunctionType()); | ||
287 | openType<go::GoFunctionType>(type); | 287 | openType<go::GoFunctionType>(type); | ||
288 | 288 | | |||
289 | DUContext* parametersContext; | 289 | DUContext* parametersContext = nullptr; | ||
290 | if(declareParameters) parametersContext = openContext(node->parameters, | 290 | if(declareParameters) parametersContext = openContext(node->parameters, | ||
291 | editorFindRange(node->parameters, 0), | 291 | editorFindRange(node->parameters, 0), | ||
292 | DUContext::ContextType::Function, | 292 | DUContext::ContextType::Function, | ||
293 | name); | 293 | name); | ||
294 | 294 | | |||
295 | parseParameters(node->parameters, true, declareParameters); | 295 | parseParameters(node->parameters, true, declareParameters); | ||
296 | if(declareParameters) closeContext(); | 296 | if(declareParameters) closeContext(); | ||
297 | 297 | | |||
298 | DUContext* returnArgsContext=0; | 298 | DUContext* returnArgsContext = nullptr; | ||
299 | 299 | | |||
300 | if(node->result) | 300 | if(node->result) | ||
301 | { | 301 | { | ||
302 | visitResult(node->result); | 302 | visitResult(node->result); | ||
303 | if(node->result->parameters) | 303 | if(node->result->parameters) | ||
304 | { | 304 | { | ||
305 | if(declareParameters) returnArgsContext = openContext(node->result, | 305 | if(declareParameters) returnArgsContext = openContext(node->result, | ||
306 | editorFindRange(node->result, 0), | 306 | editorFindRange(node->result, 0), | ||
307 | DUContext::ContextType::Function, | 307 | DUContext::ContextType::Function, | ||
308 | name); | 308 | name); | ||
309 | parseParameters(node->result->parameters, false, declareParameters); | 309 | parseParameters(node->result->parameters, false, declareParameters); | ||
310 | if(declareParameters) closeContext(); | 310 | if(declareParameters) closeContext(); | ||
311 | 311 | | |||
312 | } | 312 | } | ||
313 | if(!node->result->parameters && lastType()) | 313 | if(!node->result->parameters && lastType()) | ||
314 | type->addReturnArgument(lastType()); | 314 | type->addReturnArgument(lastType()); | ||
315 | } | 315 | } | ||
316 | closeType(); | 316 | closeType(); | ||
317 | 317 | | |||
318 | if(declareParameters) | 318 | if(declareParameters) | ||
319 | { | 319 | { | ||
320 | return declareFunction(name, type, parametersContext, returnArgsContext, comment); | 320 | return declareFunction(name, type, parametersContext, returnArgsContext, comment, bodyContext); | ||
321 | } | 321 | } | ||
322 | return 0; | 322 | return 0; | ||
323 | } | 323 | } | ||
324 | 324 | | |||
325 | void TypeBuilder::parseParameters(go::ParametersAst* node, bool parseArguments, bool declareParameters) | 325 | void TypeBuilder::parseParameters(go::ParametersAst* node, bool parseArguments, bool declareParameters) | ||
326 | { | 326 | { | ||
327 | //code below is a bit ugly because of problems with parsing go parameter list(see details at parser/go.g:331) | 327 | //code below is a bit ugly because of problems with parsing go parameter list(see details at parser/go.g:331) | ||
328 | go::GoFunctionType::Ptr function; | 328 | go::GoFunctionType::Ptr function; | ||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 420 | { | |||
423 | { | 423 | { | ||
424 | if(parseArguments) | 424 | if(parseArguments) | ||
425 | function->addArgument(argument); | 425 | function->addArgument(argument); | ||
426 | else | 426 | else | ||
427 | function->addReturnArgument(argument); | 427 | function->addReturnArgument(argument); | ||
428 | } | 428 | } | ||
429 | } | 429 | } | ||
430 | 430 | | |||
431 | //TODO call this from DeclarationBuilder::visitFunctionDecl | | |||
432 | void TypeBuilder::buildFunction(SignatureAst* node, BlockAst* block) | | |||
433 | { | | |||
434 | go::GoFunctionDeclaration* decl = parseSignature(node, true); | | |||
435 | AbstractType::Ptr type = lastType(); | | |||
436 | if(block) | | |||
437 | { | | |||
438 | DUContext* bodyContext = openContext(block, DUContext::ContextType::Function); | | |||
439 | {//import parameters into body context | | |||
440 | DUChainWriteLocker lock; | | |||
441 | if(decl->internalContext()) | | |||
442 | currentContext()->addImportedParentContext(decl->internalContext()); | | |||
443 | if(decl->returnArgsContext()) | | |||
444 | currentContext()->addImportedParentContext(decl->returnArgsContext()); | | |||
445 | } | | |||
446 | visitBlock(block); | | |||
447 | closeContext(); //wrapper context | | |||
448 | injectType(type); | | |||
449 | } | | |||
450 | } | | |||
451 | | ||||
452 | | ||||
453 | } | 431 | } | ||
454 | No newline at end of file | 432 | No newline at end of file |