Пример #1
0
        /// <summary>
        /// Store VariableCategory Store VariableCategory
        /// </summary>
        /// <param name="body">VariableCategory that should be stored</param>
        /// <returns>InlineResponse20024</returns>
        public InlineResponse20024 VariableCategoriesPost(VariableCategory body)
        {
            var path = "/variableCategories";

            path = path.Replace("{format}", "json");


            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;



            postBody = ApiClient.Serialize(body); // http body (model) parameter


            // authentication setting, if any
            String[] authSettings = new String[] {  };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling VariableCategoriesPost: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling VariableCategoriesPost: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((InlineResponse20024)ApiClient.Deserialize(response.Content, typeof(InlineResponse20024), response.Headers));
        }
        /// <summary>
        /// Compiles a call to a subroutine.  The current token should be the subroutine name if a one token name; otherwise, it should be the class or object name that preceeds the '.' operator.
        /// </summary>
        private void CompileSubroutineCall()
        {
            string subObject = tokenizer.TokenValue;
            string subroutineName;
            int    numArgs      = 0;
            int    thisVarIndex = -1;



            if (tokenizer.PeakAhead().Value == ".")
            {
                CheckTokenSequence(out validatedTokens, ".", "?identifier");
                // if the object has a symbol table entry, it's an instance and requires its index to pass the "this" variable.  If not listed, it's a class and the index will remain -1.
                thisVarIndex   = symbolTable.IndexOf(subObject);
                subroutineName = (thisVarIndex == -1) ? subObject + "." + tokenizer.TokenValue : symbolTable.TypeOf(subObject) + "." + tokenizer.TokenValue;
            }
            else   // subroutines called without a prefix in Jack are always methods of the current class, so we need to add in the class name and THIS pointer.
            {
                subroutineName = emitter.GetCurrentClassName() + "." + subObject;
                thisVarIndex   = 0;
            }

            if (tokenizer.PeakAhead().Value == "(")
            {
                CheckTokenSequence(out validatedTokens, "(");

                // if this is a method being called from an instance, we need to push the "this" argument and take it into account for the number of arguments
                if (thisVarIndex != -1)
                {
                    numArgs = 1;
                    VariableCategory objType = symbolTable.KindOf(subObject);
                    if (objType != VariableCategory.NONE)
                    {
                        emitter.emitTerm(emitter.GetVarSegment(objType), thisVarIndex);
                    }
                    else
                    {
                        emitter.emitTerm(VMWriter.Segment.POINTER, 0);
                    }
                }

                numArgs += CompileExpressionList();
                CheckTokenSequence(out validatedTokens, ")");
                emitter.emitSubroutineCall(subroutineName, numArgs);
            }
        }
Пример #3
0
        /// <summary>
        /// Update VariableCategory Update VariableCategory
        /// </summary>
        /// <param name="id">id of VariableCategory</param>
        /// <param name="body">VariableCategory that should be updated</param>
        /// <returns>InlineResponse2002</returns>
        public InlineResponse2002 VariableCategoriesIdPut(int?id, VariableCategory body)
        {
            // verify the required parameter 'id' is set
            if (id == null)
            {
                throw new ApiException(400, "Missing required parameter 'id' when calling VariableCategoriesIdPut");
            }


            var path = "/variableCategories/{id}";

            path = path.Replace("{format}", "json");
            path = path.Replace("{" + "id" + "}", ApiClient.ParameterToString(id));


            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;



            postBody = ApiClient.Serialize(body); // http body (model) parameter


            // authentication setting, if any
            String[] authSettings = new String[] {  };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling VariableCategoriesIdPut: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling VariableCategoriesIdPut: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((InlineResponse2002)ApiClient.Deserialize(response.Content, typeof(InlineResponse2002), response.Headers));
        }
Пример #4
0
        /// <summary>
        /// Gets the proper memory segment for a given variable category from the symbol table. Returns "temp" for invalid variables, because that does the least damage.
        /// </summary>
        public VMWriter.Segment GetVarSegment(VariableCategory varCat)
        {
            switch (varCat)
            {
            case VariableCategory.ARG:
                return(VMWriter.Segment.ARG);

            case VariableCategory.FIELD:
                return(VMWriter.Segment.THIS);

            case VariableCategory.STATIC:
                return(VMWriter.Segment.STATIC);

            case VariableCategory.VAR:
                return(VMWriter.Segment.LOCAL);

            default:
                return(VMWriter.Segment.TEMP);
            }
        }
        public int VarCount(VariableCategory kind)
        {
            switch (kind)
            {
            case VariableCategory.ARG:
                return(argIndex);

            case VariableCategory.FIELD:
                return(fieldIndex);

            case VariableCategory.STATIC:
                return(staticIndex);

            case VariableCategory.VAR:
                return(varIndex);

            default:
                return(0);
            }
        }
        public void Define(string name, string type, VariableCategory kind)
        {
            switch (kind)
            {
            case VariableCategory.ARG:
                subroutineScope.Add(name, new SymbolTableEntry(type, kind, argIndex++));
                break;

            case VariableCategory.FIELD:
                classScope.Add(name, new SymbolTableEntry(type, kind, fieldIndex++));
                break;

            case VariableCategory.STATIC:
                classScope.Add(name, new SymbolTableEntry(type, kind, staticIndex++));
                break;

            case VariableCategory.VAR:
                subroutineScope.Add(name, new SymbolTableEntry(type, kind, varIndex++));
                break;
            }
        }
Пример #7
0
 /// <summary>
 /// Map VariableCategory to VariableCategoryViewModel model
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public VariableCategoryViewModel ToModel(VariableCategory model)
 {
     return(new VariableCategoryViewModel()
     {
         Id = model.Id,
         CategoryName = model.CategoryName,
         CreatedDate = model.CreatedDate,
         ModifiedDate = model.ModifiedDate,
         DeactivatedDate = model.DateDeactivated,
         Guid = model.Guid,
         Variables = model.Variables.Where(v => v.DateDeactivated == null).Select(c => new SubCategoryViewModel
         {
             Guid = c.Guid,
             Id = c.Id,
             Name = c.VariableName,
             Status = string.Empty,
             Type = c.VariableType.Type,
             IsApproved = c.IsApproved,
             IsDefaultVariable = c.IsDefaultVariable,
         }).OrderBy(x => x.IsDefaultVariable).ThenBy(x => x.Name).ToList(),
         IsDefaultVariableCategory = model.IsDefaultVariableCategory,
     });
 }
        private void CompileClassVarDec()
        {
            if (CheckTokenSequence(out validatedTokens, "%static field", "%type", "?identifier", "%; ,"))
            {
                // define a new symbol table entry using the validated token name, type, and static or field status
                string           varType = validatedTokens[1].Value;
                VariableCategory varKind = (validatedTokens[0].Value == "static") ? VariableCategory.STATIC : VariableCategory.FIELD;
                symbolTable.Define(validatedTokens[2].Value, varType, varKind);
                if (tokenizer.CurrentToken.Value != ";")
                {
                    List <JackToken> valTokenList = new List <JackToken>(validatedTokens);
                    while (tokenizer.CurrentToken.Value == ",")
                    {
                        if (CheckTokenSequence(out validatedTokens, "?identifier", "%; ,"))
                        {
                            symbolTable.Define(validatedTokens[0].Value, varType, varKind);

                            valTokenList.AddRange(validatedTokens);
                        }
                    }
                }
            }
        }
 public SymbolTableEntry(string type, VariableCategory kind, int index)
 {
     this.type  = type;
     this.kind  = kind;
     this.index = index;
 }
Пример #10
0
        /// <summary>
        /// Adds one row for each variable of the specified <see cref="EntityClass"/>.</summary>
        /// <param name="entityClass">
        /// The <see cref="EntityClass"/> whose variables to show.</param>
        /// <param name="category">
        /// The <see cref="VariableCategory"/> whose variables to show.</param>
        /// <param name="showBuildResources">
        /// <c>true</c> to show <see cref="EntityClass.BuildResources"/>, <c>false</c> to show <see
        /// cref="EntityClass.Resources"/>. This argument is ignored if <paramref name="category"/>
        /// does not equal <see cref="VariableCategory.Resource"/>.</param>
        /// <exception cref="InvalidEnumArgumentException">
        /// <paramref name="category"/> is neither <see cref="VariableCategory.Attribute"/> nor <see
        /// cref="VariableCategory.Resource"/>.</exception>
        /// <remarks>
        /// <b>CreateVariableRows</b> adds one row for each initial value and modifier value defined
        /// by the specified <paramref name="entityClass"/>. The <see cref="PropertyListItem.Tag"/>
        /// of each row holds the corresponding <see cref="VariableClass"/>.</remarks>

        private void CreateVariableRows(EntityClass entityClass,
                                        VariableCategory category, bool showBuildResources)
        {
            string categoryLabel = "";
            VariableClassDictionary    variables = null;
            VariableValueDictionary    basics    = null;
            VariableModifierDictionary modifiers = null;

            // retrieve name and variable collections for category
            if (category == VariableCategory.Attribute)
            {
                categoryLabel = Global.Strings.LabelAttribute;
                variables     = MasterSection.Instance.Variables.Attributes;
                basics        = entityClass.Attributes;
                modifiers     = entityClass.AttributeModifiers;
            }
            else if (category == VariableCategory.Resource)
            {
                variables = MasterSection.Instance.Variables.Resources;

                if (showBuildResources)
                {
                    categoryLabel = Global.Strings.LabelBuildCost;
                    basics        = entityClass.BuildResources;
                }
                else
                {
                    categoryLabel = Global.Strings.LabelResource;
                    basics        = entityClass.Resources;
                    modifiers     = entityClass.ResourceModifiers;
                }
            }
            else
            {
                ThrowHelper.ThrowInvalidEnumArgumentException(
                    "category", (int)category, typeof(VariableCategory));
            }

            // insert separator before first property?
            bool addSeparator = (Items.Count > 0);

            // add variable row, preceded by separator if required
            Action <VariableClass, String> addRow = (variable, value) => {
                if (addSeparator)
                {
                    ApplicationUtility.AddSeparator(this);
                    addSeparator = false;
                }

                Items.Add(new PropertyListItem(categoryLabel, variable.Name, value, variable));
            };

            // process all variables defined by the scenario
            foreach (var pair in variables)
            {
                string id = pair.Key;
                string basicValue = null, modSelf = null;

                // get basic value if defined
                if (basics.ContainsKey(id))
                {
                    basicValue = pair.Value.Format(basics[id], false);
                }

                // get set of modifiers and self-modifier value
                VariableModifier modifier = null;
                if (modifiers != null && modifiers.TryGetValue(id, out modifier) && modifier.Self != null)
                {
                    modSelf = pair.Value.Format(modifier.Self.Value, true);
                }

                string column = (basicValue == null ? modSelf :
                                 (modSelf == null ? basicValue : String.Format(
                                      ApplicationInfo.Culture, "{0} {1}", basicValue, modSelf)));

                if (column != null)
                {
                    addRow(pair.Value, column);
                }
                if (modifier == null)
                {
                    continue;
                }

                // add one row for each additional modifier value
                foreach (ModifierTarget target in VariableModifier.AllModifierTargets)
                {
                    if (target == ModifierTarget.Self)
                    {
                        continue;
                    }

                    int?value = modifier.GetByTarget(target);
                    if (value != null)
                    {
                        column = pair.Value.Format(value, target, entityClass.ModifierRange);
                        addRow(pair.Value, column);
                    }
                }
            }
        }
Пример #11
0
        /// <overloads>
        /// Adds one row for each variable of the specified <see cref="Entity"/> or <see
        /// cref="EntityClass"/>.</overloads>
        /// <summary>
        /// Adds one row for each variable of the specified <see cref="Entity"/>.</summary>
        /// <param name="entity">
        /// The <see cref="Entity"/> whose variables to show.</param>
        /// <param name="category">
        /// The <see cref="EntityCategory"/> whose variables to show.</param>
        /// <exception cref="InvalidEnumArgumentException">
        /// <paramref name="category"/> is neither <see cref="VariableCategory.Attribute"/> nor <see
        /// cref="VariableCategory.Resource"/>.</exception>
        /// <remarks>
        /// <b>CreateVariableRows</b> adds one row for each basic value and modifier value defined
        /// by the specified <paramref name="entity"/>. The <see cref="PropertyListItem.Tag"/> of
        /// each row holds the corresponding <see cref="VariableClass"/>.</remarks>

        private void CreateVariableRows(Entity entity, VariableCategory category)
        {
            string categoryLabel = "";
            VariableClassDictionary   variables = null;
            VariableList              basics    = null;
            VariableModifierContainer modifiers = null;

            // retrieve variable collections for category
            if (category == VariableCategory.Attribute)
            {
                categoryLabel = Global.Strings.LabelAttribute;
                variables     = MasterSection.Instance.Variables.Attributes;
                basics        = entity.Attributes.Variables;
                modifiers     = entity.AttributeModifiers;
            }
            else if (category == VariableCategory.Resource)
            {
                categoryLabel = Global.Strings.LabelResource;
                variables     = MasterSection.Instance.Variables.Resources;
                basics        = entity.Resources.Variables;
                modifiers     = entity.ResourceModifiers;
            }
            else
            {
                ThrowHelper.ThrowInvalidEnumArgumentException(
                    "category", (int)category, typeof(VariableCategory));
            }

            Unit unit       = entity as Unit;
            int  firstIndex = Items.Count;

            // insert separator before first attribute?
            bool addSeparator = (firstIndex > 0);

            // add modifier row, preceded by separator if required
            Action <VariableClass, Int32, ModifierTarget, Int32>
            addRow = (variable, value, target, range) => {
                if (addSeparator)
                {
                    ApplicationUtility.AddSeparator(this);
                    addSeparator = false;
                    ++firstIndex;
                }

                string column = variable.Format(value, target, range);
                Items.Add(new PropertyListItem(categoryLabel, variable.Name, column, variable));
            };

            // process all variables defined by the scenario
            foreach (var pair in variables)
            {
                string id = pair.Key;

                // format basic value and self-modifier, if present
                string basicValue = FormatVariable(basics, id);
                string modSelf    = FormatVariable(modifiers.Self, id);

                string column = (basicValue == null ? modSelf :
                                 (modSelf == null ? basicValue : String.Format(
                                      ApplicationInfo.Culture, "{0} {1}", basicValue, modSelf)));

                if (column != null)
                {
                    // insert separator if required
                    if (addSeparator)
                    {
                        ApplicationUtility.AddSeparator(this);
                        addSeparator = false;
                        ++firstIndex;
                    }

                    var item = new PropertyListItem(categoryLabel, pair.Value.Name, column, pair.Value);

                    // show color bar for partially depleted resources
                    Variable resource;
                    if (basics.TryGetValue(id, out resource) && resource.IsDepletableResource)
                    {
                        item.Background = MediaObjects.GetBrush(MediaObjects.DangerFadeBrushes,
                                                                resource.Value, resource.Minimum, resource.Maximum);
                    }

                    // show unit strength resource as first entry
                    if (unit != null && unit.UnitClass.StrengthResource == id)
                    {
                        Items.Insert(firstIndex, item);
                    }
                    else
                    {
                        Items.Add(item);
                    }
                }

                // determine which additional modifiers are present
                Variable modOwner, modUnits, modUnitsRanged, modOwnerUnits, modOwnerUnitsRanged;
                modifiers.Units.TryGetValue(id, out modUnits);
                modifiers.UnitsRanged.TryGetValue(id, out modUnitsRanged);
                modifiers.OwnerUnits.TryGetValue(id, out modOwnerUnits);
                modifiers.OwnerUnitsRanged.TryGetValue(id, out modOwnerUnitsRanged);

                int range = entity.EntityClass.ModifierRange;
                if (modifiers.Owner.TryGetValue(id, out modOwner))
                {
                    addRow(pair.Value, modOwner.Value, ModifierTarget.Owner, range);
                }

                // always show Units & UnitsRanged modifiers
                if (modifiers.Units.TryGetValue(id, out modUnits))
                {
                    addRow(pair.Value, modUnits.Value, ModifierTarget.Units, range);
                }
                if (modifiers.UnitsRanged.TryGetValue(id, out modUnitsRanged))
                {
                    addRow(pair.Value, modUnitsRanged.Value, ModifierTarget.UnitsRanged, range);
                }

                // show OwnerUnits modifier only if different from Units modifier
                if (modifiers.OwnerUnits.TryGetValue(id, out modOwnerUnits))
                {
                    if (modUnits == null || modUnits.Value != modOwnerUnits.Value)
                    {
                        addRow(pair.Value, modOwnerUnits.Value, ModifierTarget.OwnerUnits, range);
                    }
                }
                else if (modUnits != null && modUnits.Value != 0)
                {
                    addRow(pair.Value, 0, ModifierTarget.OwnerUnits, range);
                }

                // show OwnerUnitsRanged modifier only if different from UnitsRanged modifier
                if (modifiers.OwnerUnitsRanged.TryGetValue(id, out modOwnerUnitsRanged))
                {
                    if (modUnitsRanged == null || modUnitsRanged.Value != modOwnerUnitsRanged.Value)
                    {
                        addRow(pair.Value, modOwnerUnitsRanged.Value, ModifierTarget.OwnerUnitsRanged, range);
                    }
                }
                else if (modUnitsRanged != null && modUnitsRanged.Value != 0)
                {
                    addRow(pair.Value, 0, ModifierTarget.OwnerUnitsRanged, range);
                }
            }
        }