ref_t ModuleScope :: resolveClosure(ref_t closureMessage, ref_t outputRef, ident_t ns) { ref_t signRef = 0; module->resolveAction(getAction(closureMessage), signRef); int paramCount = getParamCount(closureMessage); IdentifierString closureName(module->resolveReference(closureTemplateReference)); if (signRef == 0) { if (paramCount > 0) { closureName.appendInt(paramCount); } if (isWeakReference(closureName)) { return module->mapReference(closureName, true); } else return mapFullReference(closureName, true); } else { ref_t signatures[ARG_COUNT]; size_t signLen = module->resolveSignature(signRef, signatures); List<SNode> parameters; SyntaxTree dummyTree; SyntaxWriter dummyWriter(dummyTree); dummyWriter.newNode(lxRoot); for (size_t i = 0; i < signLen; i++) { dummyWriter.appendNode(lxTarget, signatures[i]); } if (outputRef) { dummyWriter.appendNode(lxTarget, outputRef); } // if the output signature is not provided - use the super class else dummyWriter.appendNode(lxTarget, superReference); dummyWriter.closeNode(); SNode paramNode = dummyTree.readRoot().firstChild(); while (paramNode != lxNone) { parameters.add(paramNode); paramNode = paramNode.nextNode(); } closureName.append('#'); closureName.appendInt(paramCount + 1); ref_t templateReference = 0; if (isWeakReference(closureName)) { templateReference = module->mapReference(closureName, true); } else templateReference = mapFullReference(closureName, true); if (templateReference) { return generateTemplate(templateReference, parameters, ns, false); } else return superReference; } }
void ModuleScope :: generateTemplateProperty(SyntaxWriter& output, ref_t reference, List<SNode>& parameters) { SyntaxTree templateTree; TemplateGenerator transformer(templateTree); SyntaxWriter writer(templateTree); writer.newNode(lxRoot); transformer.generateTemplateProperty(writer, *this, reference, parameters); writer.closeNode(); SyntaxTree::copyNode(output, templateTree.readRoot()); }
void ModuleScope :: importClassTemplate(SyntaxWriter& output, ref_t reference, List<SNode>& parameters) { SyntaxTree templateTree; TemplateGenerator transformer(templateTree); SyntaxWriter writer(templateTree); writer.newNode(lxRoot); transformer.generateTemplate(writer, *this, reference, parameters, false, true); writer.closeNode(); transformer.importClass(output, templateTree.readRoot()); }
void SyntaxTree :: moveNodes(Writer& writer, SyntaxTree& buffer) { SNode current = buffer.readRoot(); while (current != lxNone) { if (current != lxIdle) { if (current.strArgument >= 0) { writer.newNode(current.type, current.identifier()); } else writer.newNode(current.type, current.argument); SyntaxTree::copyNode(writer, current); writer.closeNode(); current = lxIdle; } current = current.nextNode(); } }
void Project :: compile(ident_t filePath, Compiler& compiler, Parser& parser, ModuleInfo& moduleInfo, Unresolveds& unresolved) { try { // based on the target type generate the syntax tree for the file Path fullPath(StrSetting(_ELENA_::opProjectPath)); fullPath.combine(filePath); // parse TextFileReader sourceFile(fullPath.c_str(), getDefaultEncoding(), true); if (!sourceFile.isOpened()) raiseError(errInvalidFile, filePath); SyntaxTree tree; DerivationWriter writer(tree); parser.parse(&sourceFile, writer, getTabSize()); // compile the syntax tree compiler.compileModule(*this, filePath, tree.readRoot(), moduleInfo, unresolved); } catch (LineTooLong& e) { raiseError(errLineTooLong, filePath, e.row, 1); } catch (InvalidChar& e) { size_t destLength = 6; _ELENA_::String<char, 6> symbol; _ELENA_::Convertor::copy(symbol, (_ELENA_::unic_c*)&e.ch, 1, destLength); raiseError(errInvalidChar, filePath, e.row, e.column, (const char*)symbol); } catch (SyntaxError& e) { raiseError(e.error, filePath, e.row, e.column, e.token); } }
void Project :: compile(ident_t filePath, Compiler& compiler, ScriptParser parser, ModuleInfo& moduleInfo, Unresolveds& unresolved) { try { // based on the target type generate the syntax tree for the file Path fullPath(StrSetting(_ELENA_::opProjectPath)); fullPath.combine(filePath); // parse SyntaxTree tree; parser.parse(fullPath.c_str(), tree/*, getTabSize()*/); // compile the syntax tree compiler.compileModule(*this, filePath, tree.readRoot(), moduleInfo, unresolved); } catch (LineTooLong& e) { raiseError(errLineTooLong, filePath, e.row, 1); } catch (InvalidChar& e) { size_t destLength = 6; _ELENA_::String<char, 6> symbol; _ELENA_::Convertor::copy(symbol, (_ELENA_::unic_c*)&e.ch, 1, destLength); raiseError(errInvalidChar, filePath, e.row, e.column, (const char*)symbol); } catch (SyntaxError& e) { raiseError(e.error, filePath, e.row, e.column, e.token); } catch (ScriptError& e) { raiseError(e.error, filePath); } }