1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 02:15:31 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-11-15 14:27:31 -08:00
parent 1e824bb514
commit 1e3fc49c45
2 changed files with 33 additions and 23 deletions

View file

@ -91,11 +91,12 @@ public class Value implements IValue {
fResolvedUnknown= resolvedUnknowns; fResolvedUnknown= resolvedUnknowns;
fMap= map; fMap= map;
} }
public void nextSeperator() throws UnknownValueException { public void nextSeperator() throws UnknownValueException {
final char[] expression = fExpression; final char[] expression = fExpression;
final int len = expression.length; final int len = expression.length;
int idx = pos; int idx = pos;
while(idx < len) { while (idx < len) {
if (expression[idx++] == SEPARATOR) if (expression[idx++] == SEPARATOR)
break; break;
} }
@ -105,7 +106,7 @@ public class Value implements IValue {
private static class UnknownValueException extends Exception {} private static class UnknownValueException extends Exception {}
private static UnknownValueException UNKNOWN_EX= new UnknownValueException(); private static UnknownValueException UNKNOWN_EX= new UnknownValueException();
private static int sUnique=0; private static int sUnique= 0;
private final char[] fExpression; private final char[] fExpression;
private final ICPPUnknownBinding[] fUnknownBindings; private final ICPPUnknownBinding[] fUnknownBindings;
@ -400,7 +401,8 @@ public class Value implements IValue {
* Returns a {@code Number} for numerical values or a {@code String}, otherwise. * Returns a {@code Number} for numerical values or a {@code String}, otherwise.
* @throws UnknownValueException * @throws UnknownValueException
*/ */
private static Object evaluate(IASTExpression e, Map<String, Integer> unknownSigs, List<ICPPUnknownBinding> unknowns, int maxdepth) throws UnknownValueException { private static Object evaluate(IASTExpression e, Map<String, Integer> unknownSigs,
List<ICPPUnknownBinding> unknowns, int maxdepth) throws UnknownValueException {
if (maxdepth < 0 || e == null) if (maxdepth < 0 || e == null)
throw UNKNOWN_EX; throw UNKNOWN_EX;
@ -433,7 +435,8 @@ public class Value implements IValue {
final IASTExpression pe = cexpr.getPositiveResultExpression(); final IASTExpression pe = cexpr.getPositiveResultExpression();
Object po= pe == null ? o : evaluate(pe, unknownSigs, unknowns, maxdepth); Object po= pe == null ? o : evaluate(pe, unknownSigs, unknowns, maxdepth);
Object neg= evaluate(cexpr.getNegativeResultExpression(), unknownSigs, unknowns, maxdepth); Object neg= evaluate(cexpr.getNegativeResultExpression(), unknownSigs, unknowns, maxdepth);
return "" + CONDITIONAL_CHAR + SEPARATOR + o.toString() + SEPARATOR + po.toString() + SEPARATOR + neg.toString(); //$NON-NLS-1$ return "" + CONDITIONAL_CHAR + SEPARATOR + o.toString() + SEPARATOR + po.toString() + //$NON-NLS-1$
SEPARATOR + neg.toString();
} }
if (e instanceof IASTIdExpression) { if (e instanceof IASTIdExpression) {
IBinding b= ((IASTIdExpression) e).getName().resolvePreBinding(); IBinding b= ((IASTIdExpression) e).getName().resolvePreBinding();
@ -483,7 +486,8 @@ public class Value implements IValue {
/** /**
* Extract a value off a binding. * Extract a value off a binding.
*/ */
private static Object evaluateBinding(IBinding b, Map<String, Integer> unknownSigs, List<ICPPUnknownBinding> unknowns, int maxdepth) throws UnknownValueException { private static Object evaluateBinding(IBinding b, Map<String, Integer> unknownSigs,
List<ICPPUnknownBinding> unknowns, int maxdepth) throws UnknownValueException {
if (b instanceof IType) { if (b instanceof IType) {
throw UNKNOWN_EX; throw UNKNOWN_EX;
} }
@ -510,7 +514,8 @@ public class Value implements IValue {
throw UNKNOWN_EX; throw UNKNOWN_EX;
} }
private static Object createReference(ICPPUnknownBinding unknown, Map<String, Integer> unknownSigs, List<ICPPUnknownBinding> unknowns) { private static Object createReference(ICPPUnknownBinding unknown,
Map<String, Integer> unknownSigs, List<ICPPUnknownBinding> unknowns) {
String sig= getSignatureForUnknown(unknown); String sig= getSignatureForUnknown(unknown);
Integer idx= unknownSigs.get(sig); Integer idx= unknownSigs.get(sig);
if (idx == null) { if (idx == null) {
@ -521,7 +526,8 @@ public class Value implements IValue {
return "" + REFERENCE_CHAR + idx.toString(); //$NON-NLS-1$ return "" + REFERENCE_CHAR + idx.toString(); //$NON-NLS-1$
} }
private static Object evaluateValue(IValue cv, Map<String, Integer> unknownSigs, List<ICPPUnknownBinding> unknowns) throws UnknownValueException { private static Object evaluateValue(IValue cv, Map<String, Integer> unknownSigs,
List<ICPPUnknownBinding> unknowns) throws UnknownValueException {
if (cv == Value.UNKNOWN) if (cv == Value.UNKNOWN)
throw UNKNOWN_EX; throw UNKNOWN_EX;
@ -564,7 +570,9 @@ public class Value implements IValue {
return buf.toString(); return buf.toString();
} }
private static Object evaluateUnaryExpression(IASTUnaryExpression ue, Map<String, Integer> unknownSigs, List<ICPPUnknownBinding> unknowns, int maxdepth) throws UnknownValueException { private static Object evaluateUnaryExpression(IASTUnaryExpression ue,
Map<String, Integer> unknownSigs, List<ICPPUnknownBinding> unknowns, int maxdepth)
throws UnknownValueException {
final int unaryOp= ue.getOperator(); final int unaryOp= ue.getOperator();
if (unaryOp == IASTUnaryExpression.op_sizeof) { if (unaryOp == IASTUnaryExpression.op_sizeof) {
@ -626,7 +634,8 @@ public class Value implements IValue {
} }
private static Object evaluateBinaryExpression(IASTBinaryExpression be, private static Object evaluateBinaryExpression(IASTBinaryExpression be,
Map<String, Integer> unknownSigs, List<ICPPUnknownBinding> unknowns, int maxdepth) throws UnknownValueException { Map<String, Integer> unknownSigs, List<ICPPUnknownBinding> unknowns, int maxdepth)
throws UnknownValueException {
final Object o1= evaluate(be.getOperand1(), unknownSigs, unknowns, maxdepth); final Object o1= evaluate(be.getOperand1(), unknownSigs, unknowns, maxdepth);
final Object o2= evaluate(be.getOperand2(), unknownSigs, unknowns, maxdepth); final Object o2= evaluate(be.getOperand2(), unknownSigs, unknowns, maxdepth);
@ -634,7 +643,8 @@ public class Value implements IValue {
return combineBinary(op, o1, o2); return combineBinary(op, o1, o2);
} }
private static Object combineBinary(final int op, final Object o1, final Object o2) throws UnknownValueException { private static Object combineBinary(final int op, final Object o1, final Object o2)
throws UnknownValueException {
if (o1 instanceof Number && o2 instanceof Number) { if (o1 instanceof Number && o2 instanceof Number) {
long v1= ((Number) o1).longValue(); long v1= ((Number) o1).longValue();
long v2= ((Number) o2).longValue(); long v2= ((Number) o2).longValue();
@ -721,7 +731,8 @@ public class Value implements IValue {
return "" + BINARY_OP_CHAR + op + SEPARATOR + o1.toString() + SEPARATOR + o2.toString(); //$NON-NLS-1$ return "" + BINARY_OP_CHAR + op + SEPARATOR + o1.toString() + SEPARATOR + o2.toString(); //$NON-NLS-1$
} }
public static IValue reevaluate(IValue val, int packOffset, IBinding[] resolvedUnknowns, ICPPTemplateParameterMap map, int maxdepth) { public static IValue reevaluate(IValue val, int packOffset, IBinding[] resolvedUnknowns,
ICPPTemplateParameterMap map, int maxdepth) {
try { try {
Map<String, Integer> unknownSigs= new HashMap<String, Integer>(); Map<String, Integer> unknownSigs= new HashMap<String, Integer>();
List<ICPPUnknownBinding> unknown= new ArrayList<ICPPUnknownBinding>(); List<ICPPUnknownBinding> unknown= new ArrayList<ICPPUnknownBinding>();
@ -783,7 +794,8 @@ public class Value implements IValue {
} }
return po; return po;
} }
return "" + CONDITIONAL_CHAR + SEPARATOR + cond.toString() + SEPARATOR + po.toString() + SEPARATOR + neg.toString(); //$NON-NLS-1$ return "" + CONDITIONAL_CHAR + SEPARATOR + cond.toString() + SEPARATOR + //$NON-NLS-1$
po.toString() + SEPARATOR + neg.toString();
case REFERENCE_CHAR: case REFERENCE_CHAR:
int num= parseNonNegative(buf, idx + 1); int num= parseNonNegative(buf, idx + 1);
final IBinding[] resolvedUnknowns= reeval.fResolvedUnknown; final IBinding[] resolvedUnknowns= reeval.fResolvedUnknown;
@ -885,7 +897,7 @@ public class Value implements IValue {
* Parses a long. * Parses a long.
*/ */
private static long parseLong(char[] value, int offset) throws UnknownValueException { private static long parseLong(char[] value, int offset) throws UnknownValueException {
final long maxvalue= Long.MAX_VALUE/10; final long maxvalue= Long.MAX_VALUE / 10;
final int len= value.length; final int len= value.length;
boolean negative= false; boolean negative= false;
long result = 0; long result = 0;
@ -916,7 +928,7 @@ public class Value implements IValue {
* Parses a long, returns <code>null</code> if not possible * Parses a long, returns <code>null</code> if not possible
*/ */
private static Long parseLong(char[] value) { private static Long parseLong(char[] value) {
final long maxvalue= Long.MAX_VALUE/10; final long maxvalue= Long.MAX_VALUE / 10;
final int len= value.length; final int len= value.length;
boolean negative= false; boolean negative= false;
long result = 0; long result = 0;

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.util; package org.eclipse.cdt.internal.core.dom.rewrite.util;
@ -19,7 +19,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/** /**
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*
*/ */
public class OffsetHelper { public class OffsetHelper {
@ -32,10 +31,11 @@ public class OffsetHelper {
if (location instanceof IASTMacroExpansionLocation) { if (location instanceof IASTMacroExpansionLocation) {
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location; IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
offset = macroLoc.asFileLocation().getNodeOffset(); offset = macroLoc.asFileLocation().getNodeOffset();
}else { } else {
offset = location.asFileLocation().getNodeOffset(); offset = location.asFileLocation().getNodeOffset();
} }
if(offset < nodeStart) nodeStart = offset; if (offset < nodeStart)
nodeStart = offset;
} }
} else { } else {
nodeStart = node.getFileLocation().getNodeOffset(); nodeStart = node.getFileLocation().getNodeOffset();
@ -55,14 +55,13 @@ public class OffsetHelper {
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location; IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
fileOffset = macroLoc.asFileLocation().getNodeOffset(); fileOffset = macroLoc.asFileLocation().getNodeOffset();
length = macroLoc.asFileLocation().getNodeLength(); length = macroLoc.asFileLocation().getNodeLength();
}else { } else {
fileOffset = location.asFileLocation().getNodeOffset(); fileOffset = location.asFileLocation().getNodeOffset();
length = location.asFileLocation().getNodeLength(); length = location.asFileLocation().getNodeLength();
} }
} }
} else { } else {
IASTFileLocation loc = node.getFileLocation(); IASTFileLocation loc = node.getFileLocation();
fileOffset = loc.getNodeOffset(); fileOffset = loc.getNodeOffset();
length = loc.getNodeLength(); length = loc.getNodeLength();
} }
@ -75,7 +74,7 @@ public class OffsetHelper {
} }
public static int getLengthIncludingComment(IASTNode node) { public static int getLengthIncludingComment(IASTNode node) {
return OffsetHelper.getEndOffsetIncludingComments(node) - OffsetHelper.getOffsetIncludingComment(node); return getEndOffsetIncludingComments(node) - getOffsetIncludingComment(node);
} }
public static int getNodeOffset(ASTNode node) { public static int getNodeOffset(ASTNode node) {
@ -92,6 +91,5 @@ public class OffsetHelper {
public static int getEndingLineNumber(IASTNode node) { public static int getEndingLineNumber(IASTNode node) {
return node.getFileLocation().getEndingLineNumber(); return node.getFileLocation().getEndingLineNumber();
} }
} }