Example #1
0
func CreatePropertyBlob(content string) *PropertyBlob {
	props := ordered_map.NewOrderedMap()
	parsingMessage := false
	lines := strings.Split(content, lineSeparator)
	count := len(lines)
	var message bytes.Buffer
	for index, line := range lines {
		if len(line) == 0 {
			if parsingMessage {
				message.WriteString(lineSeparator)
			} else {
				parsingMessage = true
			}
		} else if parsingMessage {
			message.WriteString(line)
			if index < count-1 {
				message.WriteString(lineSeparator)
			}
		} else {
			property := strings.SplitN(line, itemSeparator, 2)
			if len(property) == 2 {
				name := property[0]
				value := property[1]
				props.Set(name, value)
			}
		}
	}
	return &PropertyBlob{props, message.String()}
}
Example #2
0
// GenerateES5 produces ES5 code from the given scope graph.
func GenerateES5(sg *scopegraph.ScopeGraph, generatedFilePath string, sourceRoot string) (string, *sourcemap.SourceMap, error) {
	generated := generateModules(sg)

	// Order the modules by their paths.
	pather := shared.NewPather(sg.SourceGraph().Graph)
	modulePathMap := map[string]esbuilder.SourceBuilder{}

	var modulePathList = make([]string, 0)
	for module, _ := range generated {
		path := pather.GetModulePath(module)
		modulePathList = append(modulePathList, path)
		modulePathMap[path] = generated[module]
	}

	sort.Strings(modulePathList)

	// Collect the generated modules into their final source.
	ordered := ordered_map.NewOrderedMap()
	for _, modulePath := range modulePathList {
		ordered.Set(modulePath, modulePathMap[modulePath])
	}

	// Generate the unformatted code and source map.
	template := esbuilder.Template("es5", runtimeTemplate, ordered)

	sm := sourcemap.NewSourceMap(generatedFilePath, sourceRoot)
	unformatted := esbuilder.BuildSourceAndMap(template, sm)

	// Format the code.
	return escommon.FormatMappedECMASource(unformatted.String(), sm)
}
Example #3
0
func GetAndSetExample() {
	// Init new OrderedMap
	om := ordered_map.NewOrderedMap()

	// Set key
	om.Set("a", 1)
	om.Set("b", 2)
	om.Set("c", 3)
	om.Set("d", 4)

	// Same interface as builtin map
	if val, ok := om.Get("b"); ok == true {
		// Found key "b"
		fmt.Println(val)
	}

	// Delete a key
	om.Delete("c")

	// Failed Get lookup becase we deleted "c"
	if _, ok := om.Get("c"); ok == false {
		// Did not find key "c"
		fmt.Println("c not found")
	}
}
Example #4
0
// generateTypes generates all the types under the  given modules into ES5.
func (gen *es5generator) generateTypes(module typegraph.TGModule) *ordered_map.OrderedMap {
	typeMap := ordered_map.NewOrderedMap()
	types := module.Types()
	for _, typedecl := range types {
		typeMap.Set(typedecl, gen.generateType(typedecl))
	}

	return typeMap
}
Example #5
0
func CustomStruct() {
	om := ordered_map.NewOrderedMap()
	om.Set("one", &MyStruct{1, 1.1})
	om.Set("two", &MyStruct{2, 2.2})
	om.Set("three", &MyStruct{3, 3.3})

	fmt.Println(om)
	// Ouput: OrderedMap[one:&{1 1.1},  two:&{2 2.2},  three:&{3 3.3}, ]

}
func TestSerialize(t *testing.T) {
	message := "I have a few questions.\nHow do we plan on handling the latter case?\n\nWhere can I get some chili dogs?"
	propertyMap := ordered_map.NewOrderedMap()
	propertyMap.Set("author", "Elira <*****@*****.**>")
	propertyMap.Set("file", "src/example.txt")
	blob := &PropertyBlob{
		propertyMap,
		message,
	}
	props := "author Elira <*****@*****.**>\nfile src/example.txt\n\n"
	content := strings.Join([]string{props, message}, "")
	assert.Equal(t, content, blob.Serialize())
}
Example #7
0
func IteratorExample() {
	n := 100
	om := ordered_map.NewOrderedMap()

	for i := 0; i < n; i++ {
		// Insert data into OrdereMap
		om.Set(i, fmt.Sprintf("%d", i*i))
	}

	// Iterate though values
	// - Values iteration are in insert order
	// - Returned in a key/value pair struct
	for kv := range om.Iter() {
		fmt.Println(kv, kv.Key, kv.Value)
	}
}
Example #8
0
func checkInitializationCycles(builder *scopeBuilder) {
	var iwg sync.WaitGroup
	iit := builder.sg.srg.EntrypointVariables()
	for iit.Next() {
		iwg.Add(1)
		go (func(node compilergraph.GraphNode) {
			// For each static dependency, collect the tranisitive closure of the dependencies
			// and ensure a cycle doesn't exist that circles back to this variable/field.
			built := builder.getScopeForRootNode(node)
			for _, staticDep := range built.GetStaticDependencies() {
				builder.checkStaticDependencyCycle(node, staticDep, ordered_map.NewOrderedMap(), []typegraph.TGMember{})
			}

			iwg.Done()
		})(iit.Node())
	}

	iwg.Wait()
	builder.saveScopes()
}
Example #9
0
// generateImplementedMembers generates all the members under the given type or module into ES5.
func (gen *es5generator) generateImplementedMembers(typeOrModule typegraph.TGTypeOrModule) *ordered_map.OrderedMap {
	memberMap := ordered_map.NewOrderedMap()
	members := typeOrModule.Members()
	for _, member := range members {
		// Check for a base member. If one exists, generate the member has an aliased member.
		_, hasBaseMember := member.BaseMember()
		if hasBaseMember {
			memberMap.Set(member, gen.generateImplementedAliasedMember(member))
			continue
		}

		// Otherwise, generate the member if it has an implementation.
		srgMember, hasSRGMember := gen.getSRGMember(member)
		if !hasSRGMember || !srgMember.HasImplementation() {
			continue
		}

		memberMap.Set(member, gen.generateImplementedMember(member))
	}

	return memberMap
}
Example #10
0
// GenerateVariables generates the source for all the variables defined under the module.
func (gm generatingModule) GenerateVariables() *ordered_map.OrderedMap {
	orderedMap := ordered_map.NewOrderedMap()
	gm.Generator.generateVariables(gm.Module, orderedMap)
	return orderedMap
}
Example #11
0
func NewPropertyBlob() *PropertyBlob {
	props := ordered_map.NewOrderedMap()
	return &PropertyBlob{props, ""}
}
Example #12
0
func newGeneratedInitMap() *generatedInitMap {
	return &generatedInitMap{
		promising:  false,
		orderedMap: ordered_map.NewOrderedMap(),
	}
}