本文整理汇总了Golang中mojom/mojom_parser/generated/mojom_files.MojomFileGraph类的典型用法代码示例。如果您正苦于以下问题:Golang MojomFileGraph类的具体用法?Golang MojomFileGraph怎么用?Golang MojomFileGraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MojomFileGraph类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
inputBytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("failed to read: %v", err)
}
decoder := bindings.NewDecoder(inputBytes, nil)
fileGraph := mojom_files.MojomFileGraph{}
if err := fileGraph.Decode(decoder); err != nil {
log.Fatalf("Failed to decode file graph: %v", err)
}
for fileKey := range fileGraph.Files {
printFile(fileGraph, fileKey)
}
}
示例2: translateDescriptor
// translateDescriptor translates from a mojom.MojomDescriptor (the pure Go
// representation used by the parser) to a mojom_files.MojomFileGraph (the
// Mojo Go representation used for serialization.)
func translateDescriptor(d *mojom.MojomDescriptor) *mojom_files.MojomFileGraph {
fileGraph := mojom_files.MojomFileGraph{}
// Add |files| field.
fileGraph.Files = make(map[string]mojom_files.MojomFile)
for name, file := range d.MojomFilesByName {
fileGraph.Files[name] = translateMojomFile(file)
}
// Add |resolved_types| field.
fileGraph.ResolvedTypes = make(map[string]mojom_types.UserDefinedType)
for key, userDefinedType := range d.TypesByKey {
fileGraph.ResolvedTypes[key] = translateUserDefinedType(userDefinedType)
}
// Add |resolved_values| field.
fileGraph.ResolvedValues = make(map[string]mojom_types.UserDefinedValue)
for key, userDefinedValue := range d.ValuesByKey {
fileGraph.ResolvedValues[key] = translateUserDefinedValue(userDefinedValue)
}
return &fileGraph
}
示例3: TestTwoFileSerialization
//.........这里部分代码省略.........
};`
contentsB := `
module a.b.c;
struct FooB{
};`
importingName := "myLittleFriend" // File A is importing File B using this name.
topLevel := false // Simulate the File B is not a top-level file.
test.addTestCase("a.b.c", contentsA, contentsB, topLevel, importingName)
// DeclaredMojomObjects
test.expectedFileA().DeclaredMojomObjects.Structs = &[]string{"TYPE_KEY:a.b.c.FooA"}
test.expectedFileB().DeclaredMojomObjects.Structs = &[]string{"TYPE_KEY:a.b.c.FooB"}
// struct FooA
test.expectedGraph().ResolvedTypes["TYPE_KEY:a.b.c.FooA"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
DeclData: newDeclData(test.expectedFileA().FileName, "FooA", "a.b.c.FooA"),
Fields: []mojom_types.StructField{}}}
// struct FooB
test.expectedGraph().ResolvedTypes["TYPE_KEY:a.b.c.FooB"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
DeclData: newDeclData(test.expectedFileB().FileName, "FooB", "a.b.c.FooB"),
Fields: []mojom_types.StructField{}}}
test.endTestCase()
}
////////////////////////////////////////////////////////////
// Execute all of the test cases.
////////////////////////////////////////////////////////////
for i, c := range test.cases {
descriptor := mojom.NewMojomDescriptor()
// Parse file A.
parserA := parser.MakeParser(c.expectedFileA.FileName, *c.expectedFileA.SpecifiedFileName, c.mojomContentsA, descriptor, nil)
parserA.Parse()
if !parserA.OK() {
t.Errorf("Parsing error for %s: %s", c.expectedFileA.FileName, parserA.GetError().Error())
continue
}
mojomFileA := parserA.GetMojomFile()
// Parse file B.
var importedFrom *mojom.MojomFile
if !c.topLevel {
// If file B is not a top-level file then when the parser for it is constructed we give it a non-nil |importedFrom|.
importedFrom = mojomFileA
}
parserB := parser.MakeParser(c.expectedFileB.FileName, *c.expectedFileB.SpecifiedFileName, c.mojomContentsB, descriptor, importedFrom)
parserB.Parse()
if !parserB.OK() {
t.Errorf("Parsing error for %s: %s", c.expectedFileB.FileName, parserB.GetError().Error())
continue
}
mojomFileB := parserB.GetMojomFile()
// Set the canonical file name for the imported files. In real operation
// this step is done in parser_driver.go when each of the imported files are parsed.
if c.importingName != "" {
// The call to SetCanonicalImportName does a lookup in a map for a key corresponding to the
// first argument. Thus here we are also testing that |importingName| is in fact string
// that was parsed from the .mojom file.
mojomFileA.SetCanonicalImportName(c.importingName, mojomFileB.CanonicalFileName)
}
// Resolve
if err := descriptor.Resolve(); err != nil {
t.Errorf("Resolve error for case %d: %s", i, err.Error())
continue
}
if err := descriptor.ComputeEnumValueIntegers(); err != nil {
t.Errorf("ComputeEnumValueIntegers error for case %d: %s", i, err.Error())
continue
}
if err := descriptor.ComputeDataForGenerators(); err != nil {
t.Errorf("ComputeDataForGenerators error for case %d: %s", i, err.Error())
continue
}
// Serialize
EmitLineAndColumnNumbers = c.lineAndcolumnNumbers
bytes, _, err := Serialize(descriptor, false)
if err != nil {
t.Errorf("Serialization error for case %d: %s", i, err.Error())
continue
}
// Deserialize
decoder := bindings.NewDecoder(bytes, nil)
fileGraph := mojom_files.MojomFileGraph{}
fileGraph.Decode(decoder)
// Compare
if err := compareFileGraphs(c.expectedGraph, &fileGraph); err != nil {
t.Errorf("case %d:\n%s", i, err.Error())
continue
}
}
}
示例4: TestSingleFileSerialization
//.........这里部分代码省略.........
DeclaredOrdinal: -1,
DeclarationOrder: -1,
SourceFileInfo: &mojom_types.SourceFileInfo{
FileName: test.fileName(),
},
ContainedDeclarations: &mojom_types.ContainedDeclarations{
Enums: &[]string{"TYPE_KEY:mojom.test.Foo.Hats"}},
},
Fields: []mojom_types.StructField{
// field x
{
DeclData: test.newShortDeclData("x"),
Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_InT32},
},
// field y
{
DeclData: test.newShortDeclDataA("y", &[]mojom_types.Attribute{{"min_version", &mojom_types.LiteralValueInt8Value{2}}}),
Type: &mojom_types.TypeStringType{mojom_types.StringType{false}},
DefaultValue: &mojom_types.DefaultFieldValueValue{&mojom_types.ValueLiteralValue{&mojom_types.LiteralValueStringValue{"hello"}}},
},
// field z
{
DeclData: test.newShortDeclData("z"),
Type: &mojom_types.TypeStringType{mojom_types.StringType{true}},
},
},
}}
// enum Hats
test.expectedGraph().ResolvedTypes["TYPE_KEY:mojom.test.Foo.Hats"] = &mojom_types.UserDefinedTypeEnumType{mojom_types.MojomEnum{
DeclData: test.newContainedDeclData("Hats", "mojom.test.Foo.Hats", stringPointer("TYPE_KEY:mojom.test.Foo")),
Values: []mojom_types.EnumValue{
// Note(rudominer) It is a bug that we need to copy the enum values here.
// See https://github.com/domokit/mojo/issues/513.
// value TOP
test.expectedGraph().ResolvedValues["TYPE_KEY:mojom.test.Foo.Hats.TOP"].(*mojom_types.UserDefinedValueEnumValue).Value,
// value COWBOY
test.expectedGraph().ResolvedValues["TYPE_KEY:mojom.test.Foo.Hats.COWBOY"].(*mojom_types.UserDefinedValueEnumValue).Value,
// value HARD
test.expectedGraph().ResolvedValues["TYPE_KEY:mojom.test.Foo.Hats.HARD"].(*mojom_types.UserDefinedValueEnumValue).Value,
},
}}
test.endTestCase()
}
////////////////////////////////////////////////////////////
// Execute all of the test cases.
////////////////////////////////////////////////////////////
for _, c := range test.cases {
// Parse and resolve the mojom input.
descriptor := mojom.NewMojomDescriptor()
parser := parser.MakeParser(c.fileName, c.fileName, c.mojomContents, descriptor, nil)
parser.Parse()
if !parser.OK() {
t.Errorf("Parsing error for %s: %s", c.fileName, parser.GetError().Error())
continue
}
if err := descriptor.Resolve(); err != nil {
t.Errorf("Resolve error for %s: %s", c.fileName, err.Error())
continue
}
if err := descriptor.ComputeEnumValueIntegers(); err != nil {
t.Errorf("ComputeEnumValueIntegers error for %s: %s", c.fileName, err.Error())
continue
}
if err := descriptor.ComputeDataForGenerators(); err != nil {
t.Errorf("ComputeDataForGenerators error for %s: %s", c.fileName, err.Error())
continue
}
// Simulate setting the canonical file name for the imported files. In real operation
// this step is done in parser_driver.go when each of the imported files are parsed.
mojomFile := parser.GetMojomFile()
if mojomFile.Imports != nil {
for _, imp := range mojomFile.Imports {
imp.CanonicalFileName = fmt.Sprintf("%s.canonical", imp.SpecifiedName)
}
}
// Serialize
EmitLineAndColumnNumbers = c.lineAndcolumnNumbers
bytes, _, err := Serialize(descriptor, false)
if err != nil {
t.Errorf("Serialization error for %s: %s", c.fileName, err.Error())
continue
}
// Deserialize
decoder := bindings.NewDecoder(bytes, nil)
fileGraph := mojom_files.MojomFileGraph{}
fileGraph.Decode(decoder)
// Compare
if err := compareFileGraphs(c.expectedGraph, &fileGraph); err != nil {
t.Errorf("%s:\n%s", c.fileName, err.Error())
continue
}
}
}
示例5: TestSingleFileSerialization
//.........这里部分代码省略.........
ShortName: stringPointer("Foo"),
FullIdentifier: stringPointer("mojom.test.Foo"),
DeclaredOrdinal: -1,
DeclarationOrder: -1,
SourceFileInfo: &mojom_types.SourceFileInfo{
FileName: test.fileName(),
},
ContainedDeclarations: &mojom_types.ContainedDeclarations{
Enums: &[]string{"TYPE_KEY:mojom.test.Foo.Hats"}},
},
Fields: []mojom_types.StructField{
// field x
{
DeclData: test.newDeclData("x", ""),
Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_InT32},
},
// field y
{
DeclData: test.newDeclData("y", ""),
Type: &mojom_types.TypeStringType{mojom_types.StringType{false}},
DefaultValue: &mojom_types.DefaultFieldValueValue{&mojom_types.ValueLiteralValue{&mojom_types.LiteralValueStringValue{"hello"}}},
},
// field z
{
DeclData: test.newDeclData("z", ""),
Type: &mojom_types.TypeStringType{mojom_types.StringType{true}},
},
},
}}
// enum Hats
test.expectedGraph().ResolvedTypes["TYPE_KEY:mojom.test.Foo.Hats"] = &mojom_types.UserDefinedTypeEnumType{mojom_types.MojomEnum{
DeclData: test.newDeclData("Hats", "mojom.test.Foo.Hats"),
Values: []mojom_types.EnumValue{
// Note(rudominer) It is a bug that we need to copy the enum values here.
// See https://github.com/domokit/mojo/issues/513.
// value TOP
test.expectedGraph().ResolvedValues["TYPE_KEY:mojom.test.Foo.Hats.TOP"].(*mojom_types.UserDefinedValueEnumValue).Value,
// value COWBOY
test.expectedGraph().ResolvedValues["TYPE_KEY:mojom.test.Foo.Hats.COWBOY"].(*mojom_types.UserDefinedValueEnumValue).Value,
},
}}
test.endTestCase()
}
////////////////////////////////////////////////////////////
// Execute all of the test cases.
////////////////////////////////////////////////////////////
for _, c := range test.cases {
// Parse and resolve the mojom input.
descriptor := mojom.NewMojomDescriptor()
parser := parser.MakeParser(c.fileName, c.mojomContents, descriptor)
parser.Parse()
if !parser.OK() {
t.Errorf("Parsing error for %s: %s", c.fileName, parser.GetError().Error())
continue
}
if err := descriptor.Resolve(); err != nil {
t.Errorf("Resolve error for %s: %s", c.fileName, err.Error())
continue
}
if err := descriptor.ComputeEnumValueIntegers(); err != nil {
t.Errorf("ComputeEnumValueIntegers error for %s: %s", c.fileName, err.Error())
continue
}
if err := descriptor.ComputeDataForGenerators(); err != nil {
t.Errorf("ComputeDataForGenerators error for %s: %s", c.fileName, err.Error())
continue
}
// Simulate setting the canonical file name for the imported files. In real operation
// this step is done in parser_driver.go when each of the imported files are parsed.
mojomFile := parser.GetMojomFile()
if mojomFile.Imports != nil {
for _, imp := range mojomFile.Imports {
imp.CanonicalFileName = fmt.Sprintf("%s.canonical", imp.SpecifiedName)
}
}
// Serialize
EmitLineAndColumnNumbers = c.lineAndcolumnNumbers
bytes, err := Serialize(descriptor)
if err != nil {
t.Errorf("Serialization error for %s: %s", c.fileName, err.Error())
continue
}
// Deserialize
decoder := bindings.NewDecoder(bytes, nil)
fileGraph := mojom_files.MojomFileGraph{}
fileGraph.Decode(decoder)
// Compare
if err := compareFileGraphs(c.expectedGraph, &fileGraph); err != nil {
t.Errorf("%s:\n%s", c.fileName, err.Error())
continue
}
}
}
示例6: translateDescriptor
func translateDescriptor(d *MojomDescriptor) *mojom_files.MojomFileGraph {
fileGraph := mojom_files.MojomFileGraph{}
fileGraph.Files = make(map[string]mojom_files.MojomFile)
fileGraph.Files["test"] = mojom_files.MojomFile{}
return &fileGraph
}