webkit idl parser 模組分析

來源:互聯網
上載者:User

csdn    lidp    http://blog.csdn.net/perfectpdl 

webkit 中 根據idl介面 語言定義dom對象,然後通過perl 解析模組產生經過封裝的c++ 檔案。

與idl解析相關的五個檔案如下:

bindings/scripts/CodeGenerator.pm 
bindings/scripts/CodeGeneratorV8.pm 
bindings/scripts/IDLParser.pm 
bindings/scripts/IDLStructure.pm 
bindings/scripts/generate-bindings.pl

generate-bindings.pl  為解析 idl檔案入口,根據idl檔案定義產生 c++標頭檔及源檔案。

generate-bindings.pl  在makefile中被調用。比如android平台上在 webcore/Android.derived.v8bindings.mk 檔案中。

generate-bindings.pl 代碼:

首先 擷取 參數:
GetOptions('include=s@' => \@idlDirectories, # 目錄, 依賴,輸出目錄等參數。
           'outputDir=s' => \$outputDirectory,
           'generator=s' => \$generator,
           'defines=s' => \$defines,
           'preprocessor=s' => \$preprocessor,
           'write-dependencies' => \$writeDependencies);

my $idlFile = $ARGV[0];       # 要解析的idl檔案

$defines =~ s/^\s+|\s+$//g; # Regex去掉空格

# Parse the given IDL file.
#建立一個解析器
my $parser = IDLParser->new(1); # 對應IDLParser.pm  代碼
my $document = $parser->Parse($idlFile, $defines, $preprocessor);

# Generate desired output for given IDL file.  對應 CodeGenerator.pm 代碼。

my $codeGen = CodeGenerator->new(\@idlDirectories, $generator, $outputDirectory, 0, $preprocessor, $writeDependencies);

#產生標頭檔及源檔案
$codeGen->ProcessDocument($document, $defines);

ProcessDocument->GenerateInterface(CodeGeneratorV8.pm)
 

                                        |->GenerateHeader(CodeGeneratorV8.pm) 產生標頭檔,
GenerateInterface->   |
                                        |->GenerateImplementation(CodeGeneratorV8.pm) 產生源檔案
 

       

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.