| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package parser | 5 package parser |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "io/ioutil" | 9 "io/ioutil" |
| 10 "mojom/mojom_parser/mojom" | 10 "mojom/mojom_parser/mojom" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 filesToProcess = filesToProcess[1:] | 97 filesToProcess = filesToProcess[1:] |
| 98 if err = d.fileProvider.findFile(currentFile); err != nil { | 98 if err = d.fileProvider.findFile(currentFile); err != nil { |
| 99 return | 99 return |
| 100 } | 100 } |
| 101 | 101 |
| 102 if currentFile.importedFrom != nil { | 102 if currentFile.importedFrom != nil { |
| 103 // Tell the importing file about the absolute path of th
e imported file. | 103 // Tell the importing file about the absolute path of th
e imported file. |
| 104 // Note that we must do this even if the imported file h
as already been processed | 104 // Note that we must do this even if the imported file h
as already been processed |
| 105 // because a given file may be imported by multiple file
s and each of those need | 105 // because a given file may be imported by multiple file
s and each of those need |
| 106 // to be told about the absolute path of the imported fi
le. | 106 // to be told about the absolute path of the imported fi
le. |
| 107 » » » currentFile.importedFrom.mojomFile.Imports[currentFile.s
pecifiedPath] = currentFile.absolutePath | 107 » » » currentFile.importedFrom.mojomFile.SetCanonicalImportNam
e(currentFile.specifiedPath, currentFile.absolutePath) |
| 108 } | 108 } |
| 109 | 109 |
| 110 if !descriptor.ContainsFile(currentFile.absolutePath) { | 110 if !descriptor.ContainsFile(currentFile.absolutePath) { |
| 111 contents, fileReadError := d.fileProvider.provideContent
s(currentFile) | 111 contents, fileReadError := d.fileProvider.provideContent
s(currentFile) |
| 112 if fileReadError != nil { | 112 if fileReadError != nil { |
| 113 err = fileReadError | 113 err = fileReadError |
| 114 return | 114 return |
| 115 } | 115 } |
| 116 parser := MakeParser(currentFile.absolutePath, contents,
descriptor) | 116 parser := MakeParser(currentFile.absolutePath, contents,
descriptor) |
| 117 parser.SetDebugMode(d.debugMode) | 117 parser.SetDebugMode(d.debugMode) |
| 118 // Invoke parser.Parse() (but skip doing so in tests som
etimes.) | 118 // Invoke parser.Parse() (but skip doing so in tests som
etimes.) |
| 119 d.parseInvoker.invokeParse(&parser) | 119 d.parseInvoker.invokeParse(&parser) |
| 120 | 120 |
| 121 if d.debugMode { | 121 if d.debugMode { |
| 122 fmt.Printf("\nParseTree for %s:", currentFile) | 122 fmt.Printf("\nParseTree for %s:", currentFile) |
| 123 fmt.Println(parser.GetParseTree()) | 123 fmt.Println(parser.GetParseTree()) |
| 124 } | 124 } |
| 125 | 125 |
| 126 if !parser.OK() { | 126 if !parser.OK() { |
| 127 err = fmt.Errorf("\nError while parsing %s: \n%s
\n", | 127 err = fmt.Errorf("\nError while parsing %s: \n%s
\n", |
| 128 currentFile, parser.GetError().Error()) | 128 currentFile, parser.GetError().Error()) |
| 129 return | 129 return |
| 130 } | 130 } |
| 131 currentFile.mojomFile = d.fileExtractor.extractMojomFile
(&parser) | 131 currentFile.mojomFile = d.fileExtractor.extractMojomFile
(&parser) |
| 132 » » » for importedFile, _ := range currentFile.mojomFile.Impor
ts { | 132 » » » for _, importedFile := range currentFile.mojomFile.Impor
ts { |
| 133 // Note that it is important that we append all
of the imported files here even | 133 // Note that it is important that we append all
of the imported files here even |
| 134 // if some of them have already been processed.
That is because when the imported | 134 // if some of them have already been processed.
That is because when the imported |
| 135 // file is pulled from the queue it will be pre-
processed during which time the | 135 // file is pulled from the queue it will be pre-
processed during which time the |
| 136 // absolute path to the file will be discovered
and this absolute path will be | 136 // absolute path to the file will be discovered
and this absolute path will be |
| 137 // set in |mojomFile| which is necessary for ser
ializing mojomFile. | 137 // set in |mojomFile| which is necessary for ser
ializing mojomFile. |
| 138 filesToProcess = append(filesToProcess, | 138 filesToProcess = append(filesToProcess, |
| 139 » » » » » &FileReference{importedFrom: currentFile
, specifiedPath: importedFile}) | 139 » » » » » &FileReference{importedFrom: currentFile
, specifiedPath: importedFile.SpecifiedName}) |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 // Perform type and value resolution | 144 // Perform type and value resolution |
| 145 if err = descriptor.Resolve(); err != nil { | 145 if err = descriptor.Resolve(); err != nil { |
| 146 return | 146 return |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Compute data for generators. | 149 // Compute data for generators. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 return fmt.Errorf("File not found: %s", fileRef) | 269 return fmt.Errorf("File not found: %s", fileRef) |
| 270 } | 270 } |
| 271 | 271 |
| 272 func isFile(path string) bool { | 272 func isFile(path string) bool { |
| 273 info, err := os.Stat(path) | 273 info, err := os.Stat(path) |
| 274 if err != nil { | 274 if err != nil { |
| 275 return false | 275 return false |
| 276 } | 276 } |
| 277 return !info.IsDir() | 277 return !info.IsDir() |
| 278 } | 278 } |
| OLD | NEW |