Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4ca282b7767d8d1a1ac2c974cff676f1175165c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*******************************************************************************
 * Copyright (c) 2000, 2015 QNX Software Systems and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *     Red Hat Inc. - Refactor name
 *******************************************************************************/
package org.eclipse.cdt.internal.autotools.ui.editors.automake;

import org.eclipse.cdt.make.core.makefile.gnu.IVariableDefinition;

/**
 */
public class GNUVariableDef extends MacroDefinition implements IVariableDefinition  {

	/**
	 * ? is Conditional
	 * : is Simply-expanded
	 * + is append
	 * 0 is recursively-expanded.
	 */
	final static int TYPE_RECURSIVE_EXPAND = 0;
	final static int TYPE_SIMPLE_EXPAND = ':';
	final static int TYPE_CONDITIONAL = '?';
	final static int TYPE_APPEND = '+';
	int type;
	String varTarget;

	public GNUVariableDef(Directive parent, String name, StringBuffer value) {
		this(parent, name, value, TYPE_RECURSIVE_EXPAND);
	}

	public GNUVariableDef(Directive parent, String name, StringBuffer value, int type) {
		this(parent,  "", name, value, type); //$NON-NLS-1$
	}

	public GNUVariableDef(Directive parent, String target, String name, StringBuffer value, int type) {
		super(parent, name, value);
		varTarget = target;
		this.type = type;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		if (isTargetSpecific()) {
			sb.append(getTarget()).append(": "); //$NON-NLS-1$
		}
		if (isOverride()) {
			sb.append(GNUMakefileConstants.VARIABLE_OVERRIDE);
		}
		if (isMultiLine()) {
			sb.append(GNUMakefileConstants.VARIABLE_DEFINE);
			sb.append(' ');
			sb.append(getName()).append('\n');
			sb.append(getValue()).append('\n');
			sb.append(GNUMakefileConstants.TERMINAL_ENDEF);
			sb.append('\n');
		} else {
			if (isExport()) {
				sb.append(GNUMakefileConstants.VARIABLE_EXPORT);
				sb.append(' ');
			}
			sb.append(getName());
			if (isRecursivelyExpanded()) {
				sb.append(" = "); //$NON-NLS-1$
			} else if (isSimplyExpanded()) {
				sb.append(" := "); //$NON-NLS-1$
			} else if (isConditional()) {
				sb.append(" ?= "); //$NON-NLS-1$
			} else if (isAppend()) {
				sb.append(" += "); //$NON-NLS-1$
			}
			sb.append(getValue()).append('\n');
		}
		return sb.toString();
	}

	@Override
	public boolean isRecursivelyExpanded() {
		return type == TYPE_RECURSIVE_EXPAND;
	}

	@Override
	public boolean isSimplyExpanded() {
		return type == TYPE_SIMPLE_EXPAND;
	}

	@Override
	public boolean isConditional() {
		return type == TYPE_CONDITIONAL;
	}

	@Override
	public boolean isAppend() {
		return type == TYPE_APPEND;
	}

	@Override
	public boolean isTargetSpecific() {
		String t = getTarget();
		return t != null && t.length() > 0;
	}

	@Override
	public boolean isExport() {
		return false;
	}

	@Override
	public boolean isMultiLine() {
		return false;
	}

	/**
	 * Variable from an `override' directive.
	 */
	 @Override
	public boolean isOverride() {
		return false;
	}

	/**
	 * Automatic variable -- cannot be set.
	 */
	 @Override
	public boolean isAutomatic() {
		return false;
	}

	@Override
	public String getTarget() {
		return varTarget;
	}

}

Back to the top