Lines Matching +full:read +full:- +full:out

1 //=== ClangASTPropsEmitter.cpp - Generate Clang AST properties --*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
44 /// The base name of methods: read/write
59 "read", in forReader()
91 raw_ostream &Out; member in __anon8e7483cb0111::ASTPropsEmitter
98 ASTPropsEmitter(RecordKeeper &records, raw_ostream &out) in ASTPropsEmitter() argument
99 : Out(out), Records(records) { in ASTPropsEmitter()
193 // - put arrays at the end to enable abbreviations in visitAllProperties()
194 // - put conditional properties after properties used in the condition in visitAllProperties()
221 auto &baseInfo = it->second; in visitAllNodesWithInfo()
311 // Diagnose non-unique properties. in validateNode()
315 Property existingProperty = result.first->second; in validateNode()
340 "type doesn't provide optional-packing code"); in validateType()
344 "type doesn't provide optional-unpacking code"); in validateType()
363 Out << "template <class Property" << suffix << ">\n" in emitNodeReaderWriterClass()
369 Out << " Abstract" << info.HierarchyName << suffix in emitNodeReaderWriterClass()
373 // Emit a method that dispatches on a kind to the appropriate node-specific in emitNodeReaderWriterClass()
375 Out << " " << info.ResultType << " " << info.MethodPrefix << "("; in emitNodeReaderWriterClass()
377 Out << NodeClass::getASTIdTypeName() << " kind"; in emitNodeReaderWriterClass()
379 Out << "const " << info.HierarchyName << " *node"; in emitNodeReaderWriterClass()
380 Out << ") {\n" in emitNodeReaderWriterClass()
383 Out << "kind"; in emitNodeReaderWriterClass()
385 Out << "node->" << NodeClass::getASTIdAccessorName() << "()"; in emitNodeReaderWriterClass()
386 Out << ") {\n"; in emitNodeReaderWriterClass()
389 Out << " case " << info.HierarchyName << "::" << node.getId() << ":\n" in emitNodeReaderWriterClass()
392 Out << "static_cast<const " << node.getClassName() in emitNodeReaderWriterClass()
394 Out << ");\n"; in emitNodeReaderWriterClass()
396 Out << " }\n" in emitNodeReaderWriterClass()
400 // Emit node-specific methods for all the concrete nodes. in emitNodeReaderWriterClass()
408 Out << "};\n\n"; in emitNodeReaderWriterClass()
416 Out << " " << info.ResultType << " " in emitNodeReaderWriterMethod()
419 Out << "const " << node.getClassName() << " *node"; in emitNodeReaderWriterMethod()
420 Out << ") {\n"; in emitNodeReaderWriterMethod()
422 Out << " auto &ctx = " << info.HelperVariable << ".getASTContext();\n"; in emitNodeReaderWriterMethod()
427 Out << " }\n\n"; in emitNodeReaderWriterMethod()
438 auto &nodeInfo = it->second; in emitPropertiedReaderWriterBody()
453 Out << " " << nodeInfo.ReadHelper.getHelperCode() << "\n"; in emitPropertiedReaderWriterBody()
456 // Emit code to read all the properties. in emitPropertiedReaderWriterBody()
465 // Emit code to read or write this property. in emitPropertiedReaderWriterBody()
474 Out << " " << creationCode << "\n"; in emitPropertiedReaderWriterBody()
477 static void emitBasicReaderWriterMethodSuffix(raw_ostream &out, in emitBasicReaderWriterMethodSuffix() argument
481 out << type.getAbstractTypeName(); in emitBasicReaderWriterMethodSuffix()
483 out << "Array"; in emitBasicReaderWriterMethodSuffix()
487 out << "<"; in emitBasicReaderWriterMethodSuffix()
488 eltType.emitCXXValueTypeName(isForRead, out); in emitBasicReaderWriterMethodSuffix()
489 out << ">"; in emitBasicReaderWriterMethodSuffix()
492 out << "Optional"; in emitBasicReaderWriterMethodSuffix()
496 out << "<"; in emitBasicReaderWriterMethodSuffix()
497 valueType.emitCXXValueTypeName(isForRead, out); in emitBasicReaderWriterMethodSuffix()
498 out << ">"; in emitBasicReaderWriterMethodSuffix()
505 /// Emit code to read the given property in a node-reader method.
519 Out << " llvm::SmallVector<"; in emitReadOfProperty()
520 PropertyType(bufferTypes[i]).emitCXXValueTypeName(/*for read*/ true, Out); in emitReadOfProperty()
521 Out << ", 8> " << name << "_buffer_" << i << ";\n"; in emitReadOfProperty()
524 // T prop = R.find("prop").read##ValueType(buffers...); in emitReadOfProperty()
526 // get a pr-value back from read(), and we should be able to forward in emitReadOfProperty()
528 Out << " "; in emitReadOfProperty()
530 Out << "std::optional<"; in emitReadOfProperty()
531 type.emitCXXValueTypeName(true, Out); in emitReadOfProperty()
532 if (!condition.empty()) Out << ">"; in emitReadOfProperty()
533 Out << " " << name; in emitReadOfProperty()
536 Out << " = "; in emitReadOfProperty()
538 Out << ";\n" in emitReadOfProperty()
543 Out << readerName << ".find(\"" << name << "\")." in emitReadOfProperty()
544 << (type.isGenericSpecialization() ? "template " : "") << "read"; in emitReadOfProperty()
545 emitBasicReaderWriterMethodSuffix(Out, type, /*for read*/ true); in emitReadOfProperty()
546 Out << "("; in emitReadOfProperty()
548 Out << (i > 0 ? ", " : "") << name << "_buffer_" << i; in emitReadOfProperty()
550 Out << ")"; in emitReadOfProperty()
553 Out << ";\n"; in emitReadOfProperty()
555 Out << ");\n" in emitReadOfProperty()
560 /// Emit code to write the given property in a node-writer method.
573 Out << " if (" << condition << ") {\n"; in emitWriteOfProperty()
577 // T prop = <READ>; in emitWriteOfProperty()
579 Out << " "; in emitWriteOfProperty()
580 type.emitCXXValueTypeName(false, Out); in emitWriteOfProperty()
581 Out << " " << name << " = (" << readCode << ");\n" in emitWriteOfProperty()
583 emitBasicReaderWriterMethodSuffix(Out, type, /*for read*/ false); in emitWriteOfProperty()
584 Out << "(" << name << ");\n"; in emitWriteOfProperty()
587 Out << " }\n"; in emitWriteOfProperty()
594 static void emitASTReader(RecordKeeper &records, raw_ostream &out, in emitASTReader() argument
596 emitSourceFileHeader(description, out, records); in emitASTReader()
598 ASTPropsEmitter(records, out).emitNodeReaderClass<NodeClass>(); in emitASTReader()
601 void clang::EmitClangTypeReader(RecordKeeper &records, raw_ostream &out) { in EmitClangTypeReader() argument
602 emitASTReader<TypeNode>(records, out, "A CRTP reader for Clang Type nodes"); in EmitClangTypeReader()
608 static void emitASTWriter(RecordKeeper &records, raw_ostream &out, in emitASTWriter() argument
610 emitSourceFileHeader(description, out, records); in emitASTWriter()
612 ASTPropsEmitter(records, out).emitNodeWriterClass<NodeClass>(); in emitASTWriter()
615 void clang::EmitClangTypeWriter(RecordKeeper &records, raw_ostream &out) { in EmitClangTypeWriter() argument
616 emitASTWriter<TypeNode>(records, out, "A CRTP writer for Clang Type nodes"); in EmitClangTypeWriter()
625 // Declare the {Read,Write}Dispatcher template. in emitDispatcherTemplate()
626 StringRef dispatcherPrefix = (info.IsReader ? "Read" : "Write"); in emitDispatcherTemplate()
627 Out << "template <class ValueType>\n" in emitDispatcherTemplate()
636 Out << "template " << specializationParameters << "\n" in emitDispatcherTemplate()
639 Out << " template <class Basic" << info.ClassSuffix << ", class... Args>\n" in emitDispatcherTemplate()
668 Out << "\n"; in emitDispatcherTemplate()
677 Out << "template <class ValueType>\n" in emitPackUnpackOptionalTemplate()
681 Out << "template <>\n" in emitPackUnpackOptionalTemplate()
708 Out << "\n"; in emitPackUnpackOptionalTemplate()
714 Out << "template <class Impl>\n" in emitBasicReaderWriterTemplate()
716 Out << " ASTContext &C;\n"; in emitBasicReaderWriterTemplate()
717 Out << "protected:\n" in emitBasicReaderWriterTemplate()
722 Out << " ASTContext &getASTContext() { return C; }\n"; in emitBasicReaderWriterTemplate()
723 Out << " Impl &asImpl() { return static_cast<Impl&>(*this); }\n"; in emitBasicReaderWriterTemplate()
730 Out << " " << (info.IsReader ? cxxTypeName : "void") in emitBasicReaderWriterTemplate()
733 Out << (shouldPassByReference || constWhenWriting ? "const " : "") in emitBasicReaderWriterTemplate()
736 Out << ") {\n"; in emitBasicReaderWriterTemplate()
739 // Emit {read,write}ValueType methods for all the enum and subclass types in emitBasicReaderWriterTemplate()
740 // that default to using the integer/base-class implementations. in emitBasicReaderWriterTemplate()
750 Out << " }\n"; in emitBasicReaderWriterTemplate()
757 emitCasedReaderWriterMethodBody(type, casedIter->second, info); in emitBasicReaderWriterTemplate()
763 Out << " return asImpl().template readEnum<" in emitBasicReaderWriterTemplate()
766 Out << " asImpl().writeEnum(value);\n"; in emitBasicReaderWriterTemplate()
772 Out << " return cast_or_null<" << type.getSubclassClassName() in emitBasicReaderWriterTemplate()
773 << ">(asImpl().read" in emitBasicReaderWriterTemplate()
777 Out << " asImpl().write" << superclass.getAbstractTypeName() in emitBasicReaderWriterTemplate()
785 Out << "};\n\n"; in emitBasicReaderWriterTemplate()
807 Out << " auto &ctx = asImpl().getASTContext();\n"; in emitCasedReaderWriterMethodBody()
810 Out << " auto &&" << subvar << " = asImpl()." in emitCasedReaderWriterMethodBody()
813 // Read/write the kind property; in emitCasedReaderWriterMethodBody()
820 // Write the property. Note that this will implicitly read the in emitCasedReaderWriterMethodBody()
827 // the sub-reader/writer. in emitCasedReaderWriterMethodBody()
832 Out << " switch (" << kindProperty << ") {\n"; in emitCasedReaderWriterMethodBody()
834 Out << " case " << type.getCXXTypeName() << "::" in emitCasedReaderWriterMethodBody()
838 Out << " return;\n"; in emitCasedReaderWriterMethodBody()
839 Out << " }\n\n"; in emitCasedReaderWriterMethodBody()
841 Out << " }\n" in emitCasedReaderWriterMethodBody()
854 void clang::EmitClangBasicReader(RecordKeeper &records, raw_ostream &out) { in EmitClangBasicReader() argument
855 emitSourceFileHeader("Helper classes for BasicReaders", out, records); in EmitClangBasicReader()
859 ASTPropsEmitter(records, out).emitBasicReaderWriterFile(info); in EmitClangBasicReader()
864 void clang::EmitClangBasicWriter(RecordKeeper &records, raw_ostream &out) { in EmitClangBasicWriter() argument
865 emitSourceFileHeader("Helper classes for BasicWriters", out, records); in EmitClangBasicWriter()
869 ASTPropsEmitter(records, out).emitBasicReaderWriterFile(info); in EmitClangBasicWriter()