Beispiel #1
0
func WrapIfPromising(childExpression Expression, member typegraph.TGMember, basis compilergraph.GraphNode) Expression {
	if member.IsPromising() {
		return AwaitPromise(childExpression, basis)
	}

	return childExpression
}
Beispiel #2
0
// getSRGMember returns the SRG member type for the given type graph member, if any.
func (gen *es5generator) getSRGMember(member typegraph.TGMember) (srg.SRGMember, bool) {
	sourceNodeId, hasSource := member.SourceNodeId()
	if !hasSource {
		return srg.SRGMember{}, false
	}

	sourcegraph := gen.scopegraph.SourceGraph()
	srgNode, hasSRGNode := sourcegraph.TryGetNode(sourceNodeId)
	if !hasSRGNode {
		return srg.SRGMember{}, false
	}

	return sourcegraph.GetMemberReference(srgNode), true
}
Beispiel #3
0
// generateVariable generates the given variable into ES5.
func (gen *es5generator) generateVariable(member typegraph.TGMember) generatedSourceResult {
	srgMember, _ := gen.getSRGMember(member)
	initializer, _ := srgMember.Initializer()
	initResult := statemachine.GenerateExpressionResult(initializer, gen.scopegraph, gen.positionMapper)

	prefix := "instance"
	if member.IsStatic() {
		prefix = "$static"
	}

	data := struct {
		Name        string
		Prefix      string
		Initializer expressiongenerator.ExpressionResult
	}{member.Name(), prefix, initResult}

	source := esbuilder.Template("variable", variableTemplateStr, data)
	return generatedSourceResult{source, initResult.IsPromise()}
}
Beispiel #4
0
// recursivelyCollectInitDependencies recursively collects the initialization dependency fields for the
// field member, placing them in the deps map.
func (gm generatingModule) recursivelyCollectInitDependencies(current typegraph.TGMember, field typegraph.TGMember, deps map[typegraph.TGMember]bool) {
	if _, found := deps[current]; found {
		return
	}

	if field.NodeId != current.NodeId && current.IsField() {
		deps[current] = true
	} else {
		srgMember, hasSRGMember := gm.Generator.getSRGMember(current)
		if !hasSRGMember {
			return
		}

		scope, _ := gm.Generator.scopegraph.GetScope(srgMember.GraphNode)
		for _, staticDep := range scope.GetStaticDependencies() {
			memberNodeId := compilergraph.GraphNodeId(staticDep.GetReferencedNode())
			member := gm.Generator.scopegraph.TypeGraph().GetTypeOrMember(memberNodeId)
			gm.recursivelyCollectInitDependencies(member.(typegraph.TGMember), field, deps)
		}
	}
}
Beispiel #5
0
// GetStaticMemberPath returns the global path for the given statically defined type member.
func (p Pather) GetStaticMemberPath(member typegraph.TGMember, referenceType typegraph.TypeReference) string {
	// TODO(jschorr): We should generalize non-SRG support.
	if member.Name() == "new" && !member.IsPromising() {
		parentType, _ := member.ParentType()
		if strings.HasSuffix(parentType.ParentModule().Path(), ".webidl") {
			return "$t.nativenew(" + p.GetTypePath(parentType) + ")"
		}
	}

	name := p.GetMemberName(member)
	parent := member.Parent()
	if parent.IsType() {
		return p.GetStaticTypePath(parent.(typegraph.TGTypeDecl), referenceType) + "." + name
	} else {
		return p.GetModulePath(parent.(typegraph.TGModule)) + "." + name
	}
}
Beispiel #6
0
// computeMemberSignature computes a type signature for the given type member.
// Note that the signature format (except for type references) is internal to
// this method and can be changed at any time.
func computeMemberSignature(member typegraph.TGMember) memberSignature {
	kind := member.Signature().MemberKind

	// Signature form: "MemberName|MemberTypeInt|MemberTypeReference"
	var buf bytes.Buffer
	buf.WriteRune('"')
	buf.WriteString(member.Name())
	buf.WriteRune('|')
	buf.WriteString(strconv.Itoa(int(*kind)))
	buf.WriteRune('|')

	dynamic := appendSigReference(member.MemberType(), &buf)

	buf.WriteRune('"')
	return memberSignature{buf.String(), dynamic}
}
Beispiel #7
0
// GetMemberName returns the name of the given member.
func (p Pather) GetMemberName(member typegraph.TGMember) string {
	return strings.Replace(unidecode.Unidecode(member.ChildName()), "*", "$", 1)
}