예제 #1
0
        public string GetValue(Type type, object obj)
        {
            if (!string.IsNullOrWhiteSpace(Attribute?.Format))
            {
                var displayText = Attribute.Format;
                var metas       = DataListHelper.GetDataColumnMeta(type);

                return(FormatPlaceholder.Aggregate(displayText, (current, ph) => current.Replace("{" + ph + "}", metas.First(p => p.Name == ph).GetPlainValue(obj)?.ToString())));
            }

            var value = GetPlainValue(obj)?.ToString();

            if (string.IsNullOrWhiteSpace(value))
            {
                return(value);
            }
            if (ValueMap != null && ValueMap.ContainsKey(value))
            {
                var displayText = ValueMap[value];
                var metas       = DataListHelper.GetDataColumnMeta(type);

                return(ValueMapPlaceholder.Aggregate(displayText, (current, ph) => current.Replace("{" + ph + "}", metas.First(p => p.Name == ph).GetPlainValue(obj)?.ToString())));
            }
            return(value);
        }
예제 #2
0
        public T Get <T>(string Key, T Default = default(T))
        {
            if (!values.ContainsKey(Key))
            {
                return(Default);
            }

            string value = values[Key];

            Type type = typeof(T);

            if (type.IsEnum)
            {
                return((T)Enum.Parse(type, value));
            }

            return((T)Convert.ChangeType(value, type));
        }
예제 #3
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            if (Property != null)
            {
                var propertyName = Property.Key;

                Title = "Edit [" + propertyName + "]";

                txtPropertyName.Text  = propertyName;
                txtPropertyValue.Text = Cluster.Value;

                chkDeprecated.IsChecked     = Property.Deprecated;
                txtPropertyDescription.Text = Property.Description;
            }
            else
            {
                Title = "New Property...";

                txtPropertyName.Text            = "";
                txtPropertyName.BorderThickness = new Thickness(1.0);
                txtPropertyName.IsReadOnly      = false;
            }

            foreach (var dimension in Dimensions)
            {
                if (dimension.Dimension.Name == "Property")
                {
                    continue;
                }

                var control = KeyValueControl.Create(dimension);
                panelDimensions.Children.Add(control);

                if (ValueMap != null && ValueMap.ContainsKey(dimension.Dimension.Name))
                {
                    control.cmbItems.SelectedItem = ValueMap[dimension.Dimension.Name];
                }
            }

            UpdateLayout();

            var height = groupProperties.ActualHeight + groupDimensions.ActualHeight + _windowHeight;

            if (height > ActualHeight)
            {
                Height = height;
            }
        }
예제 #4
0
        public void newObj(int lineNumber, string scope)
        {
            var alSar   = _recordStack.Pop();
            var typeSar = _recordStack.Pop();

            Symbol sym;

            if (_symbolTable.Any(s => s.Value.Kind == "Constructor" && s.Value.Value == typeSar.Value))
            {
                sym = _symbolTable.First(s => s.Value.Kind == "Constructor" && s.Value.Value == typeSar.Value).Value;
            }
            else
            {
                throw new Exception(string.Format("Semantic error at line {0}: No constructor exists for class '{1}')",
                                                  lineNumber, typeSar.Value));
            }

            var constructorScope = "g." + typeSar.Value + "." + typeSar.Value;
            var newSar           = new Record(typeSar)
            {
                ArgumentList = new Stack <Record>(),
                LinkedSymbol = sym,
                Type         = RecordType.New,
                TempVariable = _intercoder.GetTempVarName(typeSar, scope)
            };

            if (alSar.ArgumentList.Count() != sym.Data.Params.Count())
            {
                throw new Exception(
                          string.Format(
                              "Semantic error at line {0}: Constructor '{1}' does not have the correct number of parameters (expected {2})",
                              lineNumber, typeSar.Value, sym.Data.Params.Count()));
            }
            foreach (var a in sym.Data.Params)
            {
                var argRecord = alSar.ArgumentList.Pop();
                var argName   = argRecord.Value;
                var symbol    =
                    (from p in _symbolTable
                     where p.Value.Scope == constructorScope && p.Key == a
                     select p.Value).FirstOrDefault();
                if (symbol == null || symbol.Data.Type != _symbolTable[a].Data.Type)
                {
                    throw new Exception(
                              string.Format(
                                  "Semantic error at line {0}: Constructor for class '{1}' does not have a param '{2}' of type '{3}', expected a value of type '{4}' instead",
                                  lineNumber, typeSar.Value, argName, symbol.Data.Type ?? "null", _symbolTable[a].Data.Type));
                }
                if (argRecord.LinkedSymbol != null && argRecord.LinkedSymbol.Data != null)
                {
                    var v1 = symbol.Data.Type;
                    var v2 = argRecord.LinkedSymbol.Data.Type;
                    if (ValueMap.ContainsKey(v1))
                    {
                        v1 = ValueMap[v1];
                    }
                    if (ValueMap.ContainsKey(v2))
                    {
                        v2 = ValueMap[v2];
                    }
                    if (!v1.Equals(v2))
                    {
                        throw new Exception(
                                  string.Format(
                                      "Semantic error at line {0}: Constructor for class '{1}' does not have a param '{2}' of type '{3}', expected a value of type '{4}' instead",
                                      lineNumber, typeSar.Value, argName, argRecord.LinkedSymbol.Data.Type,
                                      _symbolTable[a].Data.Type));
                    }
                }
                newSar.ArgumentList.Push(argRecord);
            }
            _recordStack.Push(newSar);

            var classSymbol = GetSymbol("g", typeSar);

            if (classSymbol != null)
            {
                typeSar.LinkedSymbol = classSymbol;
            }
            _intercoder.WriteNewObj(newSar, typeSar, scope);

            if (DEBUG)
            {
                Console.WriteLine("   newObj: " + typeSar.Value);
            }
        }
예제 #5
0
        public void func(string scope, int lineNumber) //function
        {
            var argumentList = _recordStack.Pop();
            var functionName = _recordStack.Pop();
            var peekRecord   = (_recordStack.Count > 0) ? _recordStack.Peek() : null;

            var newRecord = new Record(functionName)
            {
                Type         = RecordType.Func,
                ArgumentList = argumentList.ArgumentList
            };


            if (newRecord.LinkedSymbol == null || newRecord.LinkedSymbol.SymId == null ||
                newRecord.LinkedSymbol.SymId.Length == 0)
            {
                var symbol = (from s in _symbolTable
                              where s.Value.Scope == "g." + peekRecord.LinkedSymbol.Data.Type &&
                              s.Value.Value == functionName.Value &&
                              s.Value.Data.AccessMod.Equals("unprotected") &&
                              s.Value.Kind.ToLower().Equals("method")
                              select s.Value).FirstOrDefault();
                newRecord.LinkedSymbol = symbol;
            }
            if (newRecord.LinkedSymbol != null)
            {
                //test arguments
                var oldStack = new List <Record>(argumentList.ArgumentList);
                if (oldStack.Count() != newRecord.LinkedSymbol.Data.Params.Count())
                {
                    throw new Exception(
                              string.Format(
                                  "Semantic error at line {0}: Method '{1}' does not have the correct number of parameters (expected {2})",
                                  lineNumber, newRecord.Value, newRecord.LinkedSymbol.Data.Params.Count()));
                }
                foreach (var a in newRecord.LinkedSymbol.Data.Params)
                {
                    var argRecord = oldStack.First();
                    oldStack.RemoveAt(0);
                    var argName    = argRecord.Value;
                    var psymbol    = _symbolTable[a];
                    var compareStr = argName;
                    if (argRecord.LinkedSymbol != null && argRecord.LinkedSymbol.Data != null)
                    {
                        compareStr = argRecord.LinkedSymbol.Data.Type;
                    }
                    if (_symbolTable.ContainsKey(compareStr))
                    {
                        compareStr = _symbolTable[compareStr].Data.Type;
                    }
                    if (ValueMap.ContainsKey(argName))
                    {
                        compareStr = ValueMap[argName];
                    }
                    if (!psymbol.Data.Type.Equals(compareStr))
                    {
                        if (psymbol != _symbolTable[a])
                        {
                            throw new Exception(
                                      string.Format(
                                          "Semantic error at line {0}: '{1}' does not have a parameter '{2}' of type '{3}', expected a value of type '{4}' instead",
                                          lineNumber, newRecord.Value, argName, psymbol.Data.Type ?? "null",
                                          _symbolTable[a].Data.Type));
                        }
                        else
                        {
                            throw new Exception(
                                      string.Format(
                                          "Semantic error at line {0}: '{1}' does not have a parameter '{2}' of type '{3}', expected a value of type '{4}' instead",
                                          lineNumber, newRecord.Value, argName, compareStr,
                                          _symbolTable[a].Data.Type));
                        }
                    }
                }

                //
            }
            else
            {
                var checkSymbol = (from s in _symbolTable
                                   where s.Value.Scope == "g." + peekRecord.LinkedSymbol.Data.Type &&
                                   s.Value.Value == functionName.Value &&
                                   s.Value.Data.AccessMod.Equals("protected") &&
                                   s.Value.Kind.ToLower().Equals("method")
                                   select s.Value).FirstOrDefault();
                if (checkSymbol != null)
                {
                    throw new Exception(
                              string.Format(
                                  "Semantic error at line {0}: '{1}' is protected and can't be accessed from this scope.",
                                  lineNumber, functionName.Value));
                }
            }

            var scopeStrs = scope.Split('.');

            if (scopeStrs.Count() < 2)
            {
                throw new Exception("Semanter error: Quite ridiculous...");
            }
            var scopeStr = scopeStrs[0] + "." + scopeStrs[1];

            _intercoder.WriteFunctionCall(newRecord, argumentList, peekRecord, functionName, scopeStr, lineNumber);

            _recordStack.Push(newRecord);

            if (DEBUG)
            {
                Console.WriteLine("   Func: " + functionName.Value);
            }
        }