Thrift Code Generator compiler principle and source detailed analysis 1 class diagram

Source: Internet
Author: User
Tags definition generator glusterfs

Recently busy studying Glusterfs, was going to write a few blog weekend, but due to debug some of the new features of Glusterfs used a whole day, and a day to accompany the wife of adults to go shopping! This evening after browsing the microblogging discovery time has come to blog one, this blog content is mainly in the previous period of time to study the Thrift code generator of the source of detailed analysis, no specific analysis of parsing, because it is the tool field generated code, people are no way to read the----are everywhere jump table! Because the thrift support n many languages, but the generation code principle is similar, I mainly analyzed the C + + related code generation. About the use and principle of thrift, code online basically have, code annotation is very good, basically are English annotation. Here's what I've written before, and I want to be helpful to enthusiasts who are learning to use code generation code.

This feature is a separate tool that generates an executable file independently.

Section one class diagram

This section mainly shows the overall class diagram of this section, and then do a brief description of this class diagram, with this class diagram so that I can read this part of the source code can not find direction, let me know how the class in this section work together, the class diagram is as follows:

Note: The solid line represents the inheritance relationship, and the dashed lines represent dependencies.

The class diagram shows that the compiler function module is mainly divided into two parts, one is the right side of the graph shows the various language code generated classes. Their common base classes are all T_generator classes, but the object-oriented language does not inherit directly from it, but instead extracts the common object-oriented features into a class that is t_oop_generator, and other object-oriented language generation classes inherit from this class. The implementation of the total base class is dependent on the left T_program class, which represents all the features and elements required by a program code. The left part is to solve a program needs to have the data types and functions, according to Interface Definition language (IDL) to parse and generate the corresponding data and functions. The left section shows the data types that thrift defined intermediate language (IDL) can support, and the T_type class is the base class for all data type classes.

Section II Procedure flow chart

The overall flowchart for this section is shown in the following illustration:

The above flowchart briefly illustrates a process of compiler running, which lets us know the whole idea and process of generating various program code according to the intermediate definition language. The next section will be based on the source code detailed analysis of the principle and implementation of the process, which involves a number of compiler principles of knowledge, not in-depth analysis of this part, it inside the lexical analysis program is the use of Linux tools Flex automatic generation of C language programs, The Yyparse function can be called directly when parsing the intermediate definition language. Another part of the focus is to generate a variety of programming language code functions, each language with a class to generate, the following will not be detailed analysis of the generation of each language implementation code, the main analysis of three major languages (C + +, Java, Python).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.