If the expression is a variable declaration, then add it to the current scope;
DSLs introducing new containers for variable declarations should override this method
and explicitly add nested variable declarations.
@since 2.9
963055
protected void addLocalToCurrentScope(XExpression expression, ITypeComputationState state) {
		if (expression instanceof XVariableDeclaration) {
			addLocalToCurrentScope((XVariableDeclaration)expression, state);
		}
	}
670380
public void declareVariables(Variable[] vars) {
        for (int i=0; i<vars.length; i++) {
            vars[i] = declareVariable(vars[i]);
        }
    }
749897
private void parseVariableDeclaration() {
        Variable var = new Variable();
        var.setName(tokenizer.consume().getContents());
        tokenizer.consumeExpectedSymbol(":");
        var.setValue(parseExpression(true));
        if (tokenizer.current().isSymbol("!") && tokenizer.next().hasContent("default")) {
            var.setDefaultValue(true);
            tokenizer.consume();
            tokenizer.consume();
        }
        result.addVariable(var);
        tokenizer.consumeExpectedSymbol(";");
    }
168542
@Override
	protected void putVariables(Map<String, String> variables) {
		variables.put(ScopeFormat.SCOPE_TASK_VERTEX_ID, vertexId.toString());
		variables.put(ScopeFormat.SCOPE_TASK_NAME, taskName);
		variables.put(ScopeFormat.SCOPE_TASK_ATTEMPT_ID, executionId.toString());
		variables.put(ScopeFormat.SCOPE_TASK_ATTEMPT_NUM, String.valueOf(attemptNumber));
		variables.put(ScopeFormat.SCOPE_TASK_SUBTASK_INDEX, String.valueOf(subtaskIndex));
	}
733724
def +(other)
      case other
      when LinExpr
        # Add the terms of two expressions
        # For now, this assumes variables are not duplicated
        LinExpr.new(@terms.merge(other.terms) { |_, c1, c2| c1 + c2 })
      when Variable
        # Add the variable to the expression
        self + other * 1.0
      else
        fail TypeError
      end
    end
497229
function checkVariableDeclaration(node) {
            const parent = node.parent;
            const type = node.kind;

            if (!options[type]) {
                return;
            }

            const declarations = node.declarations;
            const declarationCounts = countDeclarations(declarations);
            const mixedRequires = declarations.some(isRequire) && !declarations.every(isRequire);

            if (options[type].initialized === MODE_ALWAYS) {
                if (options.separateRequires && mixedRequires) {
                    context.report({
                        node,
                        message: "Split requires to be separated into a single block."
                    });
                }
            }

            // consecutive
            const nodeIndex = (parent.body && parent.body.length > 0 && parent.body.indexOf(node)) || 0;

            if (nodeIndex > 0) {
                const previousNode = parent.body[nodeIndex - 1];
                const isPreviousNodeDeclaration = previousNode.type === "VariableDeclaration";
                const declarationsWithPrevious = declarations.concat(previousNode.declarations || []);

                if (
                    isPreviousNodeDeclaration &&
                    previousNode.kind === type &&
                    !(declarationsWithPrevious.some(isRequire) && !declarationsWithPrevious.every(isRequire))
                ) {
                    const previousDeclCounts = countDeclarations(previousNode.declarations);

                    if (options[type].initialized === MODE_CONSECUTIVE && options[type].uninitialized === MODE_CONSECUTIVE) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    } else if (options[type].initialized === MODE_CONSECUTIVE && declarationCounts.initialized > 0 && previousDeclCounts.initialized > 0) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with initialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    } else if (options[type].uninitialized === MODE_CONSECUTIVE &&
                            declarationCounts.uninitialized > 0 &&
                            previousDeclCounts.uninitialized > 0) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with uninitialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    }
                }
            }

            // always
            if (!hasOnlyOneStatement(type, declarations)) {
                if (options[type].initialized === MODE_ALWAYS && options[type].uninitialized === MODE_ALWAYS) {
                    context.report({
                        node,
                        message: "Combine this with the previous '{{type}}' statement.",
                        data: {
                            type
                        },
                        fix: joinDeclarations(declarations)
                    });
                } else {
                    if (options[type].initialized === MODE_ALWAYS && declarationCounts.initialized > 0) {
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with initialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    }
                    if (options[type].uninitialized === MODE_ALWAYS && declarationCounts.uninitialized > 0) {
                        if (node.parent.left === node && (node.parent.type === "ForInStatement" || node.parent.type === "ForOfStatement")) {
                            return;
                        }
                        context.report({
                            node,
                            message: "Combine this with the previous '{{type}}' statement with uninitialized variables.",
                            data: {
                                type
                            },
                            fix: joinDeclarations(declarations)
                        });
                    }
                }
            }

            // never
            if (parent.type !== "ForStatement" || parent.init !== node) {
                const totalDeclarations = declarationCounts.uninitialized + declarationCounts.initialized;

                if (totalDeclarations > 1) {
                    if (options[type].initialized === MODE_NEVER && options[type].uninitialized === MODE_NEVER) {

                        // both initialized and uninitialized
                        context.report({
                            node,
                            message: "Split '{{type}}' declarations into multiple statements.",
                            data: {
                                type
                            },
                            fix: splitDeclarations(node)
                        });
                    } else if (options[type].initialized === MODE_NEVER && declarationCounts.initialized > 0) {

                        // initialized
                        context.report({
                            node,
                            message: "Split initialized '{{type}}' declarations into multiple statements.",
                            data: {
                                type
                            },
                            fix: splitDeclarations(node)
                        });
                    } else if (options[type].uninitialized === MODE_NEVER && declarationCounts.uninitialized > 0) {

                        // uninitialized
                        context.report({
                            node,
                            message: "Split uninitialized '{{type}}' declarations into multiple statements.",
                            data: {
                                type
                            },
                            fix: splitDeclarations(node)
                        });
                    }
                }
            }
        }
56724
def add_variables_from_node(lhs, scope_stack, allow_duplicates=true)
      case lhs[0]
      when :@ident
        scope_stack.add_variable(lhs[1], allow_duplicates)
      when :const_path_field, :@const, :top_const_field
        if scope_stack.in_method?
          raise DynamicConstantError.new
        end
      when Array
        add_variable_list(lhs, scope_stack, allow_duplicates)
      when :mlhs_paren, :var_field, :rest_param, :blockarg
        add_variables_from_node(lhs[1], scope_stack, allow_duplicates)
      when :mlhs_add_star
        pre_star, star, post_star = lhs[1..3]
        add_variable_list(pre_star, scope_stack, allow_duplicates)
        if star
          add_variables_from_node(star, scope_stack, allow_duplicates)
        end
        add_variable_list(post_star, scope_stack, allow_duplicates) if post_star
      when :param_error
        raise InvalidArgumentError.new
      when :assign_error
        raise LHSError.new
      end
    end
549404
def add_variable(self, node):
        
        if node.name not in self.variable_names:
            self.variables.append(node)
            self.variable_names.add(node.name)
            node.parent = self
1082157
def add_var(self, field_name, field, root=False):
        
        self._dlog("adding var '{}' (root={})".format(field_name, root))

        # do both so it's not clobbered by intermediate values of the same name
        if root:
            self._scope_stack[0]["vars"][field_name] = field

        # TODO do we allow clobbering of vars???
        self._curr_scope["vars"][field_name] = field
856152
public void visitVariableExpression(VariableExpression expression) {
        String variableName = expression.getName();

        //-----------------------------------------------------------------------
        // SPECIAL CASES

        // "this" for static methods is the Class instance
        ClassNode classNode = controller.getClassNode();
        //if (controller.isInClosure()) classNode = controller.getOutermostClass();

        if (variableName.equals("this")) {
            if (controller.isStaticMethod() || (!controller.getCompileStack().isImplicitThis() && controller.isStaticContext())) {
                if (controller.isInClosure()) classNode = controller.getOutermostClass();
                visitClassExpression(new ClassExpression(classNode));
            } else {
                loadThis(expression);
            }
            return;
        }

        // "super" also requires special handling
        if (variableName.equals("super")) {
            if (controller.isStaticMethod()) {
                visitClassExpression(new ClassExpression(classNode.getSuperClass()));
            } else {
                loadThis(expression);
            }
            return;
        }

        BytecodeVariable variable = controller.getCompileStack().getVariable(variableName, false);
        if (variable == null) {
            processClassVariable(variableName);
        } else {
            controller.getOperandStack().loadOrStoreVariable(variable, expression.isUseReferenceDirectly());
        }
        if (!controller.getCompileStack().isLHS()) controller.getAssertionWriter().record(expression);
    }
69764
function Variable(scope,name,decl,o){
	this._ref = STACK._counter++;
	this._c = null;
	this._scope = scope;
	this._name = name;
	this._alias = null;
	this._initialized = true;
	this._declarator = decl;
	this._autodeclare = false;
	this._declared = o && o.declared || false;
	this._resolved = false;
	this._options = o || {};
	this._type = o && o.type || 'var'; // what about let here=
	this._export = false;
	this._references = []; // only needed when profiling
	this._assignments = [];
	this;
}
350719
private void addPreliminaryThis(Scope scope, Symbol symbol, TypeDeclaration type) {
        Symbol<TypeDeclaration> thisSymbol =
                new Symbol<TypeDeclaration>("this", symbol.getType(), type, ReferenceType.VARIABLE);
        thisSymbol.setInnerScope(scope);
        scope.addSymbol(thisSymbol);
    }
278047
public final void variable_definition() throws RecognitionException {
		CommonTree varname=null;
		CommonTree q=null;
		CommonTree pattern=null;

		try {
			// src/main/resources/org/drools/compiler/lang/dsl/DSLMapWalker.g:127:5: ( ^( VT_VAR_DEF varname= LITERAL ^( VT_QUAL (q= LITERAL )? ) (pattern= VT_PATTERN )? ) )
			// src/main/resources/org/drools/compiler/lang/dsl/DSLMapWalker.g:127:9: ^( VT_VAR_DEF varname= LITERAL ^( VT_QUAL (q= LITERAL )? ) (pattern= VT_PATTERN )? )
			{
			match(input,VT_VAR_DEF,FOLLOW_VT_VAR_DEF_in_variable_definition423); 
			match(input, Token.DOWN, null); 
			varname=(CommonTree)match(input,LITERAL,FOLLOW_LITERAL_in_variable_definition427); 
			match(input,VT_QUAL,FOLLOW_VT_QUAL_in_variable_definition430); 
			if ( input.LA(1)==Token.DOWN ) {
				match(input, Token.DOWN, null); 
				// src/main/resources/org/drools/compiler/lang/dsl/DSLMapWalker.g:127:49: (q= LITERAL )?
				int alt13=2;
				int LA13_0 = input.LA(1);
				if ( (LA13_0==LITERAL) ) {
					alt13=1;
				}
				switch (alt13) {
					case 1 :
						// src/main/resources/org/drools/compiler/lang/dsl/DSLMapWalker.g:127:49: q= LITERAL
						{
						q=(CommonTree)match(input,LITERAL,FOLLOW_LITERAL_in_variable_definition434); 
						}
						break;

				}

				match(input, Token.UP, null); 
			}

			// src/main/resources/org/drools/compiler/lang/dsl/DSLMapWalker.g:127:67: (pattern= VT_PATTERN )?
			int alt14=2;
			int LA14_0 = input.LA(1);
			if ( (LA14_0==VT_PATTERN) ) {
				alt14=1;
			}
			switch (alt14) {
				case 1 :
					// src/main/resources/org/drools/compiler/lang/dsl/DSLMapWalker.g:127:67: pattern= VT_PATTERN
					{
					pattern=(CommonTree)match(input,VT_PATTERN,FOLLOW_VT_PATTERN_in_variable_definition440); 
					}
					break;

			}

			match(input, Token.UP, null); 


			        entry_stack.peek().variables.put((varname!=null?varname.getText():null), Integer.valueOf(0));

			        if(q!=null && pattern!=null){
			            entry_stack.peek().sentenceKeyBuffer.append("{"+(varname!=null?varname.getText():null)+":"+(q!=null?q.getText():null)+":"+(pattern!=null?pattern.getText():null)+"}");
			        }else if(q==null && pattern!=null){
			            entry_stack.peek().sentenceKeyBuffer.append("{"+(varname!=null?varname.getText():null)+":"+(pattern!=null?pattern.getText():null)+"}");
			        }else{
			            entry_stack.peek().sentenceKeyBuffer.append("{"+(varname!=null?varname.getText():null)+"}");
			        }

			        if(q == null || (!q.getText().equals("ENUM") && !q.getText().equals("CF") && 
			                          !q.getText().equals("DATE") && !q.getText().equals("BOOLEAN"))){
			            entry_stack.peek().keybuffer.append(pattern != null? "(" + (pattern!=null?pattern.getText():null) + ")" : "(.*?)");
			        }else{
			            entry_stack.peek().keybuffer.append("(.*?)");
			        }
			    
			}

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
		}
	}
478396
function addVariable() {
            variableService.addOrUpdate(vm.variable, function () {
                vm.variables[vm.variable.key] = vm.variable.value;
                vm.variable = {
                    key: undefined,
                    value: undefined
                };
            });
        }
23809
public VarSet addMember( IVarDef var)
    {
    assert var != null;
    assert var.getName() != null;

    if( findMember( var.getName()) >= 0)
      {
      throw new IllegalStateException( "Member=" + var.getName() + " already defined for varSet=" + getPathName());
      }

    members_.add( var);
    var.setParent( this);
    var.setSeqNum( getNextSeqNum());

    return this;
    }
518089
private VariableStatementTree parseVariableStatement() {
    SourcePosition start = getTreeStartLocation();
    VariableDeclarationListTree declarations = parseVariableDeclarationList();
    eatPossibleImplicitSemiColon();
    return new VariableStatementTree(getTreeLocation(start), declarations);
  }
1272610
function markVariableAsUsed(context, name) {
  let scope = context.getScope();
  let variables;
  let i;
  let len;
  let found = false;

  // Special Node.js scope means we need to start one level deeper
  if (scope.type === 'global') {
    while (scope.childScopes.length) {
      scope = scope.childScopes[0];
    }
  }

  do {
    variables = scope.variables;
    for (i = 0, len = variables.length; i < len; i++) { // eslint-disable-line no-plusplus
      if (variables[i].name === name) {
        variables[i].eslintUsed = true;
        found = true;
      }
    }
    scope = scope.upper;
  } while (scope);

  return found;
}