private Value CreateValueInternal(TypeSymbol type, Symbol associatedSymbol, Value.ValueFlags flags, string name = null) { LazyInitTable(); if ((flags & Value.ValueFlags.Local) != 0 && IsRoot) { throw new InvalidOperationException("Local values cannot be created in the root table."); } Value newVal = new Value(this, GetUniqueValueName(type, flags, name), type, flags); _values.Add(newVal); return(newVal); }
private string GetUniqueValueName(TypeSymbol type, Value.ValueFlags flags, string symbolName) { string uniqueName; symbolName = UdonSharpUtils.UnmanglePropertyFieldName(symbolName); if ((flags & Value.ValueFlags.Field) != 0 || (flags & Value.ValueFlags.Parameter) != 0 || (flags & Value.ValueFlags.Reflection) != 0) { uniqueName = symbolName; } else { string namePrefix = ""; switch (flags) { case Value.ValueFlags.Constant: namePrefix = "const_"; break; case Value.ValueFlags.Internal: namePrefix = "intnl_"; break; case Value.ValueFlags.Local: namePrefix = "lcl_"; break; case Value.ValueFlags.Parameter: namePrefix = "param_"; break; case Value.ValueFlags.PropertyBackingField: namePrefix = "prop_"; break; case Value.ValueFlags.UdonThis: namePrefix = "this_"; break; case Value.ValueFlags.InternalGlobal: namePrefix = "gintnl_"; break; } string valueName = $"__{namePrefix}{(symbolName != null ? $"{symbolName}_" : "")}{type.UdonType.ExternSignature}"; if (!_uniqueIDTracker.TryGetValue(valueName, out int counter)) { _uniqueIDTracker.Add(valueName, 0); } uniqueName = $"{valueName}_{counter}"; _uniqueIDTracker[valueName] = counter + 1; } if (_nameCollisionCheckSet.Contains(uniqueName)) { throw new InvalidOperationException("Cannot allocate a symbol with the same name twice"); } _nameCollisionCheckSet.Add(uniqueName); return(uniqueName); }