Exemplo n.º 1
0
func AssignToScopedArrayIndex(arrayName string, indexNo int, value Value, lineno int) {

	if _, in1 := Scope[arrayName]; !in1 {
		if _, in2 := GlobalScope[arrayName]; !in2 {
			log.UndeclaredVariable(lineno, arrayName)
			return
		} else {
			gArray := GetVariable(arrayName, lineno)
			if gArray.Type != VALUE_ARRAY {
				log.TypeViolation(lineno)
				return
			}
			if value.Type == VALUE_OBJECT || value.Type == VALUE_ARRAY {
				log.TypeViolation(lineno)
				return
			}
			gArray.Value.(map[string]Value)[strconv.Itoa(indexNo)] =
				Value{Type: value.Type, Value: value.Value, Line: value.Line, Written: true}
		}
	} else {
		lArray := GetVariable(arrayName, lineno)
		if lArray.Type != VALUE_ARRAY {
			log.TypeViolation(lineno)
			return
		}
		if value.Type == VALUE_ARRAY || value.Type == VALUE_OBJECT {
			log.TypeViolation(lineno)
			return
		}
		lArray.Value.(map[string]Value)[strconv.Itoa(indexNo)] =
			Value{Type: value.Type, Value: value.Value, Line: value.Line, Written: true}
	}
}
Exemplo n.º 2
0
func AssignToGlobalVariable(name string, value Value, lineno int) {
	log.Tracef("sym", "Assigning value %s to global variable %s", value.ToString(), name)
	if _, in := GlobalScope[name]; !in {
		log.UndeclaredVariable(lineno, name)
	}
	GlobalScope[name] = Value{Type: value.Type, Value: value.Value, Line: value.Line, Written: true}
}
Exemplo n.º 3
0
func AssignToScopedObjectKey(objectName string, keyName string, value Value, lineno int) {
	if _, in1 := Scope[objectName]; !in1 {
		if _, in2 := GlobalScope[objectName]; !in2 {
			// Not in either local or global
			log.UndeclaredVariable(lineno, objectName)
			return
		} else {
			// In global
			gObject := GetVariable(objectName, lineno)
			if gObject.Type != VALUE_OBJECT {
				log.TypeViolation(lineno)
				return
			}
			if value.Type == VALUE_OBJECT || value.Type == VALUE_ARRAY {
				log.TypeViolation(lineno)
				return
			}
			gObject.Value.(map[string]Value)[keyName] =
				Value{Type: value.Type, Value: value.Value, Line: value.Line, Written: true}
		}
	} else {
		lObject := GetVariable(objectName, lineno)
		if lObject.Type != VALUE_OBJECT {
			log.TypeViolation(lineno)
			return
		}
		if value.Type == VALUE_OBJECT || value.Type == VALUE_ARRAY {
			log.TypeViolation(lineno)
			return
		}
		lObject.Value.(map[string]Value)[keyName] =
			Value{Type: value.Type, Value: value.Value, Line: value.Line, Written: true}
	}
}
Exemplo n.º 4
0
func AssignToScopedVariable(name string, value Value, lineno int) {
	log.Tracef("sym", "Assigning value %s to scope-local variable %s", value.ToString(), name)
	if _, in1 := Scope[name]; !in1 {
		if _, in2 := GlobalScope[name]; !in2 {
			log.UndeclaredVariable(lineno, name)
			Scope[name] = Value{Type: value.Type, Value: value.Value, Line: value.Line, Written: true}
		} else {
			GlobalScope[name] = Value{Type: value.Type, Value: value.Value, Line: value.Line, Written: true}
		}
	} else {
		Scope[name] = Value{Type: value.Type, Value: value.Value, Line: value.Line, Written: true}
	}
}
Exemplo n.º 5
0
func AssignToGlobalObjectKey(objectName string, keyName string, value Value, lineno int) {
	if _, in := GlobalScope[objectName]; !in {
		log.UndeclaredVariable(lineno, objectName)
	}

	// Get the object from the symbol table
	object := GetVariable(objectName, lineno)
	if object.Type != VALUE_OBJECT {
		log.TypeViolation(lineno)
		return
	}

	// If we are assigning an object or array, fail
	if value.Type == VALUE_OBJECT || value.Type == VALUE_ARRAY {
		log.TypeViolation(lineno)
		return
	}

	object.Value.(map[string]Value)[keyName] =
		Value{Type: value.Type, Value: value.Value, Line: value.Line, Written: true}
}